mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-13 14:15:47 +00:00
fix: race condition between HighlightJS and Mermaid
In some cases, the race condition could prevent Mermaid diagrams from being rendered. Fix #1434 See #1298
This commit is contained in:
1 parent
fc0d15d0d7
commit
037d75f6da
2 files changed
+8
-2
No files matched your search
@@ -396,15 +396,21 @@
|
||||
$("input[type='checkbox'][disabled]").parents('ul').addClass('task-list');
|
||||
|
||||
// Fix Mermaid.js clash with Highlight.js.
|
||||
// Refactor Mermaid code blocks as divs to prevent Highlight parsing them and enable Mermaid to parse them.
|
||||
let mermaids = [];
|
||||
[].push.apply(mermaids, document.getElementsByClassName('language-mermaid'));
|
||||
for (i = 0; i < mermaids.length; i++) {
|
||||
for (let i = 0; i < mermaids.length; i++) {
|
||||
$(mermaids[i]).unwrap('pre'); // Remove <pre> wrapper.
|
||||
$(mermaids[i]).replaceWith(function(){
|
||||
// Convert <code> block to <div> and add `mermaid` class so that Mermaid will parse it.
|
||||
return $("<div />").append($(this).contents()).addClass('mermaid');
|
||||
});
|
||||
}
|
||||
// Initialise code highlighting if enabled for this page.
|
||||
// Note: this block should be processed after the Mermaid code-->div conversion.
|
||||
if (code_highlighting) {
|
||||
hljs.initHighlighting();
|
||||
}
|
||||
|
||||
// Get theme variation (day/night).
|
||||
let defaultThemeVariation;
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
|
||||
{{/* Initialise code highlighting. */}}
|
||||
{{ if $.Scratch.Get "highlight_enabled" }}
|
||||
<script>hljs.initHighlightingOnLoad();</script>
|
||||
<script>const code_highlighting = true;</script>
|
||||
{{ end }}
|
||||
|
||||
{{ if ne site.Params.search.engine 0 }}
|
||||
|
||||
Reference in new issue
Block a user