Extension:Highlightjs Integration

MediaWiki extensions manual
OOjs UI icon advanced-invert.svg
Highlightjs Integration
Release status: stable
Implementation Tag
Description Allows to use the client-side syntax highlighter highlight.js in MediaWiki
Author(s) Nikus Pokus
Latest version 2.1
Database changes No
License GNU Affero General Public License 3.0
<syntaxhighlight> <source>

The Highlightjs Integration extension is a drop-in replacement for the SyntaxHighlight extension. Instead of using Pygments as server-side highlighter, it uses highlight.js a client-side JavaScript highlighter. It makes the wikis which use a lot of syntax highlighting faster.


  • Download and place the file(s) in a directory called Highlightjs_Integration in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php :
    wfLoadExtension( 'Highlightjs_Integration' );
  •   Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

To users running MediaWiki 1.24 or earlier:

The instructions above describe the new way of installing this extension using wfLoadExtension(). If you need to install this extension on these earlier versions (MediaWiki 1.24 and earlier), instead of wfLoadExtension( 'Highlightjs_Integration' );, you need to use:

require_once "$IP/extensions/Highlightjs_Integration/Highlightjs_Integration.php";


Once installed, you can use the "syntaxhighlight" or the "source" tags on wiki pages. For example,

// some php code



If no "lang" attribute is defined, the highlight.js library tries itself to determine the language.
The lang="name" attribute defines what lexer should be used. This affects how the extension highlights the source code.

<syntaxhighlight lang="php">
// some php code

The highlight.js library supports 176 languages. Specifying an invalid or unknown name will make the highlight.js library unable to highlight the source code.


The attribute indicates that the source code should be inline as part of a paragraph (as opposed to being its own block). For example:

An extract of source <syntaxhighlight lang="php" inline><?php echo "Done!"; ?></syntaxhighlight> on one line.



The highlight.js library supports color themes.
To change theme edit the file "extensions/Highlightjs_Integration/extension.json" and modify the line "highlight/styles/vs2015.min.css"

    "ResourceModules": {
        "ext.HighlightjsIntegration": {
            "styles": [


By default you can use the "syntaxhighlight" or the "source" tags to highlight source code.
To add other tags or remove some, edit the file "extensions/Highlightjs_Integration/extension.json" and modify the following block:

    "config": {
        "HighlightTags": [

Mapping between languagesEdit

If you used SyntaxHighlight, you will find some languages have different names in the highlight.js library and some have missing.
To map a language name to an existing language in the highlight.js library, edit the file "extensions/Highlightjs_Integration/extension.json" and modify the following block:

    "config": {
        "LangMapping": {
            "tsql": "sql",
            "mysql": "sql",
            "vb": "vbscript",
            "vba": "vbscript",
            "xaml": "xml",
            "mediawiki": "markdown"


This extension is bundled with highlight.js version 11.5.1 and the common languages.

Bug Uncaught SyntaxError: unterminated regular expression literalEdit

The load of the highlight.min.js script in this extension raises a syntax error.
As a workaround, the highlight.min.js script is loaded from the CDNJS url instead of the file provided with this extension.

Update HighlightJSEdit

If you want a different version of the highlight.js library or add / remove languages:

  1. go on the download page of the highlight.js website and download a custom package.
  2. remove or rename the extensions/Highlightjs_Integration/highlight folder.
  3. unarchive the custom package in extensions/Highlightjs_Integration. You should have a fresh new extensions/Highlightjs_Integration/highlight folder.

To use the bundled highlight.min.js script and not the one from CDNJS:

  • replace the content of the init.js file by the following code
    cssSelector: 'pre.code2highlight, code.code2highlight, pre.mwcode'

  • update the extension.json file by adding highlight/highlight.min.js in the scripts to load in this extension
"ResourceModules": {
    "ext.HighlightjsIntegration": {
        "scripts": [

See alsoEdit