Extension:SyntaxHighlighter

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
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.0 (2012-09-01)
MediaWiki 1.18+
Database changes No
License MIT
Download Project page

Git [Help]
Commit history
Note:
No localisation updates are provided by translatewiki.net.

README

Tags
<source>
Hooks used
ParserFirstCallInit

ParserAfterTidy

Translate the SyntaxHighlighter extension if possible

Check usage and version matrix; code metrics

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

Usage[edit | edit source]

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

<source lang="javascript" collapse="true" first-line="2">
// 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 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 | edit source]

The source code is hosted on Github and versioned using the Git tool (not SVN). So, you'll need Git to download or update the sources. Once git is installed, you can download the extension issuing the following command in the extensions/ directory: git clone git://github.com/seongjaelee/SyntaxHighlighter.git

That would create directory SyntaxHighlighter/, which contains the needed files, right under extensions/. If you don't want to be bothered, you can just download the zip file from the following address: https://github.com/seongjaelee/SyntaxHighlighter/zipball/master

Unzip the downloaded file in the extensions/ directory, and change the name of directory to SyntaxHighlighter/. Finally, add the following to LocalSettings.php

  require_once( "$IP/extensions/SyntaxHighlighter/SyntaxHighlighter.php" );

Many other syntax highlighting extensions also share source tag, so if you already use one, uncomment it from LocalSettings.php file.

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