Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(text): stop custom HTML elements vanishing in edit mode (closes #10989)
Elian Doranbd67fa700826
diff --git a/apps/client/src/widgets/type_widgets/text/config.spec.ts b/apps/client/src/widgets/type_widgets/text/config.spec.tsindex f95c98bb37..4e294921a5 100644--- a/apps/client/src/widgets/type_widgets/text/config.spec.ts+++ b/apps/client/src/widgets/type_widgets/text/config.spec.ts@@ -218,6 +218,32 @@ describe("CK config", () => {});});+describe("CK config - HTML support", () => {+ it("names every allowed tag rather than handing GHS bare strings", async () => {+ optionsState.map.allowedHtmlTags = JSON.stringify(["p", "section", "en-media"]);++ const config = await buildConfig(baseOpts());++ // The shape is the whole point: `DataFilter#loadAllowedConfig` falls back to a+ // match-everything pattern for an entry with no `name`, so a list of plain strings allowed+ // every element — including the `$customElement` catch-all, which round-tripped unknown tags+ // as opaque blobs that were invisible and un-navigable in the editing view (#10989).+ expect(config.htmlSupport?.allow).toEqual([+ { name: "p", attributes: true, classes: true, styles: true },+ { name: "section", attributes: true, classes: true, styles: true },+ { name: "en-media", attributes: true, classes: true, styles: true }+ ]);+ // Nothing is disallowed outright; the allow-list alone decides.+ expect(config.htmlSupport?.disallow).toBeUndefined();+ });++ it("allows nothing beyond the natively supported elements when the list is empty", async () => {+ const config = await buildConfig(baseOpts());++ expect(config.htmlSupport?.allow).toEqual([]);+ });+});+describe("CK config - licensing", () => {it("always runs under the open-source license, with no premium plugins", async () => {// Every premium plugin Trilium used has an in-tree GPL replacement, so there is nodiff --git a/apps/client/src/widgets/type_widgets/text/config.ts b/apps/client/src/widgets/type_widgets/text/config.tsindex e608a06f16..efc73b3aed 100644--- a/apps/client/src/widgets/type_widgets/text/config.ts+++ b/apps/client/src/widgets/type_widgets/text/config.ts@@ -187,9 +187,7 @@ export async function buildConfig(opts: BuildEditorOptions): Promise<EditorConfisnippets: {definitions: opts.templates},- htmlSupport: {- allow: JSON.parse(options.get("allowedHtmlTags"))- },+ htmlSupport: buildHtmlSupportConfig(),removePlugins: getDisabledPlugins(),// The locale's CKEditor translations, plus the dictionary of Trilium-authored editor// strings resolved through the app's i18n (see `messages.ts` in the ckeditor5 package).@@ -387,6 +385,25 @@ function buildListOfLanguages() {];}+/**+ * Turns the `allowedHtmlTags` option — a flat list of tag names, shared with the server-side+ * sanitizer — into the General HTML Support allow-list.+ *+ * The wrapping is not cosmetic. `DataFilter#loadAllowedConfig` reads each entry's `name` and falls+ * back to a match-everything pattern without one, so bare strings allowed *every* element, including+ * GHS's `$customElement` catch-all: unknown tags round-tripped as opaque blobs that the editing view+ * drew as an empty `<span data-ck-unsafe-element>` — visible in read mode and search, invisible and+ * un-navigable while editing (#10989). `attributes`/`classes`/`styles` are the per-element rules+ * `splitRules` looks for; without them GHS strips every attribute off what it does preserve.+ */+function buildHtmlSupportConfig(): EditorConfig["htmlSupport"] {+ const allowedTags: string[] = JSON.parse(options.get("allowedHtmlTags"));++ return {+ allow: allowedTags.map((name) => ({ name, attributes: true, classes: true, styles: true }))+ };+}+function getDisabledPlugins() {const disabledPlugins: string[] = [];