From 9204cde3538fb8f1fc3defa6c3453f5cfcfb85fe Mon Sep 17 00:00:00 2001 From: jeffreytse Date: Fri, 10 Jul 2020 22:27:56 +0800 Subject: feat: use highlightjs as highlighter --- assets/js/main.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'assets/js') 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); + }); +}); -- cgit v1.2.3