fix(markdown): mermaid not rendering

This commit is contained in:
Elian Doran
2026-04-17 07:35:17 +03:00
parent 822e7ffbab
commit 5ef74d5639
2 changed files with 9 additions and 1 deletions

View File

@@ -70,6 +70,11 @@ describe("renderWithSourceLines", () => {
expect(html).toContain('<aside class="admonition note">');
});
it("preserves the `mermaid` fence language so the mermaid rewrite can match it", () => {
const html = renderWithSourceLines("```mermaid\ngraph TD;\nA-->B;\n```");
expect(html).toContain('class="language-mermaid"');
});
it("produces math-tex spans for inline math", () => {
const html = renderWithSourceLines("Energy: $e=mc^2$.");
expect(html).toContain('<span class="math-tex">');

View File

@@ -155,7 +155,10 @@ class CustomMarkdownRenderer extends Renderer {
text = escapeHtml(text).replace(/&quot;/g, '"');
const ckEditorLanguage = getNormalizedMimeFromMarkdownLanguage(lang);
// `mermaid` isn't in the MIME dictionary, but CKEditor/Trilium's
// mermaid rewrite specifically looks for `language-mermaid`, so
// preserve the fence language verbatim instead of falling back to auto.
const ckEditorLanguage = lang === "mermaid" ? "mermaid" : getNormalizedMimeFromMarkdownLanguage(lang);
return `<pre><code class="language-${ckEditorLanguage}">${text}</code></pre>`;
}