Extension:SyntaxHighlighter

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png
SyntaxHighlighter

Release status:Extension status beta

SyntaxHighlighter.png
ImplementationTemplate:Extension#type Tag
DescriptionTemplate:Extension#description Allows source code to be syntax highlighted using SyntaxHighlighter.
Author(s)Template:Extension#username Seong Jae Lee (seongjaeleetalk)
Latest versionTemplate:Extension#version 1.2 (2012-09-01)
MediaWikiTemplate:Extension#mediawiki 1.18+
Database changesTemplate:Extension#needs-updatephp No
LicenseTemplate:Extension#license MIT License
Download
README
TagsTemplate:Extension#tags
<source>
Hooks usedTemplate:Extension#hook
ParserFirstCallInitManual:Hooks/ParserFirstCallInit
ParserAfterTidyManual:Hooks/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]

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]

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

Supported lexers[edit]

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]