HTML::Filter(3)
okay bestie, welcome to HTML::Filter(3) β from the User Contributed Perl Documentation β and yes, we're filtering HTML text through the parser today π
β¨
π NAME π
HTML::Filter β Filter HTML text through the parser. That's the whole name and the whole job, no cap.
β οΈ NOTE β οΈ
π¨ deprecated alert π¨ This module is deprecated. TheHTML::Parsernow provides the functionally ofHTML::Filtermuch more efficiently with thedefaulthandler. So yeah β the glow-up already happened, bestie π
π§Ύ SYNOPSIS π§Ύ
require HTML::Filter;
$p = HTML::Filter->new->parse_file("index.html");
πΈ DESCRIPTION πΈ
HTML::Filter is an HTML parser that by default prints the original text of each HTML element (a slow version of cat(1) basically). The callback methods may be overridden to modify the filtering for some HTML elements, and you can override the output() method which is called to print the HTML text. It's giving "custom filter era" π
HTML::Filter is a subclass of HTML::Parser. This means that the document should be given to the parser by calling the $p->parse() or $p->parse_file() methods. Periodt.
β¨ EXAMPLES β¨
π¬ Example 1 β CommentStripper
The first example is a filter that will remove all comments from an HTML file. This is achieved by simply overriding the comment method to do nothing. Literally the no-op slay.
package CommentStripper;
require HTML::Filter;
@ISA=qw(HTML::Filter);
sub comment { } # ignore comments
πͺ Example 2 β TableStripper
The second example shows a filter that will remove any <TABLE>s found in the HTML file. We specialize the start() and end() methods to count table tags and then make output not happen when inside a table. Table? Not today, bestie.
package TableStripper;
require HTML::Filter;
@ISA=qw(HTML::Filter);
sub start
{
my $self = shift;
$self->{table_seen}++ if $_[0] eq "table";
$self->SUPER::start(@_);
}
sub end
{
my $self = shift;
$self->SUPER::end(@_);
$self->{table_seen}-- if $_[0] eq "table";
}
sub output
{
my $self = shift;
unless ($self->{table_seen}) {
$self->SUPER::output(@_);
}
}
π«Ά Example 3 β FilterIntoString
If you want to collect the parsed text internally you might want to do something like this:
package FilterIntoString;
require HTML::Filter;
@ISA=qw(HTML::Filter);
sub output { push(@{$_[0]->{fhtml}}, $_[1]) }
sub filtered_html { join("", @{$_[0]->{fhtml}}) }
π SEE ALSO π
HTML::Parser β that's the see-also list, and honestly it's the main character here π
π COPYRIGHT π
Copyright 1997-1999 Gisle Aas.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
mwah π β this cutie is HTML::Filter(3) from perl v5.42.0, dated 2026-06-08. Catch you in the group chat, bestie π«Άβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-HTML-Parser 3.830.0-160000.3.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-HTML-Parser 3.830.0-160000.3.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-HTML-Parser 3.830.0-160000.3.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-HTML-Parser 3.830.0-160000.3.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms