| Syntax-Highlight-CSS documentation | view source | Contained in the Syntax-Highlight-CSS distribution. |
Syntax::Highlight::CSS - highlight CSS syntax
use strict;
use warnings;
use Syntax::Highlight::CSS;
my $p = Syntax::Highlight::CSS->new;
print $p->parse('a:hover { font-weight: bold; }');
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.
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:
premy $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
nnnmy $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
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.
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:
css-code - this is actually the class name that will be set on the
<pre>> element if you have that option turned on. ch-sel - Selectors ch-com - Comments ch-p - Properties ch-v - Values ch-ps - Pseudo-selectors and pseudo-elements ch-at - At-rules ch-n - The line numbers inserted by parse() method if that option is
turned on .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;
}
Zoffix Znet, <zoffix at cpan.org>
(http://zoffix.com, http://haslayout.net)
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.
You can find documentation for this module with the perldoc command.
perldoc Syntax::Highlight::CSS
You can also look for information at:
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Syntax-Highlight-CSS
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-Highlight-CSS documentation | view source | Contained in the Syntax-Highlight-CSS distribution. |