fix(frontend): isolate markdown preview renderers

This commit is contained in:
jacentsao
2026-08-18 09:20:46 +08:00
committed by lyingbug
parent ead70dec02
commit 398b4b31ef
2 changed files with 7 additions and 4 deletions
+4 -2
View File
@@ -936,8 +936,10 @@ const processMarkdown = (markdownText) => {
const safeMarkdown = safeMarkdownToHTML(mathSafeText);
// 使用标记渲染
marked.use({ renderer });
let html = marked.parse(safeMarkdown) as string;
// Do not register this renderer globally. DocumentPreview uses the same
// `marked` module; registering here made its later Markdown preview reuse
// this image validator after the user had opened the chunk view.
let html = marked.parse(safeMarkdown, { renderer }) as string;
// 还原被转义的 <br>
html = html.replace(/&lt;br\s*\/?&gt;/gi, '<br>');
+3 -2
View File
@@ -239,10 +239,11 @@ async function renderMarkdown(blob: Blob) {
}
return `<pre><code class="hljs">${highlighted}</code></pre>`;
};
marked.use({ renderer });
const mathSafeText = preprocessMathDelimiters(text);
const safeText = safeMarkdownToHTML(mathSafeText);
const rawHtml = marked.parse(safeText) as string;
// Keep this renderer local. `marked.use` mutates a shared singleton and
// would otherwise inherit renderers installed by the chunk-content view.
const rawHtml = marked.parse(safeText, { renderer }) as string;
markdownHtml.value = sanitizeHTML(rawHtml);
}