1HTML::Tidy(3) User Contributed Perl Documentation HTML::Tidy(3)
2
3
4
6 HTML::Tidy - (X)HTML validation in a Perl object
7
9 Version 1.08
10
12 use HTML::Tidy;
13
14 my $tidy = HTML::Tidy->new( {config_file => 'path/to/config'} );
15 $tidy->ignore( type => TIDY_WARNING );
16 $tidy->parse( "foo.html", $contents_of_foo );
17
18 for my $message ( $tidy->messages ) {
19 print $message->as_string;
20 }
21
23 "HTML::Tidy" is an HTML checker in a handy dandy object. It's meant as
24 a replacement for HTML::Lint. If you're currently an HTML::Lint user
25 looking to migrate, see the section "Converting from HTML::Lint".
26
28 Message types "TIDY_WARNING" and "TIDY_ERROR".
29
30 Everything else is an object method.
31
33 new()
34 Create an HTML::Tidy object.
35
36 my $tidy = HTML::Tidy->new();
37
38 Optionally you can give a hashref of configuration parms.
39
40 my $tidy = HTML::Tidy->new( {config_file => 'path/to/tidy.cfg'} );
41
42 This configuration file will be read and used when you clean or parse
43 an HTML file.
44
45 You can also pass options directly to libtidy.
46
47 my $tidy = HTML::Tidy->new( {
48 output_xhtml => 1,
49 tidy_mark => 0,
50 } );
51
52 See <http://tidy.sourceforge.net/docs/quickref.html> or "tidy
53 -help-config" for the list of options supported by libtidy.
54
55 The following options are not supported by "HTML::Tidy": quiet
56
57 messages()
58 Returns the messages accumulated.
59
60 clear_messages()
61 Clears the list of messages, in case you want to print and clear, print
62 and clear. If you don't clear the messages, then each time you call
63 parse() you'll be accumulating more in the list.
64
65 ignore( parm => value [, parm => value ] )
66 Specify types of messages to ignore. Note that the ignore flags must
67 be set before calling "parse()". You can call "ignore()" as many times
68 as necessary to set up all your restrictions; the options will stack
69 up.
70
71 · type => TIDY_(WARNING|ERROR)
72
73 Specifies the type of messages you want to ignore, either warnings
74 or errors. If you wanted, you could call ignore on both and get no
75 messages at all.
76
77 $tidy->ignore( type => TIDY_WARNING );
78
79 · text => qr/regex/
80
81 · text => [ qr/regex1/, qr/regex2/, ... ]
82
83 Checks the text of the message against the specified regex or
84 regexes, and ignores the message if there's a match. The value for
85 the text parm may be either a regex, or a reference to a list of
86 regexes.
87
88 $tidy->ignore( text => qr/DOCTYPE/ );
89 $tidy->ignore( text => [ qr/unsupported/, qr/proprietary/i ] );
90
91 parse( $filename, $str [, $str...] )
92 Parses a string, or list of strings, that make up a single HTML file.
93
94 The $filename parm is only used as an identifier for your use. The
95 file is not actually read and opened.
96
97 Returns true if all went OK, or false if there was some problem calling
98 tidy, or parsing tidy's output.
99
100 clean( $str [, $str...] )
101 Cleans a string, or list of strings, that make up a single HTML file.
102
103 Returns the cleaned string as a single string.
104
105 libtidy_version()
106 $version = HTML::Tidy->libtidy_version();
107 # for example -> "1 September 2005"
108 $version = HTML::Tidy->libtidy_version( { numeric => 1 } );
109 # for example -> 20050901
110
111 Returns the version of the underling tidy library.
112
114 HTML::Tidy requires that "libtidy" be installed on your system. You
115 can obtain libtidy through your distribution's package manager (make
116 sure you install the development package with headers), or from the
117 libtidy website at <http://tidy.sourceforge.net/src/tidy_src.tgz>.
118
120 HTML::Tidy is different from HTML::Lint in a number of crucial ways.
121
122 · It's not pure Perl
123
124 "HTML::Tidy" is mostly a happy wrapper around libtidy. Tidy's home
125 page is at <http://tidy.sourceforge.net>.
126
127 · The real work is done by someone else
128
129 Changes to libtidy may come down the pipe that I don't have control
130 over. That's the price we pay for having it do a darn good job.
131
132 · It's no longer bundled with its "Test::" counterpart
133
134 HTML::Lint came bundled with "Test::HTML::Lint", but
135 Test::HTML::Tidy is a separate distribution. This saves the people
136 who don't want the "Test::" framework from pulling it in, and all
137 its prerequisite modules.
138
140 Please report any bugs or feature requests to "bug-html-tidy at
141 rt.cpan.org", or through the web interface at
142 http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-Tidy
143 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-Tidy>. I will be
144 notified, and then you'll automatically be notified of progress on your
145 bug as I make changes.
146
148 You can find documentation for this module with the perldoc command.
149
150 perldoc HTML::Tidy
151
152 You can also look for information at:
153
154 · AnnoCPAN: Annotated CPAN documentation
155
156 http://annocpan.org/dist/HTML-Tidy <http://annocpan.org/dist/HTML-
157 Tidy>
158
159 · CPAN Ratings
160
161 http://cpanratings.perl.org/d/HTML-Tidy
162 <http://cpanratings.perl.org/d/HTML-Tidy>
163
164 · RT: CPAN's request tracker
165
166 http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-Tidy
167 <http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-Tidy>
168
169 · Search CPAN
170
171 http://search.cpan.org/dist/HTML-Tidy
172 <http://search.cpan.org/dist/HTML-Tidy>
173
174 · Subversion source code repository
175
176 http://code.google.com/p/html-tidy/source
177 <http://code.google.com/p/html-tidy/source>
178
180 Thanks to Jonathan Rockway and Robert Bachmann for contributions.
181
183 Andy Lester, "<andy at petdance.com>"
184
186 Copyright (C) 2005-2007 by Andy Lester
187
188 This library is free software; you can redistribute it and/or modify it
189 under the same terms as Perl itself, either Perl version 5.8.1 or, at
190 your option, any later version of Perl 5 you may have available.
191
192
193
194perl v5.12.0 2010-05-02 HTML::Tidy(3)