fix: wrong lang type of code block

This commit is contained in:
jeffreytse 2020-08-18 14:02:07 +08:00
parent 7b212e2efb
commit 12e3f59b97

View file

@ -59,13 +59,25 @@ function smoothScrollTo(y, time) {
// Init highlight js
document.addEventListener('DOMContentLoaded', function(event) {
document.querySelectorAll('pre code').forEach((block) => {
hljs.highlightBlock(block);
var outer = block.parentElement.parentElement.parentElement;
var lang = block.getAttribute('data-lang');
if (!lang) {
for (var cls of outer.classList) {
if (cls.startsWith('language-')) {
lang = cls;
break;
}
}
if (lang) {
block.setAttribute('class', 'hljs ' + lang);
} else {
lang = block
.getAttribute('class')
.replace('hljs ', '');
}
if (lang.startsWith('language-')) {
lang = lang.substr(9);
}
block.parentNode.setAttribute('data-lang', lang);
hljs.highlightBlock(block);
});
});