Skip to content

Build your personal knowledge base with Trilium Notes

feat(text): make General HTML Support opt-in

Elian Doran8e9ce16b585d
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 14efdf6b7a..09d6246086 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3204,7 +3204,9 @@
"content_hints_enabled": "Content hints",
"content_hints_description": "Show short hints in the bottom corner of the editor that explain how to interact with the element under the caret or pointer.",
"auto_link_previews_enabled": "Autogenerate link previews",
- "auto_link_previews_description": "Automatically turn a detected link into a preview showing the title, description and image of the web page. Inserting a preview from the toolbar always works, regardless of this setting."
+ "auto_link_previews_description": "Automatically turn a detected link into a preview showing the title, description and image of the web page. Inserting a preview from the toolbar always works, regardless of this setting.",
+ "html_support_enabled": "Preserve unsupported HTML tags",
+ "html_support_description": "Keep the HTML tags that the editor has no feature of its own for, as listed under Options → Other → HTML import tags. They appear as blocks that cannot be edited directly, and an unrecognised tag may not be visible at all while editing. With this off, such tags are dropped from a note the first time it is edited and saved; importing is unaffected either way."
},
"table_view": {
"new-row": "New row",
diff --git a/apps/client/src/widgets/type_widgets/options/text_notes.tsx b/apps/client/src/widgets/type_widgets/options/text_notes.tsx
index 03f5014580..9c9fda6457 100644
--- a/apps/client/src/widgets/type_widgets/options/text_notes.tsx
+++ b/apps/client/src/widgets/type_widgets/options/text_notes.tsx
@@ -136,6 +136,7 @@ function EditorFeatures() {
const [slashCommandsEnabled, setSlashCommandsEnabled] = useTriliumOptionBool("textNoteSlashCommandsEnabled");
const [contentHintsEnabled, setContentHintsEnabled] = useTriliumOptionBool("textNoteContentHintsEnabled");
const [autoLinkPreviewsEnabled, setAutoLinkPreviewsEnabled] = useTriliumOptionBool("textNoteAutoLinkPreviewsEnabled");
+ const [htmlSupportEnabled, setHtmlSupportEnabled] = useTriliumOptionBool("textNoteHtmlSupportEnabled");
return (
<OptionsSection title={t("editorfeatures.title")}>
@@ -178,6 +179,14 @@ function EditorFeatures() {
currentValue={contentHintsEnabled}
onChange={setContentHintsEnabled}
/>
+
+ <OptionsRowWithToggle
+ name="html-support-enabled"
+ label={t("editorfeatures.html_support_enabled")}
+ description={t("editorfeatures.html_support_description")}
+ currentValue={htmlSupportEnabled}
+ onChange={setHtmlSupportEnabled}
+ />
</OptionsSection>
);
}
diff --git a/apps/client/src/widgets/type_widgets/text/config.spec.ts b/apps/client/src/widgets/type_widgets/text/config.spec.ts
index 18e3998758..14ccbec055 100644
--- a/apps/client/src/widgets/type_widgets/text/config.spec.ts
+++ b/apps/client/src/widgets/type_widgets/text/config.spec.ts
@@ -219,6 +219,34 @@ describe("CK config", () => {
});
describe("CK config - HTML support", () => {
+ // The feature ships off, so everything below the first two tests describes what an install that
+ // has opted back in gets.
+ beforeEach(() => {
+ optionsState.map.textNoteHtmlSupportEnabled = "true";
+ });
+
+ it("keeps GHS out of the way until the user opts in", async () => {
+ optionsState.map.textNoteHtmlSupportEnabled = "false";
+ optionsState.map.allowedHtmlTags = JSON.stringify(SANITIZER_DEFAULT_ALLOWED_TAGS);
+
+ const config = await buildConfig(baseOpts());
+
+ // The allow-list is emptied rather than narrowed: GHS decides per element, so there is no
+ // subset of the option that still means anything once the feature is off. The tag list goes
+ // on governing what the server-side sanitizer accepts on import.
+ expect(config.htmlSupport?.allow).toEqual([]);
+ });
+
+ it("treats an unset option as off, the way the shipped default is", async () => {
+ // An install predating the option has no row for it, and must not silently run with GHS on.
+ delete optionsState.map.textNoteHtmlSupportEnabled;
+ optionsState.map.allowedHtmlTags = JSON.stringify(SANITIZER_DEFAULT_ALLOWED_TAGS);
+
+ const config = await buildConfig(baseOpts());
+
+ expect(config.htmlSupport?.allow).toEqual([]);
+ });
+
it("names every allowed tag rather than handing GHS bare strings", async () => {
optionsState.map.allowedHtmlTags = JSON.stringify(["p", "section", "en-media"]);
diff --git a/apps/client/src/widgets/type_widgets/text/config.ts b/apps/client/src/widgets/type_widgets/text/config.ts
index 0477690902..b75d4bab03 100644
--- a/apps/client/src/widgets/type_widgets/text/config.ts
+++ b/apps/client/src/widgets/type_widgets/text/config.ts
@@ -389,6 +389,10 @@ 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.
*
+ * Gated on `textNoteHtmlSupportEnabled`, which ships off, so the default install runs with GHS
+ * allowing nothing and the editor keeps only what its own features model. Everything below applies
+ * once the user turns it on.
+ *
* 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
@@ -397,6 +401,12 @@ function buildListOfLanguages() {
* `splitRules` looks for; without them GHS strips every attribute off what it does preserve.
*/
function buildHtmlSupportConfig(): EditorConfig["htmlSupport"] {
+ // GHS decides per element, so switching it off is an empty allow-list rather than a narrower
+ // one — there is no subset of the option that stays meaningful here.
+ if (options.get("textNoteHtmlSupportEnabled") !== "true") {
+ return { allow: [] };
+ }
+
const allowedTags: string[] = JSON.parse(options.get("allowedHtmlTags"));
return {
diff --git a/packages/commons/src/lib/options_interface.ts b/packages/commons/src/lib/options_interface.ts
index 9c1d69ba6c..b8de13de6b 100644
--- a/packages/commons/src/lib/options_interface.ts
+++ b/packages/commons/src/lib/options_interface.ts
@@ -267,6 +267,17 @@ export interface OptionDefinitions extends KeyboardShortcutsOptions<KeyboardActi
textNoteContentHintsEnabled: boolean;
/** Whether a URL typed or pasted into a text note is automatically turned into a link preview. The "Link preview" dialog is unaffected and always inserts one on request. */
textNoteAutoLinkPreviewsEnabled: boolean;
+ /**
+ * Whether the editor preserves the HTML tags it has no editing feature of its own for — the
+ * ones named by `allowedHtmlTags`, carried through CKEditor's General HTML Support.
+ *
+ * Off by default: GHS renders such a tag as an opaque blob that is awkward to navigate and, for
+ * an unknown element, invisible while editing (#10989). The price of leaving it off is that
+ * those tags are dropped from a note the first time it is edited and saved. The server-side
+ * sanitizer reads the same `allowedHtmlTags` list and keeps accepting them on import either way,
+ * so an imported note shows them correctly until it is edited.
+ */
+ textNoteHtmlSupportEnabled: boolean;
/** Whether copying note content embeds internal images as data: URIs so they paste into external apps (internal paste stays reference-based). Hidden kill-switch. */
clipboardImageEmbedEnabled: boolean;
backgroundEffects: boolean;
diff --git a/packages/trilium-core/src/routes/api/options.ts b/packages/trilium-core/src/routes/api/options.ts
index 0831eaba60..3b38892a4e 100644
--- a/packages/trilium-core/src/routes/api/options.ts
+++ b/packages/trilium-core/src/routes/api/options.ts
@@ -135,6 +135,7 @@ const ALLOWED_OPTIONS = new Set<OptionNames>([
"textNoteSlashCommandsEnabled",
"textNoteContentHintsEnabled",
"textNoteAutoLinkPreviewsEnabled",
+ "textNoteHtmlSupportEnabled",
"clipboardImageEmbedEnabled",
"includeNoteDefaultBoxSize",
"layoutOrientation",
diff --git a/packages/trilium-core/src/services/options_init.ts b/packages/trilium-core/src/services/options_init.ts
index 4a981e3d51..2c6ed64393 100644
--- a/packages/trilium-core/src/services/options_init.ts
+++ b/packages/trilium-core/src/services/options_init.ts
@@ -323,6 +323,9 @@ const defaultOptions: DefaultOption[] = [
{ name: "textNoteSlashCommandsEnabled", value: "true", isSynced: true },
{ name: "textNoteContentHintsEnabled", value: "true", isSynced: true },
{ name: "textNoteAutoLinkPreviewsEnabled", value: "true", isSynced: true },
+ // Off: the tags this carries are the ones the editor has no feature for, and GHS's handling of
+ // them is worse than their absence. See `textNoteHtmlSupportEnabled` for what turning it off costs.
+ { name: "textNoteHtmlSupportEnabled", value: "false", isSynced: true },
{ name: "clipboardImageEmbedEnabled", value: "true", isSynced: true },
{ name: "includeNoteDefaultBoxSize", value: "medium", isSynced: true },