fix(frontend): isolate markdown preview renderers
parent
ead70dec02
commit
398b4b31ef
|
|
@ -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(/<br\s*\/?>/gi, '<br>');
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue