HTML::Lint also comes with a wrapper program called weblint that handles linting from the command line:
And finally, you can also get Apache::HTML::Lint that passes any mod_perl-generated code through HTML::Lint and get it dumped into your Apache error_log.
METHODS
NOTE: Some of these methods mirror HTML::Parser's methods, but HTML::Lint is not a subclass of HTML::Parser.
new()
Create an HTML::Lint object, which inherits from HTML::Parser. You may pass the types of errors you want to check for in the "only_types" parm.
my $lint = HTML::Lint->new( only_types => HTML::Lint::Error::STRUCTURE );
If you want more than one, you must pass an arrayref:
my $lint = HTML::Lint->new(
only_types => [HTML::Lint::Error::STRUCTURE, HTML::Lint::Error::FLUFF] );
$lint->parser()
Returns the parser object for this object, creating one if necessary.
$lint->parse( $text )
$lint->parse( $code_ref )
Passes in a chunk of HTML to be linted, either as a piece of text, or a code reference. See HTML::Parser's "parse_file" method for details.
$lint->parse_file( $file )
Analyzes HTML directly from a file. The $file argument can be a filename, an open file handle, or a reference to an open file handle. See HTML::Parser's "parse_file" method for details.
$lint->eof
Signals the end of a block of text getting passed in. This must be called to make sure that all parsing is complete before looking at errors.
Any parameters (and there shouldn't be any) are passed through to HTML::Parser's eof() method.
$lint->errors()
In list context, "errors" returns all of the errors found in the parsed text. Each error is an object of the type HTML::Lint::Error.
In scalar context, it returns the number of errors found.
$lint->clear_errors()
Clears the list of errors, in case you want to print and clear, print and clear.
$lint->only_types( $type1[, $type2...] )
Specifies to only want errors of a certain type.
$lint->only_types( HTML::Lint::Error::STRUCTURE );
Calling this without parameters makes the object return all possible errors.
The error types are "STRUCTURE", "HELPER" and "FLUFF". See HTML::Lint::Error for details on these types.
$lint->gripe( $errcode, [$key1=>$val1, ...] )
Adds an error message, in the form of an HTML::Lint::Error object, to the list of error messages for the current object. The file, line and column are automatically passed to the HTML::Lint::Error constructor, as well as whatever other key value pairs are passed.
For example:
$lint->gripe( 'attr-repeated', tag => $tag, attr => $attr );
Usually, the user of the object won't call this directly, but just in case, here you go.
$lint->newfile( $filename )
Call "newfile()" whenever you switch to another file in a batch of linting. Otherwise, the object thinks everything is from the same file. Note that the list of errors is NOT cleared.
Note that $filename does NOT need to match what's put into parse() or parse_file(). It can be a description, a URL, or whatever.
MODIFYING HTML::LINT'S BEHAVIOR
Sometimes you'll have HTML that for some reason cannot conform to HTML::Lint's expectations. For those instances, you can use HTML comments to modify HTML::Lint's behavior.
Say you have an image where for whatever reason you can't get dimensions for the image. This HTML snippet:
causes this error:
foo.html (14:20) tag has no HEIGHT and WIDTH attributes
But if for some reason you can't get those dimensions when you build the page, you can at least stop HTML::Lint complaining about it.
If you want to turn off all HTML::Lint warnings for a block of code, use
And turn them back on with
You don't have to use "on" and "off". For "on", you can use "true" or "1". For "off", you can use "0" or "false".
For a list of possible errors and their codes, see HTML::Lint::Error, or run perldoc HTML::Lint::Error.
BUGS, WISHES AND CORRESPONDENCE
All bugs and requests are now being handled through GitHub.
https://github.com/petdance/html-lint/issues
DO NOT send bug reports to http://rt.cpan.org/ or http://code.google.com/
TODO
o Check for attributes that require values
o
s that have no rows.
o Form fields that aren't in a FORM
o Check for valid entities, and that they end with semicolons
o DIVs with nothing in them.
o HEIGHT= that have percents in them.
o Check for goofy stuff like:
Hello Reader - Spanish Level 1 (K-3)
COPYRIGHT & LICENSE
Copyright 2005-2015 Andy Lester.
This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License v2.0.
http://www.opensource.org/licenses/Artistic-2.0
Please note that these modules are not products of or supported by the employers of the various contributors to the code.
AUTHOR
Andy Lester, andy at petdance.com
perl v5.26.0 2017-08-01 HTML::Lint(3pm)