1
0
mirror of https://github.com/cotes2020/jekyll-theme-chirpy.git synced 2025-12-18 05:41:31 +00:00

Integrate with mermaid-js

This commit is contained in:
Cotes Chung
2020-12-10 02:42:46 +08:00
parent 5ed39300cb
commit 4d2f13c0d7
3 changed files with 67 additions and 2 deletions

28
_includes/mermaid.html Normal file
View File

@@ -0,0 +1,28 @@
<!--
mermaid-js loader
-->
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
<script>
let initTheme = "default";
if ($("html[mode=dark]").length > 0
|| ($("html[mode]").length == 0
&& window.matchMedia("(prefers-color-scheme: dark)").matches ) ) {
initTheme = "dark";
}
let mermaidConf = {
theme: initTheme /* <default|dark|forest|neutral> */
};
/* Markdown converts to HTML */
$("pre").has("code.language-mermaid").each(function() {
let svgCode = $(this).children().html();
$(this).addClass("unloaded");
$(this).after(`<div class=\"mermaid\">${svgCode}</div>`);
});
mermaid.initialize(mermaidConf);
</script>