Skip to content

Commit

Permalink
feat: Add support for Mermaid diagrams (#55)
Browse files Browse the repository at this point in the history
* Add support for `mermaidjs` charts

* Use `textContent`

* Match light theme to that of github
  • Loading branch information
anurag-roy authored Aug 4, 2024
1 parent 2ec1f02 commit 154017d
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion cmd/template.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
Expand Down Expand Up @@ -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',
});
})}
})
};
Expand Down Expand Up @@ -111,6 +127,7 @@
loadmd();
})()
</script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.9.1/mermaid.min.js"></script>
<article id="markdown-body" class="markdown-body"></article>
</body>
</html>

0 comments on commit 154017d

Please sign in to comment.