Skip to content

Commit

Permalink
Support inline fenceposts for mermaid
Browse files Browse the repository at this point in the history
  • Loading branch information
jmandel committed May 23, 2024
1 parent 792db42 commit 063693e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
13 changes: 11 additions & 2 deletions content/assets/js/mermaid-init.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
mermaid.initialize({
securityLevel: 'sandbox',
document.addEventListener('DOMContentLoaded', function() {
const mermaidCodes = document.querySelectorAll('pre.language-mermaid code.language-mermaid');
Array.from(mermaidCodes).forEach(function(code) {
const pre = code.parentNode;
const content = code.textContent;
const mermaidDiv = document.createElement('div');
mermaidDiv.className = 'mermaid';
mermaidDiv.textContent = content;
pre.parentNode.replaceChild(mermaidDiv, pre);
});
mermaid.initialize({ securityLevel: 'sandbox' });
});
3 changes: 2 additions & 1 deletion includes/fragment-pagebegin.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
<body onload="document.body.style.opacity='1'">
{% assign label = {{site.data.pages[page.path].label}} | split: '.0' %}
<script src="{{site.data.info.assets}}assets/js/prism.js"></script>

<script type="text/javascript" src="{{site.data.info.assets}}assets/js/mermaid.js"></script>
<script type="text/javascript" src="{{site.data.info.assets}}assets/js/mermaid-init.js"></script>
<style type="text/css">h2{--heading-prefix:"{{site.data.info.headingOffset}}{{label}}"}
h3,h4,h5,h6{--heading-prefix:"{{site.data.info.headingOffset}}{{site.data.pages[page.path].label}}"}</style>
<div id="segment-header" class="segment"> <!-- segment-header -->
Expand Down
2 changes: 0 additions & 2 deletions includes/fragment-pageend.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@
<script type="text/javascript" src="assets/js/clipboard.min.js"> </script>
<script type="text/javascript" src="assets/js/clipboard-btn.js"> </script>
<script type="text/javascript" src="{{site.data.info.assets}}assets/js/anchor-hover.js"> </script>
<script type="text/javascript" src="{{site.data.info.assets}}assets/js/mermaid.js"> </script>
<script type="text/javascript" src="{{site.data.info.assets}}assets/js/mermaid-init.js"> </script>
<!-- Analytics Below
================================================== -->
</body>
Expand Down

0 comments on commit 063693e

Please sign in to comment.