Wiki Syntax Highlighting
SyntaxHighlight extension[edit]
The SyntaxHighlight extension relies on the Pygments library. [1]
Installation[edit]
Add the following line to LocalSettings.php:
wfLoadExtension( 'SyntaxHighlight_GeSHi' );
It's necessary to install the Pygments library on the server.
$ pip3 install Pygments
If the extension is installed somewhere that's not in the PATH, add this line to LocalSettings.php:
$wgPygmentizePath = "/usr/local/bin/pygmentize";
Formatting errors[edit]
Pages with incorrectly formatted <syntaxhightligh> tags will be added to a category named pages with syntax highlighting errors.
Any <syntaxhightligh> tag without a lang attribute will log an error. Another common lang attribute error is to set lang="bash" when the only acceptable shell language value is lang="sh". [2]
GeSHI[edit]
The following information is deprecated. Keeping it solely for archival purposes.
Use the SyntaxHighlight GeSHi extension.
Download and copy SyntaxHighlight GeSHi extension into the MediaWiki extensions folder.
Customization of the MediaWiki LocalSettings.php file:
$wgAllowUserJs = true;
$wgAllowUserCss = true;
require_once("$IP/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.php");
Basic usage:
<syntaxhighlight lang="specifyLanguageHere"> your code. (closing syntaxhighlight tag)
CSS
From within the wiki search for "MediaWiki:Custom.css" or "MediaWiki:Geshi.css" or "MediaWiki:Monobook.css". This will load up the CSS page, which can then be edited to tweak the formatting of the code. More info at [Syntax Highlighting Discussion]
Notes[edit]
- ↑ SyntaxHighlight extension - MediaWiki documentation
- ↑ Available Lexers - Pygments documentation