Skip to content

Commit 8c07af3

Browse files
authored
FEAT: mermaid support (#5)
1 parent 795fb76 commit 8c07af3

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

_includes/mermaid_support.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!-- Load Mermaid.js from a CDN -->
2+
<script src="https://unpkg.com/mermaid@11/dist/mermaid.min.js"></script>
3+
4+
<!-- Initialize Mermaid when the page loads -->
5+
<script>
6+
document.addEventListener("DOMContentLoaded", function() {
7+
// Select all code blocks with 'language-mermaid'
8+
document.querySelectorAll('pre code.language-mermaid').forEach(function(codeBlock) {
9+
// Extract the mermaid code
10+
const mermaidCode = codeBlock.textContent.trim();
11+
12+
// Create a new div with class 'mermaid'
13+
const mermaidDiv = document.createElement('div');
14+
mermaidDiv.className = 'mermaid';
15+
mermaidDiv.textContent = mermaidCode;
16+
17+
// Replace the parent <pre> block with our new mermaid div
18+
const pre = codeBlock.parentNode;
19+
pre.parentNode.replaceChild(mermaidDiv, pre);
20+
});
21+
22+
// Now initialize Mermaid
23+
mermaid.initialize({ startOnLoad: true });
24+
});
25+
</script>

_layouts/default.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<link rel="stylesheet" href="{{ site.baseurl }}/assets/css/columns.css">
99

1010
{% include mathjax_support.html %}
11+
{% include mermaid_support.html %}
1112
</head>
1213
<body>
1314
<div class="container-lg px-3 my-5 markdown-body">

0 commit comments

Comments
 (0)