Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reinitialize highlight.js?

My website is generating some content dynamically, so I have to somehow launch the highlight.js plugin again after loading it.

This code is used to launch the highlighter:

hljs.initHighlightingOnLoad();

I tried to do something like hljs.initHighlighting(); to do this again but it does not work.

like image 930
boreq Avatar asked Oct 26 '12 21:10

boreq


2 Answers

You must set called to false first:

hljs.initHighlighting.called = false;
hljs.initHighlighting();
like image 182
Serhii Polishchuk Avatar answered Nov 19 '22 01:11

Serhii Polishchuk


You can reinitialize all of the codeblocks like this.

$(document).ready(function() {
   $('pre code').each(function(i, e) {hljs.highlightBlock(e)});
});

or if you have a div with an ID of myBlock, you can do this.

$(document).ready(function() {
   $('#myBlock').each(function(i, e) {hljs.highlightBlock(e)});
});
like image 44
planetoftheweb Avatar answered Nov 19 '22 02:11

planetoftheweb