diff options
author | jeffreytse <jeffreytse.mail@gmail.com> | 2020-07-10 22:27:56 +0800 |
---|---|---|
committer | jeffreytse <jeffreytse.mail@gmail.com> | 2020-07-10 22:27:56 +0800 |
commit | 9204cde3538fb8f1fc3defa6c3453f5cfcfb85fe (patch) | |
tree | 41d8c4d1e84e92b037d7e140cb2b3cec6df01bdf /assets/js | |
parent | 5d8928659ec3a31a4d19a3fe0d1d37bd448fbd73 (diff) |
feat: use highlightjs as highlighter
Diffstat (limited to 'assets/js')
-rw-r--r-- | assets/js/main.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/assets/js/main.js b/assets/js/main.js index 231191b..0a11d07 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -55,3 +55,17 @@ function smoothScrollTo(y, time) { })(); } } + +// Init highlight js +document.addEventListener('DOMContentLoaded', function(event) { + document.querySelectorAll('pre code').forEach((block) => { + hljs.highlightBlock(block); + var lang = block.getAttribute('data-lang'); + if (!lang) { + lang = block + .getAttribute('class') + .replace('hljs ', ''); + } + block.parentNode.setAttribute('data-lang', lang); + }); +}); |