Move html-filter into its own directory
This commit is contained in:
parent
730dfdd527
commit
519aea2ea8
@ -21,7 +21,7 @@ ts_library(
|
||||
srcs = glob(["*.ts"]),
|
||||
tsconfig = "//qt/aqt/data/web/js:tsconfig.json",
|
||||
deps = [
|
||||
"@npm//@types/jquery",
|
||||
"//ts/html-filter",
|
||||
],
|
||||
)
|
||||
|
||||
|
@ -7,10 +7,6 @@ export function nodeIsElement(node: Node): node is Element {
|
||||
return node.nodeType === Node.ELEMENT_NODE;
|
||||
}
|
||||
|
||||
export function isHTMLElement(elem: Element): elem is HTMLElement {
|
||||
return elem instanceof HTMLElement;
|
||||
}
|
||||
|
||||
const INLINE_TAGS = [
|
||||
"A",
|
||||
"ABBR",
|
||||
@ -81,7 +77,3 @@ export function caretToEnd(currentField: EditingArea): void {
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range);
|
||||
}
|
||||
|
||||
export function isNightMode(): boolean {
|
||||
return document.body.classList.contains("nightMode");
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
/* Copyright: Ankitects Pty Ltd and contributors
|
||||
* License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */
|
||||
|
||||
import { filterHTML } from "html-filter/index";
|
||||
|
||||
import { caretToEnd } from "./helpers";
|
||||
import { saveField } from "./changeTimer";
|
||||
import { filterHTML } from "./htmlFilter";
|
||||
import { updateButtonState, disableButtons } from "./toolbar";
|
||||
|
||||
import { EditorField } from "./editorField";
|
||||
|
31
ts/html-filter/BUILD.bazel
Normal file
31
ts/html-filter/BUILD.bazel
Normal file
@ -0,0 +1,31 @@
|
||||
load("@npm//@bazel/typescript:index.bzl", "ts_library")
|
||||
load("//ts:prettier.bzl", "prettier_test")
|
||||
load("//ts:eslint.bzl", "eslint_test")
|
||||
|
||||
ts_library(
|
||||
name = "html-filter",
|
||||
srcs = glob(["*.ts"]),
|
||||
module_name = "html-filter",
|
||||
tsconfig = "//qt/aqt/data/web/js:tsconfig.json",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [],
|
||||
)
|
||||
|
||||
# Tests
|
||||
################
|
||||
|
||||
prettier_test(
|
||||
name = "format_check",
|
||||
srcs = glob([
|
||||
"*.ts",
|
||||
]),
|
||||
)
|
||||
|
||||
eslint_test(
|
||||
name = "eslint",
|
||||
srcs = glob(
|
||||
[
|
||||
"*.ts",
|
||||
],
|
||||
),
|
||||
)
|
@ -1,10 +1,10 @@
|
||||
import { isNightMode, isHTMLElement } from "./helpers";
|
||||
import { removeNode as removeElement } from "./htmlFilterNode";
|
||||
import { isHTMLElement, isNightMode } from "./helpers";
|
||||
import { removeNode as removeElement } from "./node";
|
||||
import {
|
||||
filterStylingNightMode,
|
||||
filterStylingLightMode,
|
||||
filterStylingInternal,
|
||||
} from "./htmlFilterStyling";
|
||||
} from "./styling";
|
||||
|
||||
interface TagsAllowed {
|
||||
[tagName: string]: FilterMethod;
|
||||
@ -29,13 +29,11 @@ function blockAll(element: Element): void {
|
||||
filterOutAttributes(() => true, element);
|
||||
}
|
||||
|
||||
function blockExcept(attrs: string[]): FilterMethod {
|
||||
return (element: Element) =>
|
||||
filterOutAttributes(
|
||||
(attributeName: string) => !attrs.includes(attributeName),
|
||||
element
|
||||
);
|
||||
}
|
||||
const blockExcept = (attrs: string[]): FilterMethod => (element: Element): void =>
|
||||
filterOutAttributes(
|
||||
(attributeName: string) => !attrs.includes(attributeName),
|
||||
element
|
||||
);
|
||||
|
||||
function unwrapElement(element: Element): void {
|
||||
element.outerHTML = element.innerHTML;
|
||||
@ -95,7 +93,7 @@ const filterElementTagsAllowed = (tagsAllowed: TagsAllowed) => (
|
||||
): void => {
|
||||
const tagName = element.tagName;
|
||||
|
||||
if (tagsAllowed.hasOwnProperty(tagName)) {
|
||||
if (Object.prototype.hasOwnProperty.call(tagsAllowed, tagName)) {
|
||||
tagsAllowed[tagName](element);
|
||||
} else if (element.innerHTML) {
|
||||
removeElement(element);
|
7
ts/html-filter/helpers.ts
Normal file
7
ts/html-filter/helpers.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export function isHTMLElement(elem: Element): elem is HTMLElement {
|
||||
return elem instanceof HTMLElement;
|
||||
}
|
||||
|
||||
export function isNightMode(): boolean {
|
||||
return document.body.classList.contains("nightMode");
|
||||
}
|
@ -5,8 +5,8 @@ import {
|
||||
filterElementBasic,
|
||||
filterElementExtended,
|
||||
filterElementInternal,
|
||||
} from "./htmlFilterElement";
|
||||
import { filterNode } from "./htmlFilterNode";
|
||||
} from "./element";
|
||||
import { filterNode } from "./node";
|
||||
|
||||
enum FilterMode {
|
||||
Basic,
|
@ -29,6 +29,6 @@ export const filterNode = (elementFilter: (element: Element) => void) => (
|
||||
break;
|
||||
|
||||
default:
|
||||
// do nothing
|
||||
// do nothing
|
||||
}
|
||||
};
|
@ -27,7 +27,8 @@ const stylingInternal: BlockProperties = [
|
||||
const allowPropertiesBlockValues = (
|
||||
allowBlock: AllowPropertiesBlockValues
|
||||
): StylingPredicate => (property: string, value: string): boolean =>
|
||||
allowBlock.hasOwnProperty(property) && !allowBlock[property].includes(value);
|
||||
Object.prototype.hasOwnProperty.call(allowBlock, property) &&
|
||||
!allowBlock[property].includes(value);
|
||||
|
||||
const blockProperties = (block: BlockProperties): StylingPredicate => (
|
||||
property: string
|
@ -7,7 +7,8 @@
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"anki/*": ["../bazel-bin/ts/lib/*"],
|
||||
"sveltelib/*": ["../bazel-bin/ts/sveltelib/*"]
|
||||
"sveltelib/*": ["../bazel-bin/ts/sveltelib/*"],
|
||||
"html-filter/*": ["../bazel-bin/ts/html-filter/*"]
|
||||
},
|
||||
"importsNotUsedAsValues": "error",
|
||||
"outDir": "dist",
|
||||
|
Loading…
Reference in New Issue
Block a user