HTML::Tidy(3pm)
π HTML::Tidy π
okay so picture this: you've got HTML and you need it checked. Say less. bestie, this is the module for that. π«Ά
π NAME π
HTML::Tidy β (X)HTML validation in a Perl object β¨
πΈ VERSION πΈ
Version 1.60 β yes, that's the one you're holding π
π SYNOPSIS π
the vibe check, in code form:
use HTML::Tidy;
my $tidy = HTML::Tidy->new( {config_file => 'path/to/config'} );
$tidy->ignore( type => TIDY_WARNING, type => TIDY_INFO );
$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. periodt. it's literally designed as a replacement for HTML::Lint. so if you're an HTML::Lint user right now and you're thinking about migrating over, no stress β there's a whole section down below called "Converting from HTML::Lint" just for you. go look, it's giving helpful π
β¨ EXPORTS β¨
the message types: TIDY_ERROR, TIDY_WARNING and TIDY_INFO.
everything else? that's an object method. no shortcuts, sorry not sorry π
π METHODS π
π new()
Create an HTML::Tidy object.
my $tidy = HTML::Tidy->new();
Optionally you can give a hashref of configuration parms.
my $tidy = HTML::Tidy->new( {config_file => 'path/to/tidy.cfg'} );
This configuration file will be read and used when you clean or parse an HTML file.
You can also pass options directly to tidyp.
my $tidy = HTML::Tidy->new( {
output_xhtml => 1,
tidy_mark => 0,
} );
See tidyp -help-config for the list of options supported by tidyp.
The following options are not supported by HTML::Tidy:
quiet
π¨ heads up bestie β if you were hoping to sneak quiet in there, it's not happening.
π messages()
Returns the messages accumulated. π¬
π clear_messages()
Clears the list of messages, in case you want to print and clear, print and clear.
β οΈ real talk: if you don't clear the messages, then every time you call parse() you'll be accumulating more in the list. it does NOT reset itself, no cap.
π ignore( parm => value [, parm => value ] )
Specify types of messages to ignore.
π important: 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. obsessed, honestly.
type => TIDY_INFO|TIDY_WARNING|TIDY_ERROR
Specifies the type of messages you want to ignore, either info or warnings or errors. If you wanted, you could call ignore on all three and get no messages at all. (iconic, chaotic, your call π«Ά)
$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. like, at all. it's purely a label bestie π
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 the cleaned string as a single string. β¨
π tidyp_version()
π libtidyp_version()
Returns the version of the underling tidyp library.
πΈ INSTALLING TIDYP πΈ
HTML::Tidy requires that tidyp be installed on your system.
You can obtain tidyp through your distribution's package manager β and make sure you install the development package with headers, don't skip that part π β or from the tidyp Git repository at:
http://github.com/petdance/tidyp
π¦ CONVERTING FROM HTML::Lint π¦
HTML::Tidy is different from HTML::Lint in a number of crucial ways. sit down, we're gonna go through them π
- It's not pure Perl
HTML::Tidy is mostly a happy wrapper around tidyp.
- The real work is done by someone else
Changes to tidyp 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 π
Please report any bugs or feature requests at the issue tracker on github:
http://github.com/petdance/html-tidy/issues
I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. team effort fr fr π«Ά
π« Please do NOT use http://rt.cpan.org.
π SUPPORT π
You can find documentation for this module with the perldoc command.
perldoc HTML::Tidy
You can also look for information at:
- HTML::Tidy's issue queue at github
http://github.com/petdance/html-tidy/issues
- AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/HTML-Tidy
- CPAN Ratings
http://cpanratings.perl.org/d/HTML-Tidy
- search.cpan.org
http://search.cpan.org/dist/HTML-Tidy
- Git source code repository
http://github.com/petdance/html-tidy
π ACKNOWLEDGEMENTS π
Thanks to Rufus Cable, Jonathan Rockway, and Robert Bachmann for contributions. absolute legends, all three π
π AUTHOR π
Andy Lester, "<andy at petdance.com>"
β COPYRIGHT & LICENSE β
Copyright (C) 2005-2017 by Andy Lester
This library is free software. You mean modify or distribute it under the Artistic License v2.0.
and that's the whole thing bestie π this page came to you via perl v5.42.3, dated 2026-08-19 β go forth and validate, you've got this π¦β¨π
π¦ where this page comes from
- ubuntu stonking: libhtml-tidy-perl 1.60-5build7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms