feat: add mermaid for rendering mermaid diagram codes (#92)

This PR adds mermaid support
It also only loads the mermaid js module only if a code block that uses mermaid is present on that page
This commit is contained in:
BLZR
2024-10-23 20:21:04 +05:30
committed by GitHub
2 changed files with 10 additions and 0 deletions

View File

@ -46,6 +46,12 @@
<script defer src="{{ $c_js.Permalink }}" {{ printf "integrity=%q" $c_js.Data.Integrity | safeHTMLAttr }} crossorigin="anonymous"></script>
{{- end }}
{{- partial "mathjax.html" . -}}
{{ if .Page.Store.Get "hasMermaid" }}
<script defer type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true,theme: 'dark' });
</script>
{{ end }}
{{- if templates.Exists "partials/extra-foot.html" -}}{{- partial "extra-foot.html" . -}}{{- end }}
</body>

View File

@ -0,0 +1,4 @@
<pre class="mermaid">
{{- .Inner | safeHTML }}
</pre>
{{ .Page.Store.Set "hasMermaid" true }}