SyntaxHighlight
The SyntaxHighlight extension, formerly known as SyntaxHighlight_GeSHi, provides rich formatting of source code using the <syntaxhighlight> tag. It is powered by the Pygments library and supports hundreds of different programming languages and file formats.[1]
NOTE:
This extension is part of the standard MediaWiki installation.
Syntax
<syntaxhighlight lang="NAME" [PARAMETER ...]> ... </syntaxhighlight>
Parameters
- copy
- The copy attribute adds a button link that copies the content to the clipboard when clicked.
- highlight="NUMBER,[NUMBER, ...]"
- The highlight attribute specifies one or more lines that should be marked (by highlighting those lines with a different background color).
- NOTE:The line number specification ignores any renumbering of the displayed line numbers with the start attribute.
- lang="NAME"
- The lang attribute defines what lexer should be used. The language affects how the extension highlights the source code. See Supported languages for details of supported languages.
- line
- The line attribute enables line numbers.
- start="NUMBER"
- The start attribute (in combination with line) defines the first line number of the code block.
Hints
Install the Pygments package
python3 -m 'pip' install --upgrade --user 'Pygments'
Change the permissions of the pygmentize binary
chmod -R 0755 "${HOME}/.local/bin"
Configure the path to the pygmentize binary in the LocalSettings.php file
vi 'LocalSettings.php'
# Absolute path to pygmentize of the Pygments package.
$wgPygmentizePath = $_SERVER['HOME'] . '/.local/bin/pygmentize';
References
- ↑ Project contributors. "Extension:SyntaxHighlight." SyntaxHighlight project. https://www.mediawiki.org/wiki/Extension:SyntaxHighlight (accessed 19.08.2025)