Extension:ASHighlight
ASHighlight Release status: beta |
|||
---|---|---|---|
Implementation | Tag | ||
Description | Allows source code to be syntax highlighted on wiki pages. | ||
Author(s) | John Pye | ||
Last version | offsite SVN (2008-04-22) | ||
MediaWiki | 1.9 and up | ||
License | GPL | ||
Download | Browse, SVN README ChangeLog |
||
Example | <source lang="C">while(1){i++;}</source> | ||
|
|||
Check usage (experimental) |
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 on the right) into your 'extensions' directory, then add a line in your LocalSettings.php file. See the README for more information.
From a *nix terminal type
svn co svn://ascend4.org/code/trunk/tools/mediawiki ashighlight
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
Installation on a Windows system: highlight installs by default in the folder C:\Program Files\WinHighlight Therefore the following changes are required in ashighlight.class.php
change
define('ASHIGHLIGHT_LANG_ROOT',"/user/share/highlight/langDefs");
to
define('ASHIGHLIGHT_LANG_ROOT',"C:\Program Files\WinHighlight\langDefs");
change
function __construct($dir="/temp",$default_lang="py"){
to
function __construct($dir="C:\\temp",$default_lang="py"){
change
$cmd = "highlight --fragment"
to
$cmd = "C:\Progra~1\WinHighlight\highlight --fragment"
change
$css = $this->dir . "/" . "highlight.css";
to
$css = $this->dir . "\\" . "highlight.css";
[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
- http://ascend4.org/ExtPy (Python highlighting)
- http://ascend4.org/Calculation_of_sun_position (highlighting in the ASCEND language)
[edit] See also
- http://wiki.lyx.org/Examples/IncludeExternalProgramListing (using Highlight with LyX)
- Extension:Geshi
[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)