GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Syntax::Highlight::HTML(3) User Contributed Perl Documentation Syntax::Highlight::HTML(3)

Syntax::Highlight::HTML - Highlight HTML syntax

Version 0.04

    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:

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.

new()
The constructor. Returns a "Syntax::Highlight::HTML" object, which derives from "HTML::Parser". As such, any "HTML::parser" method can be called on this object (that is, expect for "parse()" 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>");
    

The following methods are for internal use only.
_highlight_tag()
"HTML::Parser" tags handler: highlights a tag.
_highlight_text()
"HTML::Parser" text handler: highlights text.

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 the "DOCTYPE", 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: "&eacute;" "&#171;"
  • ".h-lno" - for the line numbers

An example stylesheet can be found in eg/html-syntax.css.

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&#233;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>
    &middot; <a href="/author/">Authors</a>
    &middot; <a href="/recent">Recent</a>
    &middot; <a href="/news">News</a>
    &middot; <a href="/mirror">Mirrors</a>
    &middot; <a href="/faq.html">FAQ</a>
    &middot; <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>&nbsp;<input type="submit" value="CPAN Search">
    </form>

will be rendered like this (using the CSS stylesheet eg/html-syntax.css):

"Syntax::Highlight::HTML" relies on "HTML::Parser" for parsing the HTML and therefore suffers from the same limitations.

HTML::Parser

Sébastien Aperghis-Tramoni, <sebastien@aperghis.net>

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 (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.

2005-04-03 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.