Display code syntax with line numbers and color highlights
How to setup & use Tiki
Plugin Code
This Wiki Plugin is used to display any source code (including wiki syntax) on a page without it being processed. The code is displayed in a gray box in a fixed-width monospaced font. A title can be added to the box and the code can be highlighted and line numbers added.If a third party program called GeSHi (Generic Syntax Highlighter) has been installed on the Tiki site by the administrator, then the highligting feature is greatly enhanced. Without GeSHi, only php syntax can be highlighted and only when line numbering is turned off. With GeSHi (stable version), over 110 languages can be highlighted and used together with line numbering. Also with GeSHi (stable version), key terms in the code will be linked to the documentation page explaining the term on that language's web site.
The plugin will escape syntax, preventing tiki from accidentally parsing them, but there are a few difficult areas that you need to beware of. XML or SGML syntax may cause a hiccup if you have enabled the HTML flag on the document. This also means that you must be wary with the greater than , or less than signs.
Usage
To display code in a wiki page, use the syntax:{CODE()}
{CODE(colors=php ln="1")}
getHomeMenu();
if($menu->link != "") {
print "\t\n";
$menu->printMenu();
print "\t \n";
}
{CODE}{CODE}And if you have not figured it out yet, the example of the use of the code plugin, actually uses the code plugin - neat eh? You can recurse code tags, and it will simply render all those but the ending one. Beware: this will cause a problem if you mismatch them.
Parameters
| Parameter | Accepted values | Effect | Since |
|---|---|---|---|
| ln | without GeSHi: 0 or 1 | Adds line numbering when set to 1. Warning: Doesn't work when colors parameter is also set. | |
| with GeSHi: any number | Adds line numbering starting with the number given. Also works when colors parameter is set | ||
| colors | without GeSHi: php or highlights | Adds code syntax color highlighting for php (only). The php tag must be included at the beginning of the displayed code for the highlighting to work. The colors and ln parameters do not work together. | |
| with GeSHi: any language name that GeSHI supports (like php, javascript, css, html). See below for more information on GeSHi. | Adds color highlighting of the code syntax and key terms are linked to the documentation page on the language's site. No need to include beginning tags for the highlighting to work. Can be used together with line numbering. | ||
| caption | 0 or 1 | This allows you to provide a caption for the code box | |
| wrap | 0 or 1 | This enables line wrapping on the code, if necessary. | |
| wiki | 0 or 1 | This enables wiki interpretation of the code, otherwise wiki style markup in the code is left alone. | |
| rtl | 0 or 1 | This enables the right to left display of text | |
| ishtml | 0 or 1 | When set to 1, HTML will still be processed |
Example Without GeSHi
This code:{CODE(colors=php)}
<?php
$menu = $menubar->getHomeMenu();
if($menu->link != "") {
print "\t<td width=\"7%\" valign=\"top\">\n";
$menu->printMenu();
print "\t</td>\n";
}
{CODE}Would display:
For the color highlighting to work for php when GeSHi is not installed, it's important to include the php tag at the beginning.
GeSHi - Generic Syntax Highlighter
Supported Languages
Since Tiki 2.0., if the GeSHi package is installed additionally in the server, then many markups will be recognized and highlighted accordingly:Be careful to install the latest stable version and not the latest development version of GeSHi, otherwise only a few languages will be available and functionality will suffer.
|
|
|
|
To be certain which languages your installation of GeSHi covers, check the language files in directory where GeSHi was installed.
Installing GeSHi
Since GeSHi has been licensed under GPL - which is incompatible with Tikiwiki's LGPL licence - the administrator will need to manually download http://qbnz.com/highlighter and copy GeSHI in your own tikiwiki's lib/geshi/ directory. You can also install the stable version of GeSHI with the Debian/Ubuntu package "php-geshi".It is recommended to install the latest stable version of GeSHi (not the latest development version) because the stable version handles many more languages and has more functionality.
Examples with GeSHi
This code:
{CODE(ln=1 colors=html4strict)}
<!-- HTML example with GeSHi installed-->
<html>
<head>
<title>Hi!</title>
</head>
<body>
<div id="content" class="foo">
<p>This is the content of the page.</p>
A ... Z
</div>
</body>
–
</html>
{CODE}Would produce:
Screenshot of the output
Which should be the same to the real-time output in doc.tw.o once the geshi package is properly installed:
1 2 3 4 56 7 8 9 1011 12 13 | <!-- HTML example with GeSHi installed--> <html> <head> <title>Hi!</title> </head> <body> <div id="content" class="foo"> <p>This is the content of the page.</p> A ... Z </div> </body> – </html> |
To highlight HTML, the colors parameter needs to be set to "html4strict" when using the stable version of GeSHi. The exact spelling required for a language is determined by the name of the language file in the GeSHi directory.
Related pages
Contributors to this page: lindon
,
Xavi
,
Danny Staple
,
Marc Laporte
,
Greg Martin
,
dthacker
and
Jean-Fran
.
Page last modified on Saturday 10 July, 2010 03:40:45 UTC by lindon
.
