The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Syntax::Highlight::HTML - Highlight HTML syntax

Version

Version 0.01

Synopsis

    use Syntax::Highlight::HTML;

    my $highlighter = new Syntax::Highlight::HTML;
    $colored = $highlighter->parse($html);

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

_highlight_tag()

Internal method: HTML::Parser tags handler

Highlights a tag.

_highlight_text()

Internal method: HTML::Parser text handler

Highlights text.

Notes

The result 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;

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

Author

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

See Also

HTML::Parser

Bugs

Please report any bugs or feature requests to bug-syntax-highlight-html@rt.cpan.org, or through the web interface at http://rt.cpan.org. 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.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 247:

Non-ASCII character seen before =encoding in 'Sébastien'. Assuming CP1252