Stephen Sykes > Template-Plugin-HighlightPerl > Template::Plugin::HighlightPerl

Download:
Template-Plugin-HighlightPerl-0.04.tar.gz

Dependencies

Annotate this POD (1)

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.04   Source  

NAME ^

Template::Plugin::HighlightPerl - Template Toolkit plugin which implements wrapper around Syntax::Highlight::Perl module.

SYNOPSIS ^

    [% USE HighlightPerl -%]

    [% FILTER highligh_perl -%]
        [perl]Code block here[/perl]
        [code]None perl code here[/code]
        [nobr]No code and no line breaks[/nobr]
    [% END -%]

DESCRIPTION ^

Template::Plugin::HighlightPerl - Template Toolkit plugin which implements wrapper around Syntax::Highlight::Perl module and provides filter for converting perl code to syntax highlighted HTML. Also adds support for non-perl code, see below.

If you plan to use this in a blog type application, just make sure to use the proper code tags around you Perl code before you store to database.

Proper and required code tags are: Open: [perl] Close: [/perl]

Your Perl code goes between opening and closing tags. ;)

If you need to format non-perl code, use the following tags: Open: [code] Close: [/code]

If you are not using code tags and do not want line breaks: Open: [nobr] Close [/nobr]

Within your template file, use the following:

    [% USE HighlightPerl -%]

    [% FILTER highligh_perl -%]
        [% article.body %]
    [% END -%]

Where [% article.body %] is data passed to the template file from database query.

Please note that, unless you use [nobr] tags, line breaks are generated. So you will not need to use other TT2 filters, such as html_line_break or html_para. Also note that pre tags are automaticlly producted to maintain proper formatting of your Perl code, so there is no need to add white space pre to css file.

This template filter also produces CSS div classes for user customization.

Generated CSS classes for perl code: <div class="highlight_perl_head">Perl Code:</div> <div class="highlight_perl_body"><pre>Perl Code</pre></div>

Generated CSS for non-perl code: <div class="highlight_code_head">Code:<div> <div class="highlight_code_body"><pre>Non-Perl Code</pre></div>

For example, you can use the following in your css file:

    .highlight_perl_head {
        margin-left: 10px;
    }
    .highlight_perl_body {
        margin-left: 10px;
        margin-top:5px;
        margin-bottom: 5px;
        white-space: pre;
        background: #0a0a0a;
        color: #cccccc;
        font-family: monospace;
        font-size: 93%;
        border: 1px solid #555555;
        overflow: auto;
        padding: 10px;
        width: 640px;
    }
    .highlight_code_head {
        margin-left: 10px;
    }
    .highlight_code_body {
        margin-left: 10px;
        margin-top:5px;
        margin-bottom: 5px;
        white-space: pre;
        background: #0a0a0a;
        color: #cccccc;
        font-family: monospace;
        font-size: 93%;
        border: 1px solid #555555;
        overflow: auto;
        padding: 10px;
        width: 640px;
    }

This will produce nice div areas with head description and black background and auto-scoll bars for code overflow.

SEE ALSO ^

Template, Syntax::Highlight::Perl

AUTHOR ^

Stephen Sykes, <stephen@stephensykes.us>

http://www.stephensykes.us/

COPYRIGHT AND LICENSE ^

Copyright (C) 2008 StephenSykes. All Rights Reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: