From a2795f3440c5755d5ced83b5d396a36230f7d0a7 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 11 Mar 2025 17:51:35 +0200 Subject: [PATCH] fix(import/markdown): title deduplication breaking special chars --- src/services/import/markdown.spec.ts | 8 ++++++++ src/services/import/utils.ts | 3 +++ 2 files changed, 11 insertions(+) diff --git a/src/services/import/markdown.spec.ts b/src/services/import/markdown.spec.ts index 06d9c87d3..3be8e0a0a 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`\
Hi
`); }); + + it("parses duplicate title with escape correctly", () => { + const result = markdownService.renderToHtml(trimIndentation`\ + # What's new + Hi there + `, "What's new") + expect(result).toBe(`\n

Hi there

\n`); + }); }); diff --git a/src/services/import/utils.ts b/src/services/import/utils.ts index 41c42ae22..110e521cc 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>/gi, (match, text) => { + text = unescapeHtml(text); const convertedContent = `

${text}

`; // strip away very first found h1 tag, if it matches the title