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