git@cosmocr.at/gitweb.git @ HEAD · summary refs log
HEAD / web / mermaid-init.js /
web/mermaid-init.js · 1003 B · raw
view: SourceMarkdown ☑ force

"use strict"; // Rendered markdown may contain

 diagram blocks. This tiny
// script is loaded on every markdown/git page but does nothing unless such a
// block is present, in which case it lazy-loads the (large) mermaid bundle and
// draws the diagrams. Keeping the load conditional means ordinary pages stay
// script-light, and everything is served same-origin (no CDN).
(function () {
if (!document.querySelector(".mermaid")) return;
var s = document.createElement("script");
s.src = "/_assets/mermaid.min.js";
s.onload = function () {
try {
// securityLevel "strict" disables click handlers and HTML in labels, so
// diagram source from a repo cannot inject markup or scripts.
window.mermaid.initialize({ startOnLoad: false, securityLevel: "strict" });
window.mermaid.init(undefined, document.querySelectorAll(".mermaid"));
} catch (e) {
console.error("mermaid render failed:", e);
}
};
document.head.appendChild(s);
})();