MCPcopy
hub / github.com/marktext/marktext / renderMermaid

Method renderMermaid

packages/muya/src/state/markdownToHtml.ts:14–47  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12 constructor(public markdown: string, public muya?: Muya) {}
13
14 async renderMermaid() {
15 const codes = this._exportContainer!.querySelectorAll(
16 'code.language-mermaid',
17 );
18 for (const code of codes) {
19 const preEle = code.parentNode;
20 if (!isHTMLElement(preEle))
21 continue;
22 const mermaidContainer = document.createElement('div');
23 mermaidContainer.innerHTML = sanitize(
24 unescapeHTML(code.innerHTML),
25 EXPORT_DOMPURIFY_CONFIG,
26 true,
27 ) as string;
28 mermaidContainer.classList.add('mermaid');
29 preEle.replaceWith(mermaidContainer);
30 }
31 const mermaid = await loadRenderer('mermaid');
32 // We only export light theme, so set mermaid theme to `default`, in the future, we can choose which theme to export.
33 mermaid.initialize({
34 startOnLoad: false,
35 securityLevel: 'strict',
36 theme: 'default',
37 });
38 await mermaid.run({
39 nodes: [...this._exportContainer!.querySelectorAll('div.mermaid')],
40 });
41 if (this.muya) {
42 mermaid.initialize({
43 securityLevel: 'strict',
44 theme: this.muya.options.mermaidTheme,
45 });
46 }
47 }
48
49 async renderDiagram() {
50 const selector

Callers 1

renderHtmlMethod · 0.95

Calls 7

isHTMLElementFunction · 0.90
sanitizeFunction · 0.90
unescapeHTMLFunction · 0.90
replaceWithMethod · 0.80
runMethod · 0.80
loadRendererFunction · 0.50
addMethod · 0.45

Tested by

no test coverage detected