anki/ts/editor/rich-text-input/normalizing-node-store.ts
Damien Elmes b2049209ff Re-enable formatting for .ts files
There are some style differences compared to prettier, and not all are
necessarily an improvement, but it's much faster now.
2022-11-28 09:33:04 +10:00

28 lines
877 B
TypeScript

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import type { DecoratedElement } from "../../editable/decorated";
import type { NodeStore } from "../../sveltelib/node-store";
import { nodeStore } from "../../sveltelib/node-store";
import { decoratedElements } from "../decorated-elements";
function normalizeFragment(fragment: DocumentFragment): void {
fragment.normalize();
for (const decorated of decoratedElements) {
for (
const element of fragment.querySelectorAll(
decorated.tagName,
) as NodeListOf<DecoratedElement>
) {
element.undecorate();
}
}
}
function getStore(): NodeStore<DocumentFragment> {
return nodeStore<DocumentFragment>(undefined, normalizeFragment);
}
export default getStore;