Open main menu

Extension:SyntaxHighlighter

MediaWiki extensions manual
OOjs UI icon advanced.svg
SyntaxHighlighter
Release status: beta
SyntaxHighlighter.png
Implementation Tag
Description Allows source code to be syntax highlighted using SyntaxHighlighter.
Author(s) Seong Jae Lee (seongjaeleetalk)
Latest version 1.2 (2012-09-01)
MediaWiki 1.18+
Database changes No
License MIT License
Download
README
<source>
Translate the SyntaxHighlighter extension if it is available at translatewiki.net
Check usage and version matrix.

The SyntaxHighlighter extension displays formatted source code with the <source> tag using the SyntaxHighlighter JavaScript library.

UsageEdit

On a wiki page, you can now use "source" elements:

<source lang="javascript" line start="2" highlight="4-6">
// SyntaxHighlighter makes your code snippets beautiful without tiring your servers.
// http://alexgorbatchev.com
var setArray = function(elems) {
    this.length = 0;
    push.apply(this, elems);
    return this;
}
</source>

The above code produces the following result on the page:

2 // SyntaxHighlighter makes your code snippets beautiful without tiring your servers.
3 // http://alexgorbatchev.com
4 var setArray = function(elems) {
5     this.length = 0;
6     push.apply(this, elems);
7     return this;
8 }

The lang parameter specifies which language you are using. For more information, please refer to the README.md file. To see how the source codes are rendered, please refer to the sample page.

InstallationEdit

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

Supported lexersEdit

Some of the supported languages and corresponding lang parameters are shown below. For the full list, please refer to the SyntaxHighlighter site.

  • C++ : cpp, c
  • C# : csharp, c-sharp
  • CSS : css
  • PHP : php
  • XML : xml, html, xhtml
  • Python : python, py
  • Java : java
  • JavaScript : jscript, js, javascript

See alsoEdit