From 5b265833f5ce549dac4e73ae25997105b38a75bc Mon Sep 17 00:00:00 2001 From: Stephan Lachnit Date: Tue, 26 Apr 2022 17:01:07 +0200 Subject: [PATCH] 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 --- assets/js/mermaid.js | 5 ++--- layouts/_default/_markup/render-codeblock-mermaid.html | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 layouts/_default/_markup/render-codeblock-mermaid.html diff --git a/assets/js/mermaid.js b/assets/js/mermaid.js index 821e567872..9580739917 100644 --- a/assets/js/mermaid.js +++ b/assets/js/mermaid.js @@ -2,10 +2,9 @@ {{ if .enable }} (function($) { var needMermaid = false; - $('.language-mermaid').parent().replaceWith(function() { + if ($('.mermaid').length > 0) { needMermaid = true; - return $('
').text($(this).text());
-    });
+    };
 
     if (!needMermaid)  {
         mermaid.initialize({startOnLoad: false});
diff --git a/layouts/_default/_markup/render-codeblock-mermaid.html b/layouts/_default/_markup/render-codeblock-mermaid.html
new file mode 100644
index 0000000000..85166b1de9
--- /dev/null
+++ b/layouts/_default/_markup/render-codeblock-mermaid.html
@@ -0,0 +1,3 @@
+
+ {{- .Inner | safeHTML }} +