Extension:SyntaxHighlighter

From MediaWiki.org
Jump to navigation Jump to search
Not to be confused with Extension:SyntaxHighlight.
MediaWiki extensions manual
Crystal Clear action run.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
Tags
<source>
Hooks used
ParserFirstCallInit
ParserAfterTidy
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.

Usage[edit source]

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.

Installation[edit source]

  • 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";
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Supported lexers[edit source]

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 also[edit source]