summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjeffreytse <jeffreytse.mail@gmail.com>2020-08-18 14:02:07 +0800
committerjeffreytse <jeffreytse.mail@gmail.com>2020-08-18 14:02:07 +0800
commit12e3f59b97cd901d3c084089821118ea957b3941 (patch)
tree8cd8bcfa0f89a1820106033749e8d5581348cef9
parent7b212e2efb54ef67b119f0d200af3483af4a8228 (diff)
fix: wrong lang type of code block
-rw-r--r--assets/js/main.js16
1 files changed, 14 insertions, 2 deletions
diff --git a/assets/js/main.js b/assets/js/main.js
index 0a11d07..bb295f4 100644
--- a/assets/js/main.js
+++ b/assets/js/main.js
@@ -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);
});
});