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"]),
|
srcs = glob(["*.ts"]),
|
||||||
tsconfig = "//qt/aqt/data/web/js:tsconfig.json",
|
tsconfig = "//qt/aqt/data/web/js:tsconfig.json",
|
||||||
deps = [
|
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;
|
return node.nodeType === Node.ELEMENT_NODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isHTMLElement(elem: Element): elem is HTMLElement {
|
|
||||||
return elem instanceof HTMLElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
const INLINE_TAGS = [
|
const INLINE_TAGS = [
|
||||||
"A",
|
"A",
|
||||||
"ABBR",
|
"ABBR",
|
||||||
@ -81,7 +77,3 @@ export function caretToEnd(currentField: EditingArea): void {
|
|||||||
selection.removeAllRanges();
|
selection.removeAllRanges();
|
||||||
selection.addRange(range);
|
selection.addRange(range);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isNightMode(): boolean {
|
|
||||||
return document.body.classList.contains("nightMode");
|
|
||||||
}
|
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
/* Copyright: Ankitects Pty Ltd and contributors
|
/* Copyright: Ankitects Pty Ltd and contributors
|
||||||
* License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */
|
* 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 { caretToEnd } from "./helpers";
|
||||||
import { saveField } from "./changeTimer";
|
import { saveField } from "./changeTimer";
|
||||||
import { filterHTML } from "./htmlFilter";
|
|
||||||
import { updateButtonState, disableButtons } from "./toolbar";
|
import { updateButtonState, disableButtons } from "./toolbar";
|
||||||
|
|
||||||
import { EditorField } from "./editorField";
|
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 { isHTMLElement, isNightMode } from "./helpers";
|
||||||
import { removeNode as removeElement } from "./htmlFilterNode";
|
import { removeNode as removeElement } from "./node";
|
||||||
import {
|
import {
|
||||||
filterStylingNightMode,
|
filterStylingNightMode,
|
||||||
filterStylingLightMode,
|
filterStylingLightMode,
|
||||||
filterStylingInternal,
|
filterStylingInternal,
|
||||||
} from "./htmlFilterStyling";
|
} from "./styling";
|
||||||
|
|
||||||
interface TagsAllowed {
|
interface TagsAllowed {
|
||||||
[tagName: string]: FilterMethod;
|
[tagName: string]: FilterMethod;
|
||||||
@ -29,13 +29,11 @@ function blockAll(element: Element): void {
|
|||||||
filterOutAttributes(() => true, element);
|
filterOutAttributes(() => true, element);
|
||||||
}
|
}
|
||||||
|
|
||||||
function blockExcept(attrs: string[]): FilterMethod {
|
const blockExcept = (attrs: string[]): FilterMethod => (element: Element): void =>
|
||||||
return (element: Element) =>
|
|
||||||
filterOutAttributes(
|
filterOutAttributes(
|
||||||
(attributeName: string) => !attrs.includes(attributeName),
|
(attributeName: string) => !attrs.includes(attributeName),
|
||||||
element
|
element
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
function unwrapElement(element: Element): void {
|
function unwrapElement(element: Element): void {
|
||||||
element.outerHTML = element.innerHTML;
|
element.outerHTML = element.innerHTML;
|
||||||
@ -95,7 +93,7 @@ const filterElementTagsAllowed = (tagsAllowed: TagsAllowed) => (
|
|||||||
): void => {
|
): void => {
|
||||||
const tagName = element.tagName;
|
const tagName = element.tagName;
|
||||||
|
|
||||||
if (tagsAllowed.hasOwnProperty(tagName)) {
|
if (Object.prototype.hasOwnProperty.call(tagsAllowed, tagName)) {
|
||||||
tagsAllowed[tagName](element);
|
tagsAllowed[tagName](element);
|
||||||
} else if (element.innerHTML) {
|
} else if (element.innerHTML) {
|
||||||
removeElement(element);
|
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,
|
filterElementBasic,
|
||||||
filterElementExtended,
|
filterElementExtended,
|
||||||
filterElementInternal,
|
filterElementInternal,
|
||||||
} from "./htmlFilterElement";
|
} from "./element";
|
||||||
import { filterNode } from "./htmlFilterNode";
|
import { filterNode } from "./node";
|
||||||
|
|
||||||
enum FilterMode {
|
enum FilterMode {
|
||||||
Basic,
|
Basic,
|
@ -27,7 +27,8 @@ const stylingInternal: BlockProperties = [
|
|||||||
const allowPropertiesBlockValues = (
|
const allowPropertiesBlockValues = (
|
||||||
allowBlock: AllowPropertiesBlockValues
|
allowBlock: AllowPropertiesBlockValues
|
||||||
): StylingPredicate => (property: string, value: string): boolean =>
|
): 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 => (
|
const blockProperties = (block: BlockProperties): StylingPredicate => (
|
||||||
property: string
|
property: string
|
@ -7,7 +7,8 @@
|
|||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"anki/*": ["../bazel-bin/ts/lib/*"],
|
"anki/*": ["../bazel-bin/ts/lib/*"],
|
||||||
"sveltelib/*": ["../bazel-bin/ts/sveltelib/*"]
|
"sveltelib/*": ["../bazel-bin/ts/sveltelib/*"],
|
||||||
|
"html-filter/*": ["../bazel-bin/ts/html-filter/*"]
|
||||||
},
|
},
|
||||||
"importsNotUsedAsValues": "error",
|
"importsNotUsedAsValues": "error",
|
||||||
"outDir": "dist",
|
"outDir": "dist",
|
||||||
|
Loading…
Reference in New Issue
Block a user