From c483ccdd011dee5e911a8367afbe1b5affe9b55d Mon Sep 17 00:00:00 2001 From: Mohan Date: Wed, 12 Aug 2026 18:28:31 +0800 Subject: [PATCH] fix(render): run code highlight on all article content --- src/utils/markdown.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/utils/markdown.ts b/src/utils/markdown.ts index 295234c..7f5262a 100644 --- a/src/utils/markdown.ts +++ b/src/utils/markdown.ts @@ -49,10 +49,12 @@ function highlightHtmlCode(html: string): string { } export function renderArticle(content: string): string { + let html: string if (content.trimStart().startsWith('<')) { - const safe = DOMPurify.sanitize(content) - return highlightHtmlCode(safe) + html = DOMPurify.sanitize(content) + } else { + const rawHtml = marked.parse(content, { async: false }) as string + html = DOMPurify.sanitize(rawHtml) } - const rawHtml = marked.parse(content, { async: false }) as string - return DOMPurify.sanitize(rawHtml) + return highlightHtmlCode(html) } \ No newline at end of file