summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);
});
});