NAME
Daizu::Plugin::SyntaxHighlight - a plugin for syntax-highlighting code samples in HTML pages
DESCRIPTION
This plugin filters XHTML content expanding any daizu::syntax-highlight
elements by passing their contents through the Text::VimColor module, which is required for it to work. The source of your articles can contain markup like this:
<daizu:syntax-highlight filetype="perl">
# A piece of Perl code which will be syntax highlighted.
my $foo = 'bar';
</daizu:syntax-highlight>
The daizu
prefix should be bound to the Daizu HTML extension namespace (which is done automatically for the content of XHTML articles). The output will be an HTML pre
element, containing text and span
elements with appropriate classes.
Extra whitespace at the start or end of the content is trimmed off.
If you want to highlight a larger amount of code, put it in a separate file and use XInclude to insert it into the syntax-highlight
element. For example:
<daizu:syntax-highlight filetype="sql">
<xi:include href="database-schema.sql" parse="text"/>
</daizu:syntax-highlight>
Note that the xi:include
element isn't indented, because that might leave an extra bit of indentation on the first line.
You can also use a different element instead of pre
. For example to highlight a Perl regular expression which appears in a paragraph, you can instead use a code
element:
<daizu:syntax-highlight filetype="perl" element="code"
>/^_index\./</daizu:syntax-highlight>
CONFIGURATION
To turn on this plugin, include the following in your Daizu CMS configuration file:
<plugin class="Daizu::Plugin::SyntaxHighlight" />
All files which have a daizu:type
property of 'article' will then be filtered by this module.
STYLING
For the highlighting to be presented properly you will have to provide some rules in your CSS stylesheet. The following works well if your pre
blocks will have a white background:
span.syn-comment { color: #0000FF }
span.syn-constant { color: #FF00FF }
span.syn-identifier { color: #008B8B }
span.syn-statement { color: #A52A2A ; font-weight: bold }
span.syn-preproc { color: #A020F0 }
span.syn-type { color: #2E8B57 ; font-weight: bold }
span.syn-special { color: #6A5ACD }
span.syn-underlined { color: #000000 ; text-decoration: underline }
span.syn-error { color: #FFFFFF ; background: #FF0000 none }
span.syn-todo { color: #0000FF ; background: #FFFF00 none }
The Daizu CMS default stylesheet has these rules included already.
METHODS
- Daizu::Plugin::SyntaxHighlight->register($cms, $whole_config, $plugin_config, $path)
-
Called by Daizu CMS when the plugin is registered. It registers the do_syntax_highlighting() method as an HTML DOM filter.
The configuration is currently ignored.
- $self->do_syntax_highlighting($cms, $file, $doc)
-
Does the actual filtering in-place on
$doc
and returns it. Currently$cms
is ignored.
COPYRIGHT
This software is copyright 2006 Geoff Richards <geoff@laxan.com>. For licensing information see this page: