From 154017d324c96bf06afb7d3059f003edcc559606 Mon Sep 17 00:00:00 2001 From: Anurag Roy Date: Sun, 4 Aug 2024 19:00:34 +0530 Subject: [PATCH] feat: Add support for Mermaid diagrams (#55) * Add support for `mermaidjs` charts * Use `textContent` * Match light theme to that of github --- cmd/template.html | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cmd/template.html b/cmd/template.html index 07b8a7b..60a3626 100644 --- a/cmd/template.html +++ b/cmd/template.html @@ -1,3 +1,4 @@ + @@ -83,7 +84,22 @@ } } MathJax.typeset(); - }) + }); + $('div.highlight-source-mermaid > pre').each(function(i, pre) { + pre.textContent = pre.textContent; + }); + + {{ if eq .Mode "dark" }} + const mermaidJsTheme = 'dark'; + {{ else if eq .Mode "light" }} + const mermaidJsTheme = 'default'; + {{ else }} + const mermaidJsTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'default'; + {{ end }} + mermaid.initialize({ startOnLoad: false, theme: mermaidJsTheme }); + mermaid.run({ + querySelector: 'div.highlight-source-mermaid > pre', + }); })} }) }; @@ -111,6 +127,7 @@ loadmd(); })() +