!!Color Code Plugin
By [RoyPhillips]

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.
[{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|ColorCodePluginProperties], 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|ColorCodePlugin_properties_eg] -- hope this helps, Roy
;:and... Add the package lu.intrasoft.jspwiki.plugin to the plugin searchpath in the file WEB_INF/jspwiki.properties (for example jspwiki.plugin.searchPath = lu.intrasoft.jspwiki.plugin).

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:

[{Image src='colorcode_eg.bmp' width='99%;' }]

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...)
[{Image src='colorcode_eg2.bmp' width='99%;' }]

!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 [vm.properties] 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|colorcode-plugin.jar] into the local {{JSPWiki/WEB-INF/lib}} directory.
*Either invoke with full package name, or add to {{JSPWiki/WEB-INF/jspwiki.properties}} plugin search path:
;:{{jspwiki.plugin.searchPath = ...,lu.intrasoft.jspwiki.plugin, ...}}

*Unpack the [source jar|colorcode-plugin-src.jar] into some convenient directory
*Edit the {{build.properties}} 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.java|]|Simple {{[WikiPlugin|JSPWikiPlugin]}} implemenation
|[ColorCodeHTML.java|]|Non-plugin specific code to render text as HTML (the guts of this thing)
|[SyntaxTokenizer.java|]|A {{~StreamTokenizer}} subclass that configures it's options from provided properties

[<< Back to Contributed Plugins|ContributedPlugins]


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|sql.properties]|SQL syntax highlighting (Oracle flavor)
|[C/C++|c.properties]|C & C++ -- full C++ '98 keyword set
|[Java|java.properties]|Works, but nowhere near as nice as [Java2HtmlPlugin]
|[Velocity|vm.properties]|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

[<< Back to Contributed Plugins|ContributedPlugins]