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 ^_^
<span>
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.
@media
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
parse()
<pre class="css-code">
<pre>
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
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:
<spans>
css-code - this is actually the class name that will be set on the <pre>> element if you have that option turned on.
css-code
<pre>>
ch-sel - Selectors
ch-sel
ch-com - Comments
ch-com
ch-p - Properties
ch-p
ch-v - Values
ch-v
ch-ps - Pseudo-selectors and pseudo-elements
ch-ps
ch-at - At-rules
ch-at
ch-n - The line numbers inserted by parse() method if that option is turned on
ch-n
.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; }
Syntax::Highlight::Engine::Kate::CSS, CSS::Parse, http://w3.org/Style/CSS/
Zoffix Znet, <zoffix at cpan.org> (http://zoffix.com, http://haslayout.net)
<zoffix at cpan.org>
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.
bug-syntax-highlight-css at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Syntax::Highlight::CSS
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Syntax-Highlight-CSS
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Syntax-Highlight-CSS
CPAN Ratings
http://cpanratings.perl.org/d/Syntax-Highlight-CSS
Search CPAN
http://search.cpan.org/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.
To install Syntax::Highlight::CSS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Syntax::Highlight::CSS
CPAN shell
perl -MCPAN -e shell install Syntax::Highlight::CSS
For more information on module installation, please visit the detailed CPAN module installation guide.