-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.js
28 lines (25 loc) · 912 Bytes
/
mod.js
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
const mermaidScript = `
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });`
export default function (){
return (site) => {
site.process([".html"], (pages) => {
for (const page of pages) {
const document = page.document;
if (!document) continue;
const elements = document.querySelectorAll("pre code.language-mermaid");
if (elements.length) {
const scriptElement = document.createElement("script");
scriptElement.setAttribute("type", "module")
scriptElement.textContent = mermaidScript;
document.head.appendChild(scriptElement);
}
for (const element of elements) {
const pre = element.parentElement;
pre.textContent = element.textContent;
pre.classList.add("mermaid");
}
}
});
};
}