Initialise highlighting without jQuery

Nothing against the venerable old library, but it’s only being used here as a loader for the syntax highlighter. This approach will work in everything even remotely modern (IE9+, everything else), and saves 30Kb gzipped plus parsing time on the pages it’s used on.
This commit is contained in:
Robin Whittleton 2018-12-30 16:11:33 +01:00 committed by Alex Cabal
parent cb47dc102e
commit 2affd08cf9
3 changed files with 5 additions and 7 deletions

View file

@ -1,9 +1,10 @@
'use strict';
$(function(){
document.addEventListener('DOMContentLoaded', function() {
if(hljs){
$('code.html.full, code.css.full, figure code.html').each(function(i, block) {
hljs.highlightBlock(block);
});
var blocks = document.querySelectorAll('code.html.full, code.css.full, figure code.html');
for (var i=0; i<blocks.length; i++) {
hljs.highlightBlock(blocks[i]);
};
}
});