diff --git a/layouts/_default/_markup/render-codeblock-mermaid.html b/layouts/_default/_markup/render-codeblock-mermaid.html new file mode 100644 index 00000000..79a2f05e --- /dev/null +++ b/layouts/_default/_markup/render-codeblock-mermaid.html @@ -0,0 +1,12 @@ + +{{ if not (.Page.Scratch.Get "mermaid") }} + + + {{ .Page.Scratch.Set "mermaid" true }} +{{ end }} + + +{{ .Page.Scratch.Set "mermaid" true }} +
+ {{- .Inner -}} +diff --git a/layouts/partials/foot.html b/layouts/partials/foot.html index e27cce58..99dbffa6 100644 --- a/layouts/partials/foot.html +++ b/layouts/partials/foot.html @@ -4,8 +4,3 @@ {{- $searchConfig := resources.Get "search/config.json" | resources.ExecuteAsTemplate $searchConfigFile . | resources.Minify -}} {{- $searchConfig.Publish -}} {{ end }} - - -{{ if and (findRE "[\n^]```mermaid[\n ]" .RawContent) (not (.Scratch.Get "mermaid")) }} - -{{ end }} diff --git a/src/js/mermaid.js b/src/js/mermaid.js index 1b85aa90..263dd6df 100644 --- a/src/js/mermaid.js +++ b/src/js/mermaid.js @@ -18,20 +18,19 @@ document.addEventListener("DOMContentLoaded", function (event) { import("mermaid") .then(({ default: md }) => { - // Configure mermaid with matching color scheme md.initialize({ flowchart: { useMaxWidth: true }, theme: theme, themeVariables: { darkMode: darkMode + }, + mermaid: { + // Fix height of mermaid SVG elements (see https://github.com/mermaid-js/mermaid/issues/2481) + callback: (id) => { + document.getElementById(id).setAttribute("height", "100%") + } } }) - - // Render mermaid from shortcodes and code fences - md.init(undefined, ".mermaid,.language-mermaid", (id) => { - // Fix height of mermaid SVG elements (see https://github.com/mermaid-js/mermaid/issues/2481) - document.getElementById(id).setAttribute("height", "100%") - }) }) .catch((error) => console.error(error)) })