Search code examples
syntax-highlightinghighlightjs

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.


Solution

  • You must set called to false first:

    hljs.initHighlighting.called = false;
    hljs.initHighlighting();