1
0
This commit is contained in:
Deven Blake 2021-06-20 11:02:41 -04:00
parent 69852ed3a2
commit b2c82520d3

View File

@ -21,6 +21,7 @@
* JavaScript to work. */ * JavaScript to work. */
window.is_highlightjs_here = 0; window.is_highlightjs_here = 0;
window.is_highlighted_languages = []; window.is_highlighted_languages = [];
window.to_be_highlighted = [];
window.is_highlight_stylesheet_here = 0; window.is_highlight_stylesheet_here = 0;
window.load_highlighting = function(language){ window.load_highlighting = function(language){
var script; var script;
@ -36,17 +37,26 @@ window.load_highlighting = function(language){
window.is_highlightjs_here = 1; window.is_highlightjs_here = 1;
} }
if(window.is_highlighted_languages.indexOf(language) == -1){ if(window.is_highlighted_languages.indexOf(language) == -1){
window.to_be_highlighted.push(language);
script = document.createElement('script'); script = document.createElement('script');
script.async = false; script.async = false;
script.src = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/languages/" + language + ".min.js"; script.src = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/languages/" + language + ".min.js";
document.body.appendChild(script); script.onload = function(){
window.is_highlighted_languages.push(language);
document.querySelectorAll("pre code").forEach((element) => { document.querySelectorAll("pre code").forEach((element) => {
if(element.className == "language-" + language) worked = 0;
language = window.to_be_highlighted.shift()
if(element.className == "language-" + language){
hljs.highlightElement(element); hljs.highlightElement(element);
worked = 1;
}
if(!worked)
console.log("Could not find any elements of lang " + language + " to be highlighted.");
else
window.is_highlighted_languages.push(language);
}); });
} }
document.body.appendChild(script);
}
} }
</SCRIPT> </SCRIPT>