From 8107dab6f7e770e78000bc65a3339bc3d900c264 Mon Sep 17 00:00:00 2001 From: Andreas Deininger Date: Thu, 20 Oct 2022 18:12:03 +0200 Subject: [PATCH] mermaid diagrams: automatic activation (with hugo >=0.93.0) --- assets/js/mermaid.js | 17 ++++++++++++++--- .../_markup/render-codeblock-mermaid.html | 2 ++ layouts/partials/scripts.html | 9 +++++++-- userguide/config.yaml | 3 --- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/assets/js/mermaid.js b/assets/js/mermaid.js index 9580739917..90d162ebab 100644 --- a/assets/js/mermaid.js +++ b/assets/js/mermaid.js @@ -1,10 +1,22 @@ -{{ with .Site.Params.mermaid }} -{{ if .enable }} +{{ $needmermaid := or .Site.Params.mermaid.enable -}} +{{ if ge hugo.Version "0.93.0" -}} + {{ $needmermaid = or $needmermaid (.Page.Store.Get "hasmermaid") -}} +{{ end }} + +{{ if $needmermaid }} (function($) { var needMermaid = false; + +{{ if ge hugo.Version "0.93.0" -}} if ($('.mermaid').length > 0) { needMermaid = true; }; +{{ else -}} + $('.language-mermaid').parent().replaceWith(function() { + needMermaid = true; + return $('
').text($(this).text());
+    });
+{{ end -}}
 
     if (!needMermaid)  {
         mermaid.initialize({startOnLoad: false});
@@ -34,4 +46,3 @@
     mermaid.initialize(settings);
 })(jQuery);
 {{ end }}
-{{ end }}
diff --git a/layouts/_default/_markup/render-codeblock-mermaid.html b/layouts/_default/_markup/render-codeblock-mermaid.html
index 85166b1de9..0b8d7c01bd 100644
--- a/layouts/_default/_markup/render-codeblock-mermaid.html
+++ b/layouts/_default/_markup/render-codeblock-mermaid.html
@@ -1,3 +1,5 @@
+{{ .Page.Store.Set "hasmermaid" true -}}
+
 
{{- .Inner | safeHTML }}
diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html index 9cc401bbbb..b47d8ba7c4 100644 --- a/layouts/partials/scripts.html +++ b/layouts/partials/scripts.html @@ -1,5 +1,10 @@ -{{ if .Site.Params.mermaid.enable -}} - +{{ $needmermaid := or .Site.Params.mermaid.enable -}} +{{ if ge hugo.Version "0.93.0" -}} + {{ $needmermaid = or $needmermaid (.Page.Store.Get "hasmermaid") -}} +{{ end }} + +{{ if $needmermaid -}} + {{ end -}} {{ if .Site.Params.markmap.enable -}} diff --git a/userguide/config.yaml b/userguide/config.yaml index dd3ba61bca..483d2bfd3c 100644 --- a/userguide/config.yaml +++ b/userguide/config.yaml @@ -106,9 +106,6 @@ params: icon: fa-brands fa-github desc: Development takes place here! - mermaid: - enable: true - theme: default plantuml: enable: true theme: default