Skip to content

Commit

Permalink
fix: register extra highlight language
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Wang <[email protected]>
  • Loading branch information
ruibaby committed May 23, 2022
1 parent 8f29547 commit 31e979a
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions module/highlightjs/scripts.ftl
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
<script>
const extraLanguages = "${settings.highlight_extra_languages!''}".split(",")
extraLanguages.forEach(function (lang) {
loadScript("${theme_base!}/assets/libs/highlight.js/languages/" + lang + ".min.js");
});
document.addEventListener('DOMContentLoaded', (event) => {
(async function () {
const extraLanguages = "${settings.highlight_extra_languages!''}".split(",").filter(x => x);
for (let i = 0; i < extraLanguages.length; i++) {
const lang = extraLanguages[i];
if (lang) {
await loadScript("${theme_base!}/assets/libs/highlight.js/languages/" + lang + ".min.js");
}
}
console.log("Extra languages: ", extraLanguages);
document.querySelectorAll('pre code').forEach((el) => {
hljs.highlightElement(el);
});
console.log("Extra languages: ", extraLanguages)
console.log("Loaded languages: ", hljs.listLanguages())
});
})()
function loadScript(url) {
const script = document.createElement("script");
script.type = "text/javascript";
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
return new Promise(function (resolve, reject) {
const script = document.createElement('script');
script.type = "text/javascript";
script.src = url;
script.onload = resolve;
script.onerror = reject;
document.head.appendChild(script);
});
}
</script>

0 comments on commit 31e979a

Please sign in to comment.