fix: wrong lang badge of code block

This commit is contained in:
jeffreytse 2020-08-24 11:13:39 +08:00
parent 83eac8261e
commit 306203221a

View file

@ -67,16 +67,14 @@ document.addEventListener('DOMContentLoaded', function(event) {
break; break;
} }
} }
if (lang) { if (!lang) {
block.setAttribute('class', 'hljs ' + lang); cls = block.getAttribute('class');
} else { lang = cls ? cls.replace('hljs ', '') : '';
lang = block
.getAttribute('class')
.replace('hljs ', '');
} }
if (lang.startsWith('language-')) { if (lang.startsWith('language-')) {
lang = lang.substr(9); lang = lang.substr(9);
} }
block.setAttribute('class', 'hljs ' + lang);
block.parentNode.setAttribute('data-lang', lang); block.parentNode.setAttribute('data-lang', lang);
hljs.highlightBlock(block); hljs.highlightBlock(block);
}); });