Highilght.js exports a few functions as methods of the hljs object.
Core highlighting function. Accepts a language name, or an alias, and a string with the code to highlight. The ignore_illegals parameter, 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. The continuation is an optional mode stack representing unfinished parsing. When present, the function will restart parsing from this state instead of initializing a new one. Returns an object with the following properties:
Highlighting with language detection. Accepts a string with the code to highlight and an optional array of language names and aliases restricting detection to only those languages. The subset can also be set with configure, but the local parameter overrides the option if set. Returns an object with the following properties:
Post-processing of the highlighted markup. Currently consists of replacing indentation TAB characters and using <br> tags instead of new-line characters. Options are set globally with configure.
Accepts a string with the highlighted markup.
Applies highlighting to a DOM node containing code.
This function is the one to use to apply highlighting dynamically after page load or within initialization code of third-party Javascript frameworks.
Configures global options:
Accepts an object representing options with the values to updated. Other options don’t change
hljs.configure({
tabReplace: ' ', // 4 spaces
classPrefix: '' // don't append class prefix
// … other options aren't changed
})
hljs.initHighlighting();
Applies highlighting to all <pre><code>..</code></pre> blocks on a page.
Attaches highlighting to the page load event.
Adds new language to the library under the specified name. Used mostly internally.
Looks up a language by name or alias.
Returns the language object if found, undefined otherwise.