diff --git a/assets/js/academic.js b/assets/js/academic.js index 2888ac09..48535dc5 100644 --- a/assets/js/academic.js +++ b/assets/js/academic.js @@ -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
 wrapper.
       $(mermaids[i]).replaceWith(function(){
         // Convert  block to 
and add `mermaid` class so that Mermaid will parse it. return $("
").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; diff --git a/layouts/partials/site_js.html b/layouts/partials/site_js.html index 41945d9f..26b40290 100644 --- a/layouts/partials/site_js.html +++ b/layouts/partials/site_js.html @@ -46,7 +46,7 @@ {{/* Initialise code highlighting. */}} {{ if $.Scratch.Get "highlight_enabled" }} - + {{ end }} {{ if ne site.Params.search.engine 0 }}