feat: add support for Mermaid diagrams in Markdown content (#1186)
* Add support for Mermaid diagrams in markdown content
This commit introduces native Mermaid diagram rendering to the theme.
Following Hugo’s official documentation, a new custom code block renderer
(`render-codeblock-mermaid.html`) was added under `layouts/_default/` to
detect Mermaid code blocks and inject the necessary script flag into the
page context.
Additionally, the `baseof.html` template now conditionally includes the
Mermaid JS module from the CDN when a page contains a Mermaid diagram:
{{ 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, theme: 'neutral' });
</script>
{{ end }}
This enables rendering of fenced code blocks using the `mermaid` language
in markdown files without requiring any external preprocessing.
* Create article/components/mermaid and fix script version
---------
Co-authored-by: Jimmy <jimmy@cai.im>
This commit is contained in:
co-authored by
Jimmy
parent
47db505228
commit
ba9a5caa16
@@ -0,0 +1,9 @@
|
||||
{{ if .Store.Get "hasMermaid" }}
|
||||
<script type="module">
|
||||
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11.12.2/+esm';
|
||||
mermaid.initialize({
|
||||
startOnLoad: true,
|
||||
theme: 'neutral',
|
||||
});
|
||||
</script>
|
||||
{{ end }}
|
||||
Reference in New Issue
Block a user