From 059d22ca96e1aa7e6c0b5f1da06d45ac168a4ef1 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Tue, 22 Apr 2025 05:44:50 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20Preserve=20Mermaid=20inde?= =?UTF-8?q?ntation=20disrupted=20by=20Hugo=20minify=20(#2069)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a pre tag to the Mermaid class to preserve indentation and ensure data retrieval on DOMContentLoaded --- assets/js/mermaid.js | 13 ++++++++++++- layouts/shortcodes/mermaid.html | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/assets/js/mermaid.js b/assets/js/mermaid.js index cd41e5ad..7df77a21 100644 --- a/assets/js/mermaid.js +++ b/assets/js/mermaid.js @@ -2,6 +2,17 @@ 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: { @@ -17,4 +28,4 @@ mermaid.initialize({ "ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,segoe ui,Roboto,helvetica neue,Arial,noto sans,sans-serif", fontSize: "16px", }, -}); \ No newline at end of file +}); diff --git a/layouts/shortcodes/mermaid.html b/layouts/shortcodes/mermaid.html index 7246bf82..e7d4ef24 100644 --- a/layouts/shortcodes/mermaid.html +++ b/layouts/shortcodes/mermaid.html @@ -1,3 +1,3 @@
{{ .Inner | safeHTML }}