Files
blowfish/assets/js/mermaid.js
ZhenShuo Leo 059d22ca96 🐛 fix: Preserve Mermaid indentation disrupted by Hugo minify (#2069)
Add a pre tag to the Mermaid class to preserve indentation and ensure data retrieval on DOMContentLoaded
2025-04-22 05:53:15 +08:00

32 lines
1019 B
JavaScript

function css(name) {
return "rgb(" + getComputedStyle(document.documentElement).getPropertyValue(name) + ")";
}
document.addEventListener("DOMContentLoaded", () => {
const mermaidDivs = document.querySelectorAll("div.mermaid");
for (const div of mermaidDivs) {
const preElement = div.querySelector("pre");
if (preElement) {
div.textContent = preElement.textContent;
}
}
});
mermaid.initialize({
theme: "base",
themeVariables: {
background: css("--color-neutral"),
primaryColor: css("--color-primary-200"),
secondaryColor: css("--color-secondary-200"),
tertiaryColor: css("--color-neutral-100"),
primaryBorderColor: css("--color-primary-400"),
secondaryBorderColor: css("--color-secondary-400"),
tertiaryBorderColor: css("--color-neutral-400"),
lineColor: css("--color-neutral-600"),
fontFamily:
"ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,segoe ui,Roboto,helvetica neue,Arial,noto sans,sans-serif",
fontSize: "16px",
},
});