Highilght.js exports a few functions as methods of the hljs object.
Core highlighting function. Accepts a language name and a string with the code to highlight. The third parameter ignore_illegals, when present and evaluates to a true value, forces highlighting to finish even in case of detecting illegal syntax for the language instead of throwing an exception. Returns an object with the following properties:
Highlighting with language detection. Accepts a string with the code to highlight. Returns an object with the following properties:
Post-processing of the highlighted markup. Accepts a string with the highlighted markup and two optional values:
Applies highlighting to a DOM node containing code. Accepts a DOM node and two optional parameters for fixMarkup.
This function is the one to use to apply highlighting dynamically after page load or within initialization code of third-party Javascript frameworks.
Applies highlighting to all <pre><code>..</code></pre> blocks on a page.
To control tab replacement use global flags on hljs object before initialization:
hljs.tabReplace = ' '; //4 spaces
hljs.initHighlighting();
Attaches highlighting to the page load event.