HTML::Valid - tidy/validate HTML
use FindBin '$Bin'; use HTML::Valid; my $html = <<EOF; <ul> <li>Shape it up <li>Get straight <li>Go forward <li>Move ahead <li>Try to detect it <li>It's not too late EOF my $htv = HTML::Valid->new (); my ($output, $errors) = $htv->run ($html); print "$output\n"; print "$errors\n";
outputs
<!DOCTYPE html> <html> <head> <meta name="generator" content= "HTML Tidy for HTML5 for FreeBSD version 5.0.0"> <title></title> </head> <body> <ul> <li>Shape it up</li> <li>Get straight</li> <li>Go forward</li> <li>Move ahead</li> <li>Try to detect it</li> <li>It's not too late</li> </ul> </body> </html> line 1 column 1 - Warning: missing <!DOCTYPE> declaration line 1 column 1 - Warning: inserting implicit <body> line 1 column 1 - Warning: missing </ul> line 1 column 1 - Warning: inserting missing 'title' element Info: Document content looks like HTML5 4 warnings, 0 errors were found!
This document describes HTML::Valid version 0.00_04. This corresponds to "HTML Tidy" version 5.0.0.
Validate/repair HTML. This module is based on "HTML Tidy", but not on the Perl module HTML::Tidy.
my $htv = HTML::Valid->new ();
$htv->set_filename ('file.html');
Set the file name for error reporting to file.html.
my ($output, $errors) = $htv->run ($content);
Get the tidy HTML output and errors.
There is a script called "htmlok" which runs on files and prints errors. It is extremely flaky at the moment.
This is a program and a library in C for improving HTML. HTML::Valid is based on this project.
HTML Tidy web page
HTML Tidy git repository
You may like to try these validators for checking your HTML.
Commercial HTML validator.
W3 Consortium validator.
New W3 Consortium validator.
Ben Bullock <bkb@cpan.org>
HTML::Valid is based on HTML Tidy, which is under the following copyright:
Copyright (c) 1998-2008 World Wide Web Consortium (Massachusetts Institute of Technology, European Research Consortium for Informatics and Mathematics, Keio University). All Rights Reserved. COPYRIGHT NOTICE: This software and documentation is provided "as is," and the copyright holders and contributing author(s) make no representations or warranties, express or implied, including but not limited to, warranties of merchantability or fitness for any particular purpose or that the use of the software or documentation will not infringe any third party patents, copyrights, trademarks or other rights. The copyright holders and contributing author(s) will not be held liable for any direct, indirect, special or consequential damages arising out of any use of the software or documentation, even if advised of the possibility of such damage. Permission is hereby granted to use, copy, modify, and distribute this source code, or portions hereof, documentation and executables, for any purpose, without fee, subject to the following restrictions: 1. The origin of this source code must not be misrepresented. 2. Altered versions must be plainly marked as such and must not be misrepresented as being the original source. 3. This Copyright notice may not be removed or altered from any source or altered source distribution.
The Perl parts of this distribution are copyright (C) 2015 Ben Bullock and may be used under either the above licence terms, or the usual Perl conditions, either the GNU General Public Licence or the Perl Artistic Licence.
To install HTML::Valid, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTML::Valid
CPAN shell
perl -MCPAN -e shell install HTML::Valid
For more information on module installation, please visit the detailed CPAN module installation guide.