NAME
Syntax::Highlight::HTML - Highlight HTML syntax
VERSION
Version 0.04
SYNOPSIS
use Syntax::Highlight::HTML;
my $highlighter = new Syntax::Highlight::HTML;
$output = $highlighter->parse($html);
If $html contains the following HTML fragment:
<!-- a description list -->
<dl compact="compact">
  <dt>some word</dt>
  <dd>the description of the word. Plus some <a href="/definitions/other_word"
  >reference</a> towards another definition. </dd>
</dl>
then the resulting HTML contained in $output will render like this:
    <!-- a description list -->
    <dl compact="compact">
      <dt>some word</dt>
      <dd>the description of the word. Plus some <a href="/definitions/other_word"
      >reference</a> towards another definition. </dd>
    </dl>
DESCRIPTION
This module is designed to take raw HTML input and highlight it (using a CSS stylesheet, see "Notes" for the classes). The returned HTML code is ready for inclusion in a web page.
It is intented to be used as an highlighting filter, and as such does not reformat or reindent the original HTML code.
METHODS
- new()
 - 
The constructor. Returns a
Syntax::Highlight::HTMLobject, which derives fromHTML::Parser. As such, anyHTML::parsermethod can be called on this object (that is, expect forparse()which is overloaded here).Options
nnn- Activate line numbering. Default value: 0 (disabled).pre- Surround result by<pre>...</pre>tags. Default value: 1 (enabled).
Example
To avoid surrounding the result by the
<pre>...</pre>tags:my $highlighter = Syntax::Highlight::HTML->new(pre => 0); - parse()
 - 
Parse the HTML code given in argument and returns the highlighted HTML code, ready for inclusion in a web page.
Example
$highlighter->parse("<p>Hello, world.</p>"); 
Internals Methods
The following methods are for internal use only.
- _highlight_tag()
 - 
HTML::Parsertags handler: highlights a tag. - _highlight_text()
 - 
HTML::Parsertext handler: highlights text. 
NOTES
The resulting HTML uses CSS to colourize the syntax. Here are the classes that you can define in your stylesheet.
.h-decl- for a markup declaration; in a HTML document, the only markup declaration is theDOCTYPE, like:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">.h-pi- for a process instruction like<?html ...>or<?xml ...?>.h-com- for a comment,<!-- ... -->.h-ab- for the characters'<'and'>'as tag delimiters.h-tag- for the tag name of an element.h-attr- for the attribute name.h-attv- for the attribute value.h-ent- for any entities:é«.h-lno- for the line numbers
An example stylesheet can be found in eg/html-syntax.css.
EXAMPLE
Here is an example of generated HTML output. It was generated with the script eg/highlight.pl.
The following HTML fragment (which is the beginning of http://search.cpan.org/~saper/)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <link rel="stylesheet" href="/s/style.css" type="text/css">
  <title>search.cpan.org: Sébastien Aperghis-Tramoni</title>
 </head>
 <body id="cpansearch">
<center><div class="logo"><a href="/"><img src="/s/img/cpan_banner.png" alt="CPAN"></a></div></center>
<div class="menubar">
 <a href="/">Home</a>
· <a href="/author/">Authors</a>
· <a href="/recent">Recent</a>
· <a href="/news">News</a>
· <a href="/mirror">Mirrors</a>
· <a href="/faq.html">FAQ</a>
· <a href="/feedback">Feedback</a>
</div>
<form method="get" action="/search" name="f" class="searchbox">
<input type="text" name="query" value="" size="35">
<br>in <select name="mode">
 <option value="all">All</option>
 <option value="module" >Modules</option>
 <option value="dist" >Distributions</option>
 <option value="author" >Authors</option>
</select> <input type="submit" value="CPAN Search">
</form>
will be rendered like this (using the CSS stylesheet eg/html-syntax.css):
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 5 <link rel="stylesheet" href="/s/style.css" type="text/css"> 6 <title>search.cpan.org: Sébastien Aperghis-Tramoni</title> 7 </head> 8 <body id="cpansearch"> 9 <center><div class="logo"><a href="/"><img src="/s/img/cpan_banner.png" alt="CPAN"></a></div></center> 10 <div class="menubar"> 11 <a href="/">Home</a> 12 · <a href="/author/">Authors</a> 13 · <a href="/recent">Recent</a> 14 · <a href="/news">News</a> 15 · <a href="/mirror">Mirrors</a> 16 · <a href="/faq.html">FAQ</a> 17 · <a href="/feedback">Feedback</a> 18 </div> 19 <form method="get" action="/search" name="f" class="searchbox"> 20 <input type="text" name="query" value="" size="35"> 21 <br>in <select name="mode"> 22 <option value="all">All</option> 23 <option value="module" >Modules</option> 24 <option value="dist" >Distributions</option> 25 <option value="author" >Authors</option> 26 </select> <input type="submit" value="CPAN Search"> 27 </form>
CAVEATS
Syntax::Highlight::HTML relies on HTML::Parser for parsing the HTML and therefore suffers from the same limitations.
SEE ALSO
AUTHORS
Sébastien Aperghis-Tramoni, <sebastien@aperghis.net>
BUGS
Please report any bugs or feature requests to bug-syntax-highlight-html@rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Syntax-Highlight-HTML. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
COPYRIGHT & LICENSE
Copyright (C)2004 Sébastien Aperghis-Tramoni, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.