Extension:SyntaxHighlight

The SyntaxHighlight GeSHi extension 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:

This is the result of the following 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).

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 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

 * (optional): The extension bundles the Pygments package, but you can point to a different version.
 * : 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, ..).

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.