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

This commit is contained in:
Elian Doran 2025-03-11 17:51:35 +02:00
parent 3d10ac5e1f
commit a2795f3440
No known key found for this signature in database
2 changed files with 11 additions and 0 deletions

View File

@ -40,4 +40,12 @@ describe("markdown", () => {
expect(result).toBe(trimIndentation`\ expect(result).toBe(trimIndentation`\
<pre><code class="language-text-x-trilium-auto">Hi</code></pre>`); <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`);
});
}); });

View File

@ -1,9 +1,12 @@
"use strict"; "use strict";
import { unescapeHtml } from "../utils.js";
function handleH1(content: string, title: string) { function handleH1(content: string, title: string) {
let isFirstH1Handled = false; let isFirstH1Handled = false;
return content.replace(/<h1[^>]*>([^<]*)<\/h1>/gi, (match, text) => { return content.replace(/<h1[^>]*>([^<]*)<\/h1>/gi, (match, text) => {
text = unescapeHtml(text);
const convertedContent = `<h2>${text}</h2>`; const convertedContent = `<h2>${text}</h2>`;
// strip away very first found h1 tag, if it matches the title // strip away very first found h1 tag, if it matches the title