Loading...
 
Display code with syntax highlighting and line numbering
This page needs review

Starting in Tiki7, CodeMirror was added as experimental for Syntax Highlighting, and in Tiki8, it becomes the default syntax highlighting. Geshi is no longer supported.

CodeMirror has several benefits:
  • The license permits us to bundle it in Tiki, and avoid a seperate download/install
  • It is in JavaScript and permits real-time and thus, a Web-based source code editor


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.



1. Usage

To display code in a wiki page, use the syntax:
{CODE(colors=php ln="1")}
<?php
$menu = $menubar->getHomeMenu();
if($menu->link != "") {
print "\t<td width=\"7%\" valign=\"top\">\n";
$menu->printMenu();
print "\t</td>\n";
}
{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.

2. 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.
rtl 0 or 1 This enables the right to left display of text


3. Example Without GeSHi but Codemirror (Tiki 8+)

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

 Note

For the color highlighting to work for php when GeSHi is not installed and you are using Tiki6 or earlier versions, it's important to include the php tag at the beginning.


3.1. Codemirror - Supported Languages

bash (?)
clike
clojure
coffeescript
css
diff
groovy
haskell
htmlmixed
javascript
jinja2
lua
markdown
ntriples
pascal
perl
php
plsql
python
r
rst
ruby
rust
scheme
smalltalk
sparql
stex
tiddlywiki
tiki
velocity
xml
xmlpure
yaml


Full list is here: http://codemirror.net/mode/


4. GeSHi - Generic Syntax Highlighter (Tiki6 LTS)

4.1. Geshi - 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:

 Note

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.

4.2. 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).

4.3. 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:
Screenshot of the output
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:

<!-- 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>


 Note

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.



alias
Plugin Code

Attached files

ID Name Comment Uploaded Size Downloads Actions
49 png codenogeshi.png Code no geshi lindon Thu 10 Jun, 2010 04:03 CEST 20.39 Kb 7652 View Download  

doc.tiki.org
[Toggle]


Keywords

Keywords serve as "hubs" for navigation within the Tiki documentation. They correspond to development keywords (bug reports and feature requests):

Accessibility (WAI and 508)
Accounting (7.x)
Articles and Submissions
Backlinks
Banners
Batch (6.x)
BigBlueButton audio/video/chat/screensharing (5.x)
Blog
Bookmark
Browser Compatibility
Link Cache
Calendar
Category
Chat
Clean URLs
Comments
Communication Center
Compression (gzip)
Contacts (Address Book)
Contact us
Content Templates
Contribution (2.x)
Cookie
Copyright
Credit (6.x)
Custom Home and Group Home Page
Date and Time
Debugger Console
Directory of hyperlinks
Documentation link from Tiki to doc.tiki.org (Help System)
Docs 8.x
Draw 7.x
Dynamic Content
Dynamic Variable
External Authentication
FAQ
Featured links
File Gallery
Forum
Friendship Network (Community)
Gmap Google maps
Groups
Hotword
HTML Page
i18n (Multilingual, l10n, Babelfish)
Image Gallery
Import-Export
Install
Integrator
Interoperability
Inter-User Messages
InterTiki
Kaltura video management (4.x)
Karma
Live Support
Login
Logs (system & action)
Look and Feel
Lost edit protection
Mail-in
Map with Mapserver
Menu
Meta Tags
Mobile Tiki and Voice Tiki
Mods
Module
MultiTiki
MyTiki
Newsletter
Notepad
Payment
Performance Speed / Load
Permissions
Platform independence (Linux-Apache, Windows/IIS, Mac, BSD)
Polls
Profiles
Profile Manager
Report
Toolbar
Quiz
Rating
Feeds
Score
Search engine optimization
Search
Search and Replace
Security
Semantic links (3.x)
Shadowbox
Shadow Layers
Share
Shopping cart
Shoutbox
Slideshow
Smiley
Social Networks
Spam protection (Anti-bot CATPCHA)
Spellcheck
Spreadsheet
Stats
Surveys
Tags (2.x)
Task
Tell a Friend, alert + Social Bookmarking
TikiTests (2.x)
Theme CSS & Smarty
Trackers
Transitions (5.x)
TRIM
User Administration including registration and banning
User Files
User Menu
Watch
WebHelp
WebDAV (5.x)
Webmail
Web Services
Wiki 3D
Wiki History, page rename, etc
Wiki Page Staging and Approval (2.x)
Wiki Plugin extends basic syntax
Wiki Syntax
Wiki structure (book and table of content)
Workspace
WSOD
WYSIWYCA
WYSIWYG (2.x)
XMLRPC


Tiki Newsletter

Delivered fresh to your email inbox!
Newsletter subscribe icon
Don't miss major announcements and other news!
Contribute to Tiki
Show php error messages