Extension:SyntaxHighlighterAndCodeColorizer

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png
Syntax Highlighter and Code Colorizer

Release status:Extension status stable

ImplementationTemplate:Extension#type Variable
DescriptionTemplate:Extension#description Highlight Syntax and Color Code using javascript.
Latest versionTemplate:Extension#version 3.0.83 (2010-07-02)
MediaWikiTemplate:Extension#mediawiki any
Database changesTemplate:Extension#needs-updatephp No
LicenseTemplate:Extension#license LGPLv3
Download
ExampleTemplate:Extension#example <pre class="brush:[code-alias]"> …Your Code Here </pre>

Translate the SyntaxHighlighterAndCodeColorizer extension if it is available at translatewiki.net

Check usage and version matrix.

Introduction[edit]

Highlight syntax and color code using JavaScript. This plugin integrates Alex Gorbatchev’s Syntax Highlighter Tool.

Supported languages[edit]

  • ActionScript 3
  • Bash/shell
  • ColdFusion
  • C#
  • C++
  • CSS
  • Delphi
  • Diff
  • Erlang
  • Groovy
  • JavaScript
  • Java
  • JavaFX
  • Perl
  • PHP
  • Plain Text
  • PowerShell
  • Python
  • Ruby
  • Scala
  • SQL
  • Visual Basic
  • XML
  • Custom languages (several have already been created)

Example[edit]

See it in action:

Usage[edit]

Just surround your code like this (note that your code must be HTML escaped):

<pre class="brush:[code-alias]"> ...Your Code Here... </pre>

or like this:

<script type="syntaxhighlighter" class="brush: js"><![CDATA[ ...Your Code Here... ]]></script>

Replace the [code-alias] segment with the type of code you have. For a list of all available brush aliases, see here. There's some pros and cons for each of the above options here.

Admins can provide additional aliases (like <plsql> your code </plsql>) by adding to the extension file code like this:

// This is a comment. Comments are not displayed in the browser //
$wgHooks['ParserFirstCallInit'][] = 'syntaxHighlightingExtension';
 
function syntaxHighlightingExtension( &$parser ) {
    $parser->setHook( 'PLSQL', 'syntaxHighlightingRenderHtml' );
    return true;
}

function syntaxHighlightingRenderHtml($input, $args, $parser, $frame){
    return "<pre class=\"brush:sql\">\n" . $input . "</pre>";
}

Installation[edit]

  • Download the latest version of SyntaxHighlighter and extract the files in a directory called Syntax in your extensions/ folder.
  • Add the code from the files under #Code section on this page to this directory.
  • Add the following to LocalSettings.php:
require_once("{$IP}/extensions/SyntaxHighlighter/SyntaxHighlighter.php");

Alternative installation[edit]

Alternatively, you could handle the installation of the appropriate files and the generation of this content all with a script. An example of this can be seen here.

See also[edit]