summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjeffreytse <jeffreytse.mail@gmail.com>2020-08-24 11:13:39 +0800
committerjeffreytse <jeffreytse.mail@gmail.com>2020-08-24 11:13:39 +0800
commit306203221a3c17457be11ff336f6976b1789ea59 (patch)
treebdbbedb2380fcd44ea83fd90b955704d41910f0d
parent83eac8261e48a7d5278968122fe4180986662a2c (diff)
fix: wrong lang badge of code block
-rw-r--r--assets/js/main.js10
1 files changed, 4 insertions, 6 deletions
diff --git a/assets/js/main.js b/assets/js/main.js
index bb295f4..01c0ca5 100644
--- a/assets/js/main.js
+++ b/assets/js/main.js
@@ -67,16 +67,14 @@ document.addEventListener('DOMContentLoaded', function(event) {
break;
}
}
- if (lang) {
- block.setAttribute('class', 'hljs ' + lang);
- } else {
- lang = block
- .getAttribute('class')
- .replace('hljs ', '');
+ if (!lang) {
+ cls = block.getAttribute('class');
+ lang = cls ? cls.replace('hljs ', '') : '';
}
if (lang.startsWith('language-')) {
lang = lang.substr(9);
}
+ block.setAttribute('class', 'hljs ' + lang);
block.parentNode.setAttribute('data-lang', lang);
hljs.highlightBlock(block);
});