Skip to content

Format mermaid.html #1963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>