Zoffix Znet > Syntax-Highlight-CSS-0.0102 > Syntax::Highlight::CSS

Download:
Syntax-Highlight-CSS-0.0102.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.0102   Source  

NAME ^

Syntax::Highlight::CSS - highlight CSS syntax

SYNOPSIS ^

    use strict;
    use warnings;

    use Syntax::Highlight::CSS;

    my $p = Syntax::Highlight::CSS->new;

    print $p->parse('a:hover { font-weight: bold; }');

DESCRIPTION ^

The module takes CSS code and wraps different pieces of syntax into HTML <span> elements with appropriate class names which enables you to highlight syntax of the snippet using.. CSS ^_^

I honestly suggest you to try Syntax::Highlight::Engine::Kate::CSS first and see if it does what you want. Personally, I found that it wasn't interpeting @media blocks properly, but I could've been DoingItWrong. In constrast, with Syntax::Highlight::Engine::Kate::CSS you will be able to differentiate between more syntax elements than with this module.

CONSTRUCTOR ^

new

    my $p = Syntax::Highlight::CSS->new;

    my $p = Syntax::Highlight::CSS->new(
        pre => 0,
        nnn => 1,
    );

Constructs and returns a brand new Syntax::Highlight::CSS object ready to be exploited. Takes two optional arguments which are passed in a arg/value fashion. Possible arguments are as follows:

pre

    my $p = Syntax::Highlight::CSS->new( pre => 0, );

Optional. Takes either true or false values. When set to a true value, the parse() method will wrap the result into HTML <pre class="css-code"> element. Otherwise, no <pre>s will be inserted. Defaults to: 1

nnn

    my $p = Syntax::Highlight::CSS->new( nnn => 1, );

Optional. Takes either true or false values. When set to a true value will ask the highlighter to insert line numbers in the resulting code. Defaults to: 0

METHODS ^

parse

    my $highlighted_text = $p->parse('a:hover { font-weight: bold; }');

Takes one mandatory argument which is a string of CSS code to highlight. Returns the highlighted code.

COLORING YOUR HIGHLIGHTED CSS ^

To actually set any colors on your "highlighted" CSS code returned from the parse() method you need to style all the generated <spans> with CSS; a sample CSS code to do that is shown in the section below. Each <span> will have the following class names/meanings:

SAMPLE STYLE SHEET FOR COLORING HIGHLIGHTED CODE ^

    .css-code {
        font-family: 'DejaVu Sans Mono Book', monospace;
        color: #000;
        background: #fff;
    }
        .ch-sel, .ch-p, .ch-v, .ch-ps, .ch-at {
            font-weight: bold;
        }
        .ch-sel { color: #007; } /* Selectors */
        .ch-com {                /* Comments */
            font-style: italic;
            color: #777;
        }
        .ch-p {                  /* Properties */
            font-weight: bold;
            color: #000;
        }
        .ch-v {                  /* Values */
            font-weight: bold;
            color: #880;
        }
        .ch-ps {                /* Pseudo-selectors and Pseudo-elements */
            font-weight: bold;
            color: #11F;
        }
        .ch-at {                /* At-rules */
            font-weight: bold;
            color: #955;
        }
        .ch-n {
            color: #888;
        }

SEE ALSO ^

Syntax::Highlight::Engine::Kate::CSS, CSS::Parse, http://w3.org/Style/CSS/

AUTHOR ^

Zoffix Znet, <zoffix at cpan.org> (http://zoffix.com, http://haslayout.net)

BUGS ^

There are likely to be many bugs in this module. It was tested only with common CSS codes and definitely not the entire CSS spec.

Please report any bugs or feature requests to bug-syntax-highlight-css at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Syntax-Highlight-CSS. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT ^

You can find documentation for this module with the perldoc command.

    perldoc Syntax::Highlight::CSS

You can also look for information at:

COPYRIGHT & LICENSE ^

Copyright 2008 Zoffix Znet, all rights reserved.

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

syntax highlighting: