Skip to content

Commit

Permalink
Format mermaid.html (google#1963)
Browse files Browse the repository at this point in the history
  • Loading branch information
chalin authored Apr 30, 2024
1 parent 41075a4 commit b984336
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions layouts/partials/scripts/mermaid.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,35 @@
{{ end -}}

<script type="module" async>
import mermaid from "{{ $cdnurl }}";
import mermaid from "{{ $cdnurl }}";

(function($) {
if ($('.mermaid').length == 0) {
mermaid.initialize({startOnLoad: false});
return;
(function ($) {
if ($('.mermaid').length == 0) {
mermaid.initialize({ startOnLoad: false });
return;
}

var params = {{ with .Site.Params.mermaid }}{{ . | jsonify | safeJS }}{{ else }}{}{{- end }};

// Site params are stored with lowercase keys; lookup correct casing
// from Mermaid default config.
var norm = function(defaultConfig, params) {
var result = {};
for (const key in defaultConfig) {
const keyLower = key.toLowerCase();
if (defaultConfig.hasOwnProperty(key) && params.hasOwnProperty(keyLower)) {
if (typeof defaultConfig[key] === "object") {
result[key] = norm(defaultConfig[key], params[keyLower]);
} else {
result[key] = params[keyLower];
}
}
var norm = function (defaultConfig, params) {
var result = {};
for (const key in defaultConfig) {
const keyLower = key.toLowerCase();
if (defaultConfig.hasOwnProperty(key) && params.hasOwnProperty(keyLower)) {
if (typeof defaultConfig[key] === "object") {
result[key] = norm(defaultConfig[key], params[keyLower]);
} else {
result[key] = params[keyLower];
}
}
return result;
}
return result;
};

var settings = norm(mermaid.mermaidAPI.defaultConfig, params);
settings.startOnLoad = true;
mermaid.initialize(settings);
})(jQuery);
})(jQuery);
</script>

0 comments on commit b984336

Please sign in to comment.