[Show/Hide Right Column]

Display code syntax with line numbers and color highlights
Print

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: Image

noteNote
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:

noteNote
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.

List of languages supported by Geshi 1.0.8.9, the latest stable release 1_0_X as of August 2010 (with the exact syntax of each language code used by Geshi):

  • 4cs
  • 6502acme
  • 6502kickass
  • 6502tasm
  • 68000devpac
  • abap
  • actionscript3
  • actionscript
  • ada
  • algol68
  • apache
  • applescript
  • apt_sources
  • asm
  • asp
  • autoconf
  • autohotkey
  • autoit
  • avisynth
  • awk
  • bash
  • basic4gl
  • bf
  • bibtex
  • blitzbasic
  • bnf
  • boo
  • caddcl
  • cadlisp
  • cfdg
  • cfm
  • chaiscript
  • cil
  • clojure
  • c_mac
  • cmake
  • cobol
  • c
  • cpp
  • cpp-qt
  • csharp
  • css
  • cuesheet
  • dcs
  • delphi
  • diff
  • div
  • dos
  • dot
  • d
  • ecmascript
  • eiffel
  • email
  • e
  • erlang
  • f1
  • fo
  • fortran
  • freebasic
  • fsharp
  • gambas
  • gdb
  • genero
  • genie
  • gettext
  • glsl
  • gml
  • gnuplot
  • go
  • groovy
  • gwbasic
  • haskell
  • hicest
  • hq9plus
  • html4strict
  • icon
  • idl
  • ini
  • inno
  • intercal
  • io
  • java5
  • java
  • javascript
  • j
  • jquery
  • kixtart
  • klonec
  • klonecpp
  • latex
  • lb
  • lisp
  • locobasic
  • logtalk
  • lolcode
  • lotusformulas
  • lotusscript
  • lscript
  • lsl2
  • lua
  • m68k
  • magiksf
  • make
  • mapbasic
  • matlab
  • mirc
  • mmix
  • modula2
  • modula3
  • mpasm
  • mxml
  • mysql
  • newlisp
  • nsis
  • oberon2
  • objc
  • objeck
  • ocaml-brief
  • ocaml
  • oobas
  • oracle11
  • oracle8
  • oxygene
  • oz
  • pascal
  • pcre
  • perl6
  • perl
  • per
  • pf
  • php-brief
  • php
  • pic16
  • pike
  • pixelbender
  • plsql
  • postgresql
  • povray
  • powerbuilder
  • powershell
  • progress
  • prolog
  • properties
  • providex
  • purebasic
  • python
  • qbasic
  • q
  • rails
  • rebol
  • reg
  • robots
  • rpmspec
  • rsplus
  • ruby
  • sas
  • scala
  • scheme
  • scilab
  • sdlbasic
  • smalltalk
  • smarty
  • sql
  • systemverilog
  • tcl
  • teraterm
  • text
  • thinbasic
  • tsql
  • typoscript
  • unicon
  • vala
  • vbnet
  • vb
  • verilog
  • vhdl
  • vim
  • visualfoxpro
  • visualprolog
  • whitespace
  • whois
  • winbatch
  • xbasic
  • xml
  • xorg_conf
  • xpp
  • z80
  • zxbasic

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 Tiki's LGPL licence - the administrator will need to manually download a copy of GeSHI, from their sourceforge page or through subversion.

It is strongly 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.

To download Geshi, see: http://qbnz.com/highlighter/geshi-doc.html#getting-geshi

Once you have you copy of Geshi, you should place it in your own tiki's lib/geshi/ directory, so that once placed there the folder structure is something like:

./lib/geshi/contrib/
./lib/geshi/docs/
./lib/geshi/geshi/
./lib/geshi/geshi.php

You could alternatively install the stable version of GeSHI with the Debian/Ubuntu package "php-geshi" (check if the version of the package is fresh enough for your needs, compared to the latest stable from their website or subversion repository).

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&nbsp; &nbsp;...&nbsp; &nbsp; Z
        </div>
    </body>
&ndash;
</html>
{CODE}

Would produce:

Image
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&nbsp; &nbsp;...&nbsp; &nbsp; Z
        </div>    </body>
&ndash;
</html>

noteNote
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.


Contributors to this page: Marc Laporte5511 points  , Xavi36278 points  , Danny Staple13 points  , lindon2331 points  , Greg Martin49 points  , dthacker1330 points  and Jean-François B.722 points  .
Page last modified on Saturday 21 August, 2010 06:23:54 UTC by Marc Laporte5511 points .

Find by Page Name

Exact match

Keywords

The following is a list of keywords that should serve as hubs for navigation within the Tiki documentation and should correspond to development keywords (bug reports and feature requests):