Skip to content

Build your personal knowledge base with Trilium Notes

fix(import/markdown): title deduplication breaking special chars

Elian Dorana2795f3440c5
diff --git a/src/services/import/markdown.spec.ts b/src/services/import/markdown.spec.ts
index 06d9c87d33..3be8e0a0a3 100644
--- a/src/services/import/markdown.spec.ts
+++ b/src/services/import/markdown.spec.ts
@@ -40,4 +40,12 @@ describe("markdown", () => {
expect(result).toBe(trimIndentation`\
<pre><code class="language-text-x-trilium-auto">Hi</code></pre>`);
});
+
+ it("parses duplicate title with escape correctly", () => {
+ const result = markdownService.renderToHtml(trimIndentation`\
+ # What's new
+ Hi there
+ `, "What's new")
+ expect(result).toBe(`\n<p>Hi there</p>\n`);
+ });
});
diff --git a/src/services/import/utils.ts b/src/services/import/utils.ts
index 41c42ae221..110e521cc5 100644
--- a/src/services/import/utils.ts
+++ b/src/services/import/utils.ts
@@ -1,9 +1,12 @@
"use strict";
+import { unescapeHtml } from "../utils.js";
+
function handleH1(content: string, title: string) {
let isFirstH1Handled = false;
return content.replace(/<h1[^>]*>([^<]*)<\/h1>/gi, (match, text) => {
+ text = unescapeHtml(text);
const convertedContent = `<h2>${text}</h2>`;
// strip away very first found h1 tag, if it matches the title