Skip to content

Commit 5b26583

Browse files
performance: use hugo render hook for Mermaid
This switches Mermaid to use hugo's Markdown render hooks [1] instead of manipulating the string at runtime, which should improve performance by a bit. [1]: https://gohugo.io/templates/render-hooks/#render-hooks-for-code-blocks Signed-off-by: Stephan Lachnit <[email protected]>
1 parent bd991a5 commit 5b26583

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

assets/js/mermaid.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
{{ if .enable }}
33
(function($) {
44
var needMermaid = false;
5-
$('.language-mermaid').parent().replaceWith(function() {
5+
if ($('.mermaid').length > 0) {
66
needMermaid = true;
7-
return $('<pre class="mermaid">').text($(this).text());
8-
});
7+
};
98

109
if (!needMermaid) {
1110
mermaid.initialize({startOnLoad: false});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="mermaid">
2+
{{- .Inner | safeHTML }}
3+
</div>

0 commit comments

Comments
 (0)