View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Zoffix Znet > App-ZofCMS-1.001006 > App::ZofCMS::Plugin::Syntax::Highlight::HTML



Annotate this POD


View/Report Bugs
Module Version: 1.001006   Source   Latest Release: App-ZofCMS-1.001007


App::ZofCMS::Plugin::Syntax::Highlight::HTML - provide HTML code snippets on your site


In ZofCMS template:

        body        => \'index.tmpl',
        highlight_html => {
            foohtml => '<div class="bar">beer</div>',
            bar     => sub { return '<div class="bar">beer</div>' },
            beer    => \ '',
        plugins     => [ qw/Syntax::Highlight::HTML/ ],

In HTML::Template template:

    <tmpl_var name="foohtml">
    <tmpl_var name="bar">
    <tmpl_var name="beer">


The module is a plugin for App::ZofCMS. It provides means to include HTML (HyperText Markup Lanugage) code snippets with syntax highlights on your pages.

This documentation assumes you've read App::ZofCMS, App::ZofCMS::Config and App::ZofCMS::Template



        plugins => [ qw/Syntax::Highlight::HTML/ ],

First and obvious is that you'd want to include the plugin in the list of plugins to run.


        highlight_html => {
            foohtml => '<div class="bar">beer</div>',
            bar     => sub { return '<div class="bar">beer</div>' },
            beer    => \ '',

The highlight_html is the heart key of the plugin. It takes a hashref as a value. The keys of this hashref except for two special keys described below are the name of <tmpl_var name=""> tags in your HTML::Template template into which to stuff the syntax-highlighted code. The value of those keys can be either a scalar, subref or a scalarref. They are interpreted by the plugin as follows:


    highlight_html => {
        foohtml => '<div class="bar">beer</div>'

When the value of the key is a scalar it will be interpreted as HTML code to be highlighted. This will do it for short snippets.


    highlight_html => {
        beer    => \ '',

When the value is a scalarref it will be interpreted as the name of a file in the data_store dir. That file will be read and its contents will be understood as HTML code to be highlighted. If an error occured during opening of the file, your <tmpl_var name=""> tag allocated for this entry will be populated with an error message.


    highlight_html => {
        bar     => sub { return '<div class="bar">beer</div>' },

When the value is a subref, it will be executed and its return value will be taken as HTML code to highlight. The @_ of that sub when called will contain the following: $template, $query, $config where $template is a hashref of your ZofCMS template, $query is a hashref of the parameter query whether it's a POST or a GET request, and $config is the App::ZofCMS::Config object.

SPECIAL KEYS IN highlight_html

    highlight_html => {
        nnn => 1,
        pre => 0,

There are two special keys, namely nnn and pre, in highlight_html hashref. Their values will affect the resulting highlighted HTML code.


    highlight_html => {
        nnn => 1,

Instructs the highlighter to activate line numbering. Default value: 0 (disabled).


    highlight_html => {
        nnn => 0,

Instructs the highlighter to surround result by <pre>...</pre> tags. Default value: 1 (enabled).


        highlight_before => '<div class="highlights">',

Takes a scalar as a value. When specified, every highlighted HTML code will be prefixed with whatever you specify here.


        highlight_after => '</div>',

Takes a scalar as a value. When specified, every highlighted HTML code will be postfixed with whatever you specify here.


Given '<foo class="bar">beer</foo>' as input plugin will generate the following code:

        <span class="h-ab">&lt;</span><span class="h-tag">foo</span>
        <span class="h-attr">class</span>=<span class="h-attv">"bar</span>"
        <span class="h-ab">&gt;</span>beer<span class="h-ab">&lt;/</span>
        <span class="h-tag">foo</span><span class="h-ab">&gt;</span>

Now you'd use CSS to highlight specific parts of HTML syntax. Here are the classes that you can define in your stylesheet (list shamelessly stolen from Syntax::Highlight::HTML documentation):


Sebastien Aperghis-Tramoni, the author of Syntax::Highlight::HTML, was kind enough to provide sample CSS code defining the look of each element of HTML syntax. It is presented below:

    .h-decl { color: #336699; font-style: italic; }   /* doctype declaration  */
    .h-pi   { color: #336699;                     }   /* process instruction  */
    .h-com  { color: #338833; font-style: italic; }   /* comment              */
    .h-ab   { color: #000000; font-weight: bold;  }   /* angles as tag delim. */
    .h-tag  { color: #993399; font-weight: bold;  }   /* tag name             */
    .h-attr { color: #000000; font-weight: bold;  }   /* attribute name       */
    .h-attv { color: #333399;                     }   /* attribute value      */
    .h-ent  { color: #cc3333;                     }   /* entity               */

    .h-lno  { color: #aaaaaa; background: #f7f7f7;}   /* line numbers         */


Despite the ZofCMS design this module uses Syntax::Highlight::HTML which in turn uses HTML::Parser which needs a C compiler to install.

This module requires Syntax::Highlight::HTML and File::Spec (the later is part of the core)


Fork this module on GitHub:


To report bugs or request features, please use

If you can't access GitHub, you can email your request to bug-App-ZofCMS at


Zoffix Znet <zoffix at> (,


You can use and distribute this module under the same terms as Perl itself. See the LICENSE file included in this distribution for complete details.

syntax highlighting: