++ed by:
DOHERTY SHLOMIF AYOUNG SZABGAB KEEDI

6 PAUSE users
2 non-PAUSE users.

Andy Lester

NAME

HTML::Tidy - Web validation in a Perl object

VERSION

Version 1.06

SYNOPSIS

    use HTML::Tidy;

    my $tidy = HTML::Tidy->new( {config_file => 'path/to/config'} );
    $tidy->ignore( type => TIDY_WARNING );
    $tidy->parse( "foo.html", $contents_of_foo );

    for my $message ( $tidy->messages ) {
        print $message->as_string;
    }

Description

HTML::Tidy is an HTML checker in a handy dandy object. It's meant as a replacement for HTML::Lint. If you're currently an HTML::Lint user looking to migrate, see the section "Converting from HTML::Lint".

Exports

Message types TIDY_WARNING and TIDY_ERROR.

Everything else is an object method.

Methods

new()

Create an HTML::Lint object.

    my $tidy = HTML::Tidy->new();

Optionally you can give a hashref of configuration parms. Currently, only config_file is supported.

    my $tidy = HTML::Tidy->new( {config_file => 'path/to/tidy.cfg'} );

This configuration file will be read and used when you clean an HTML file.

messages()

Returns the messages accumulated.

clear_messages()

Clears the list of messages, in case you want to print and clear, print and clear. If you don't clear the messages, then each time you call parse() you'll be accumulating more in the list.

ignore( parm => value [, parm => value ] )

Specify types of messages to ignore. Note that the ignore flags must be set before calling parse(). You can call ignore() as many times as necessary to set up all your restrictions; the options will stack up.

  • type => TIDY_(WARNING|ERROR)

    Specifies the type of messages you want to ignore, either warnings or errors. If you wanted, you could call ignore on both and get no messages at all.

        $tidy->ignore( type => TIDY_WARNING );
  • text => qr/regex/

  • text => [ qr/regex1/, qr/regex2/, ... ]

    Checks the text of the message against the specified regex or regexes, and ignores the message if there's a match. The value for the text parm may be either a regex, or a reference to a list of regexes.

        $tidy->ignore( text => qr/DOCTYPE/ );
        $tidy->ignore( text => [ qr/unsupported/, qr/proprietary/i ] );

parse( $filename, $str [, $str...] )

Parses a string, or list of strings, that make up a single HTML file.

The $filename parm is only used as an identifier for your use. The file is not actually read and opened.

Returns true if all went OK, or false if there was some problem calling tidy, or parsing tidy's output.

clean( $str [, $str...] )

Cleans a string, or list of strings, that make up a single HTML file.

Returns true if all went OK, or false if there was some problem calling tidy, or parsing tidy's output.

Converting From HTML::Lint

HTML::Tidy is different from HTML::Lint in a number of crucial ways.

  • It's not pure Perl

    HTML::Tidy is mostly a happy wrapper around libtidy.

  • The real work is done by someone else

    Changes to libtidy may come down the pipe that I don't have control over. That's the price we pay for having it do a darn good job.

  • It's no longer bundled with its Test:: counterpart

    HTML::Lint came bundled with Test::HTML::Lint, but Test::HTML::Tidy is a separate distribution. This saves the people who don't want the Test:: framework from pulling it in, and all its prerequisite modules.

Bugs & Feedback

I welcome your comments and suggestions. Please send them to <bug-html-tidy at rt.cpan.org> so that they can be tracked in the RT ticket tracking system.

Author

Andy Lester, <andy at petdance.com>

Copyright & License

Copyright (C) 2005 by Andy Lester

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.1 or, at your option, any later version of Perl 5 you may have available.