Extension:SyntaxHighlight

The SyntaxHighlight extension, formerly known as SyntaxHighlight_GeSHi, provides rich formatting of source code using the   tag. It is powered by the Pygments library and supports hundreds of different programming languages and file formats.

Like the  tag and   tags, the text is rendered exactly as it was typed, preserving any white space.

Usage
Once installed, you can use "syntaxhighlight" tags on wiki pages. For example,

is the result of the following wikitext markup:

In older versions (before MediaWiki 1.16), the extension used the tag. This is still supported, but  may help avoid conflicts if your source code itself contains   tags (for example XML).

Styling
If the displayed code is too big, you can adjust it by putting the following into the MediaWiki:Geshi.css page in your wiki (create it if it does not exist):

Actually this is a bug that needs to be fixed. Encasing code blocks in borders can be done by inserting a line like border: 1px dashed blue; in the div section above. Control over font family used can also be exercised by inserting a line like font-family: monospace, "Courier New" !important; into both sections above.

lang
The  attribute defines what lexer should be used. This affects how the extension highlights the source code. See the section Supported languages in this page for details of supported languages. Specifying an invalid or unknown name will tag the page with a tracking category. The message key MediaWiki:syntaxhighlight-error-category determines the category name, on this wiki it is Category:.

line
The  attribute enables line numbers.

start
The  attribute (in combination with  ) defines the first line number of the code block. For example,  will make line numbering start at 55.

highlight
The  attribute specifies one or more lines that should be marked (by highlighting those lines with a different background color). You can specify multiple line numbers separated by commas (for example, ) or ranges using two line numbers and a hyphen (for example,  ). is the result of

inline
The  attribute indicates that the source code should be inline as part of a paragraph (as opposed to being its own block). This option is available starting with MediaWiki 1.26. For backwards-compatibility, an  attribute results in the same behaviour.

For example,  is a lambda expression in Python.

Supported languages
The Pygments library provides support for hundreds of computer languages and file formats (full list and complete details in the Pygments document) and there are some mappings for some language names which were supported by GeSHi (full list).

Below is a partial list of languages that GeSHi could highlight, with strike-through for languages no longer supported after the switch to Pygments.

Configuration
Linux Windows
 * (optional): Absolute path to pygmentize of the Pygments package. The extension bundles the Pygments package and  points to the bundled version by default, but you can point to a different version, if you want to.
 * : Configure the default lexer for some wiki pages. By default this will highlight javascript and css pages. Additional content models can be configured by extensions (e.g. Lua, JSON, ..).
 * If you are hosting your Mediawiki on a Windows Mashine, you have to set the path for the Pygmentize.exe

VisualEditor integration
The plugin enables direct editing with VisualEditor. A popup is opened when a user wants to edit  or   sections. For this to work, VisualEditor must be installed and configured from the latest git version, same for Parsoid. The feature randomly does not work with older Parsoid versions.