-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMermaid.razor.js
More file actions
43 lines (37 loc) · 1.26 KB
/
Mermaid.razor.js
File metadata and controls
43 lines (37 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { addScript } from '../BootstrapBlazor/modules/utility.js'
export async function init(id, content) {
await addScript('./_content/BootstrapBlazor.Mermaid/mermaid.min.js');
await render(id, content);
}
export async function render(id, content) {
mermaid.initialize({ startOnLoad: false });
const render = await mermaid.render(`${id}-svg`, content);
if (render) {
const el = document.getElementById(id);
el.innerHTML = render.svg;
}
}
export function getContent(id) {
let svgDataUrl = "";
const el = document.getElementById(id);
if (el) {
for (let e in el.childNodes) {
if (el.childNodes[e].nodeName == "svg") {
const svgElement = el.childNodes[e];
const serializer = new XMLSerializer();
const svgString = serializer.serializeToString(svgElement);
const encodedString = encodeURIComponent(svgString);
svgDataUrl = 'data:image/svg+xml;base64,' + btoa(unescape(encodedString));
return svgDataUrl;
}
}
}
}
export function getSvgHtml(id) {
const el = document.getElementById(id);
const svg = el.querySelector('svg');
if (svg) {
return svg.outerHTML;
}
return "";
}