This is version . It is not the current version, and thus it cannot be edited.
[Back to current version]   [Restore this version]


This plugin implements the WikiPlugin interface, providing an execute implemenation that renders the body text as colorized source code, according to either a named syntax parameter, and/or parameter values provided at the plugin's point of invocation. Example:
[{ColorCodePlugin syntax='sql'
select count(*) from dual

The above example will attempt to load a resource named 'sql' from the webapps classpath, for example, a properties file, and use the properties in it to format the text.

  • Could someone write here a short example where to actually put .properties file. Can't get this working.
--Juhani, 26-Oct-2006

Short Properties file example -- contents & location

These properties define how (color, bold, italic) each element, such as keywords will be rendered, as well as listing the keywords and optionally, 'special' patterns in the text (see XML example below). Using the settings distributed, the example renders:

Alternatively, the configuration can be specified as immediate parameters to the Plugin, as in this cheap-and-cheerful XML example:

                  tokenizer.wordChar: '.,-,/,!,<,>'
                  tokenizer.ordinaryChar: '<,>'

(...xml document here...)

The Specials#

As well as the predefined categories of token, keyword, normal, string, number, symbol, the properties file may define any number of 'special' token classes. In the example above, the property colorcode.special.tag.pattern defined the pattern by which the special token class tag could be recognized. Otherwise 'normal' tokens that match this regular expression will be rendered according to the default special font properties, unless explictly specified by a matching colorcode.special.tag.font.color etc. definition.

See for an example of definining more than one class of special token. Notice that the StreamTokenizer has to be programmed to accept any non-alphabetic characters that form part of a special token, by including them in the tokenizer.ordinaryChar and tokenizer.wordChar properties.


(sorry, that should have read Installing)
  • Download the distribution jar(info) into the local JSPWiki/WEB-INF/lib directory.
  • Either invoke with full package name, or add to JSPWiki/WEB-INF/ plugin search path:
jspwiki.plugin.searchPath = ...,lu.intrasoft.jspwiki.plugin, ...


  • Unpack the source jar(info) into some convenient directory
  • Edit the file to set the local webserver path
    • E.g., webserver.dir=C:/Program Files/Apache Software Foundation/Tomcat 5.5
  • Run the ant task deploy


ColorCodePlugin.javaSimple WikiPlugin implemenation
ColorCodeHTML.javaNon-plugin specific code to render text as HTML (the guts of this thing)
SyntaxTokenizer.javaA StreamTokenizer subclass that configures it's options from provided properties

<< Back to Contributed Plugins

do NOT forget to include the blank line between the syntax and your code! (wont work without)
are there any pre-defined .properties for other languages?

--Max, 03-Oct-2006

Currently, the pre-defined .properties include:

SQL(info)SQL syntax highlighting (Oracle flavor)
C/C++(info)C & C++ -- full C++ '98 keyword set
Java(info)Works, but nowhere near as nice as Java2HtmlPlugin
Velocity(info)Velocity template file highlighing

The XML example above could easily be converted to a properties file, as well. It's easy enough to create one for a different syntax - I have used inline definitions for emails, bash scripts, etc., that don't occur often enough for a formal properties file.

--Roy, 03-Oct-2006

Fixed the special pattern matching to respect the '^' start-of-line anchor, making it easier to describe syntaxes such as Java .properties files:

colorcode.special.variable.pattern='^[a-zA-Z0-9 /\\.-]+'
colorcode.special.comment.pattern='^#[ -]+'
tokenizer.ordinaryChar: '#,/,.,},{,.,0x20,0x2C'
tokenizer.wordChar: '#,/,.,},{,.,0x20,0x2C'

--Roy, 05-Oct-2006

Hi Roy... nice. And a rather compact little beastie, for anyone who care to look at the code and design of the plugin -

One thing: some control over font-size would be nice... the HTML prologue/ epilogues currently come from hardcoded constants, and specify explicit sizes which would tend to override CSS?

Later: We did manage to get past this - CSS style on 'code' tag, and use !important for the font-size specification. (thanks Phil Duhs for this tip)

My preference for code snippets, is definitely *smaller* rather than *large print*. We run a development shop here not a, ahem, remedial reading course :)

--Thomas Whitmore, 11-Jan-2007

Thanks for the comments, Thomas, I have added a new way of specifying markup styles in this plugin using spans/css classes (thanks to Damien French for the use case & testing). It works like this:

Set the parameter spans to 'true' (ColorCodePlugin spans='true'), and it will insert spans with class set to the 2nd part of the property for the type of token, so if it's a symbol (property 'colorcode.symbol') it'll get class='symbol'. An external css can then define the appearance of that element.

The built-in classes are : normal, keyword, symbol, string, number, comment, and 'specials' defined will get the user-defined part used as the class name, so "" will generate class="email"

Does that help in your case?

-- Roy, 16-Jan-2007

Has anyone done a properties file for python syntax? Thanks.

-- Mariano, 27-Aug-2010

<< Back to Contributed Plugins

Add new attachment

Only authorized users are allowed to upload new attachments.

List of attachments

Kind Attachment Name Size Version Date Modified Author Change note
properties 2.2 kB 2 04-Oct-2006 16:25 Sothach
checker.bmp 5.8 kB 1 05-Oct-2006 10:30 Sothach
colorcode-plugin-src.jar 14.2 kB 5 05-Oct-2006 13:08 Sothach
colorcode-plugin.jar 13.2 kB 4 16-Jan-2007 10:51 Sothach
colorcode_eg.bmp 30.1 kB 1 29-Sep-2006 15:06 Sothach
colorcode_eg2.bmp 398.8 kB 1 29-Sep-2006 15:15 Sothach
properties 1.9 kB 2 04-Oct-2006 16:25 Sothach
project1.dtd 0.7 kB 1 09-Oct-2011 16:43
project1.xml 5.4 kB 1 09-Oct-2011 16:43
properties 2.2 kB 2 04-Oct-2006 16:25 Sothach
properties 1.9 kB 2 04-Oct-2006 16:25 Sothach
« This particular version was published on 27-Aug-2010 16:46 by AnonymousCoward.