Automatic account creation is now enabled. Captcha authentication required for account creation and editing unless you are trusted here.
Code Extension
From WiX Wiki at MindCapers
Contents |
Description
The Code extension Paul Grinberg to beautify the wiki appearance. By taking advantage of GeSHi, the General Syntax Hilighting software, this extension can make any code listing look pretty. Also, since GeSHi supports syntax highlighting for DOS and Bash, even CLI documentation is greatly improved.
Hide InstructionsInstallation
Since GeSHi is used as the syntax highlighting engine, it must be installed first. Download the latest version from SourceForge and uncompress/unpackage it straight into the wiki/extensions directory. The extracted files will all be placed inside a folder called geshi.
Next, install Code.phpinto the wiki/extensions directory (make sure the saved filename is Code.php). Lastly, enable the extension in LocalSettings.php by adding
<?php $wgExtensionFunctions[] = "wfCodeExtension"; 'version' => '0.5', 'name' => 'Code', 'author' => 'Paul Grinberg', 'description' => 'adds <Code> tag', 'url' => 'LicSvr Extensions' ); function wfCodeExtension() { global $wgParser; $wgParser->setHook( "Code", "renderCode" ); } function renderCode($input, $argv, &$parser) { global $wgShowHideDiv; //$parser->disableCache(); //wfDebug( __METHOD__.": '$input'\n" ); // default values $language = 'text'; $showLineNumbers = false; $source = $input; $tabwidth = 4; $convertTabs = true; foreach ($argv as $key => $value) { switch ($key) { case 'lang': $language = $value; break; case 'linenumbers': $showLineNumbers = true; break; case 'tabwidth': $tabwidth = $value; break; case 'tabs': $convertTabs = false; break; case 'fileurl': $html = $parser->unstrip($parser->recursiveTagParse($value),$parser->mStripState); $url = $matches[1]; //print("URL is '$url'"); break; default : wfDebug( __METHOD__.": Requested '$key ==> $value'\n" ); break; } } include('geshi/geshi.php'); // include only once or else wiki dies } // Convert Tabs to Spaces if desired $geshi_code = $source; if ($convertTabs) { $tabSpaces = ''; for ($i=0; $i<$tabwidth; $i++) { $tabSpaces .= ' '; } } $geshi = new GeSHi($geshi_code, $language); $error = $geshi->error(); // die gracefully if errors found if ($error) { return "Code Extension Error: $error"; } if ($showLineNumbers) { // enable line numbers if requested $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS); } return $geshi->parse_code(); } ?>
require_once 'extensions/Code.php';
Usage
There are two typical usages of this extension. The first is to perform Syntax Highlighting on a code snippet that is typed directly into the wiki page
<code lang='perl' linenumbers> use strict; use warnings; print "Hello World\n"; </code>which produces
use strict; use warnings; print "Hello World\n";
The second typical usage is to pass the URL of a file containing some code directly to the extension, like so
<code fileurl='http://nostarch.com/extras/hownotc/hello4.c' lang='c'/>which produces
#include <stdio.h> int main() { printf("Hello World/n"); return (0); }
It is also sometimes nice to hide the code from the wiki page by taking advantage of the ShowHide Extension. For example,
<ShowHideDiv default='hide' showmsg='(Click to show code)' hidemsg='(Click to hide code)'><code fileurl='http://nostarch.com/extras/hownotc/hello4.c' lang='c'/></ShowHideDiv>would produce (Click to hide code)
#include <stdio.h> int main() { printf("Hello World/n"); return (0); }
The extension has the following options
| Option | Default Value | Possible Values |
|---|---|---|
| lang | Any of the supported 80+ syntaxes supported by GeSHi | |
| linenumbers | false | false, true |
| fileurl | Any URL accessible by the wiki | |
| tabwidth | 4 | Number of spaces used to replace a tab character |
| tabs | false | Leave the tabs as they were |
Supported Languages
Over 80, including ...
- c
- cpp
- csharp
- lua
- php
- sql
- text
- vb
- vbnet
- wix
- xml
Bug Reports
Revision History
- v0.5 - 4/25/2007 - Installed

