Extension:ASHighlight

From MediaWiki.org

Jump to: navigation, search
Manual on MediaWiki Extensions
List of MediaWiki Extensions
ASHighlight

Release status: beta

Implementation Tag
Description Allows source code to be syntax highlighted on wiki pages.
Author(s) John Pye
Version offsite SVN (2008-04-22)
MediaWiki 1.9 and up
Download Browse, SVN
README
ChangeLog
Parameters lang="LANG",...
Example <source lang="C">while(1){i++;}</source>

This extension adds the <source> tag to present formatted source code, with support from Andre Simon's highlight program. highlight is a fast syntax highlighter (implemented using C++) with support for over 120 different languages out of the box. It has the useful feature that it can output formatted code as HTML, XHTML, XML, LaTeX or TeX.

The code is based on the GeSHi extension also offered on this wiki.

The motivation for adding support for Andre Simon's tool was that it allowed a single syntax definition file to be used across ViewVC, LaTeX/LyX-based documentation, and MediaWiki -- no need to write three different syntax definition files, which is useful if you are creating documentation for an evolving or less well-known language.

Contents

[edit] Installation

Make sure you have highlight installed (available as a binary package in most Linux distributions such as Fedora and Ubuntu). Drop the files (see SVN link above) into your 'extensions' directory, then add a line in your LocalSettings.php file. See the README for more information.

Note that this extension assumes PHP 5. It was tested using MediaWiki 1.9.3 on PHP 5.1.6, with highlight 2.4.5 on Ubuntu 6.10.

See Discussion Page for fix that works for MW 11.1.0

[edit] Usage

Use a 'source' HTML-style tag in your wiki code, and give it a 'lang' attribute that matches the standard file extension for your source code, eg 'c' for C code, 'cpp' for C++ code, 'py' for Python, etc. For example:

What it looks like What you type
while(1){
  i++;
}
<source lang="c">
while(1){
  i++;
}
</source>

[edit] Example

You can see this extension in action at

[edit] See also

[edit] Known issues

[edit] Aborts PdfBook export

Using this extension in combination with Extension:Pdf_Book may block the export of articles containing the <source> tag, as well as subsequent articles in the generated PDF. This does not affect the intermediate HTML export. Unfortunately, the current workaround is to use Extension:SyntaxHighlight GeSHi instead of ASHighlight.

(Occured with MediaWiki v1.12.0 / PdfBook v0.0.9)

Personal tools