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. Returns an object with the following properties:
language: language name, same as the one passed into a function, returned for consistency with highlightAutorelevance: integer valuekeyword_count integer valuevalue: HTML string with highlighting markupHighlighting with language detection. Accepts a string with the code to highlight. Returns an object with the following properties:
language: detected languagerelevance: integer valuekeyword_count: integer valuevalue: HTML string with highlighting markupsecond_best: object with the same structure for second-best heuristically detected language, may be absentPost-processing of the highlighted markup. Accepts a string with the highlighted markup and two optional values:
tabReplace: arbitrary string (may contain HTML) to replace TAB characters withuseBR: a boolean flag to replace real line-breaks with <br> which is useful for non-<pre> containers
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.