Skip to content

Build your personal knowledge base with Trilium Notes

test(markdown export): stop asserting environment-dependent attribute escaping

Elian Dorand6266f17cf6a
diff --git a/packages/trilium-core/src/services/export/markdown.spec.ts b/packages/trilium-core/src/services/export/markdown.spec.ts
index 8b57629d12..2ad224b8ce 100644
--- a/packages/trilium-core/src/services/export/markdown.spec.ts
+++ b/packages/trilium-core/src/services/export/markdown.spec.ts
@@ -114,10 +114,16 @@ describe("Markdown export", () => {
'<section class="link-embed" data-url="https://e.com/?a=1&amp;b=2" data-embed-type="opengraph" data-title="A &amp; B &lt;x&gt;"></section>'
);
- expect(exported).toBe(
- '<section class="link-embed" data-url="https://e.com/?a=1&amp;b=2" data-embed-type="opengraph" data-title="A &amp; B &lt;x&gt;">' +
- '<a href="https://e.com/?a=1&amp;b=2">A &amp; B &lt;x&gt;</a></section>'
- );
+ // The fallback anchor is generated from the data attributes, so its href and title must be
+ // HTML-escaped or a title like `A & B <x>` would break the exported markup. This escaping is
+ // done deterministically with escape-html, so it holds under both test environments.
+ expect(exported).toContain('<a href="https://e.com/?a=1&amp;b=2">A &amp; B &lt;x&gt;</a>');
+
+ // The section wrapper and its data attributes survive so the preview re-imports losslessly.
+ // The escaping of `<`/`>` inside data-title is left to turndown's serializer, which differs by
+ // environment (server/node uses domino and escapes them; standalone/happy-dom uses the browser
+ // serializer and leaves them raw). It is not asserted because both forms decode to the same value.
+ expect(exported).toContain('<section class="link-embed" data-url="https://e.com/?a=1&amp;b=2" data-embed-type="opengraph"');
});
it("exports strikethrough text correctly", () => {