add: mermaid support

This commit is contained in:
Junyi Hou 2024-04-09 15:20:53 +08:00
parent 775f4e9de0
commit ce5f1811c4
4 changed files with 122 additions and 2 deletions

View file

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

View file

@ -41,4 +41,15 @@
{{ if not .Params.disableComments }}
{{ partial "comments.html" . }}
{{ end }}
{{/* When you use ```mermaid``, render-codeblock-mermaid.html is called and
`.Store.Set "hasMermaid"` is executed.
`.Store.Get "hasMermaid"` will return true and mermaid.js will be loaded.
*/}}
{{ if .Store.Get "hasMermaid" }}
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
{{ end }}
{{ end }}