1HTML::Filter(3)       User Contributed Perl Documentation      HTML::Filter(3)
2
3
4

NAME

6       HTML::Filter - Filter HTML text through the parser
7

NOTE

9       This module is deprecated. The "HTML::Parser" now provides the
10       functionally of "HTML::Filter" much more efficiently with the "default"
11       handler.
12

SYNOPSIS

14        require HTML::Filter;
15        $p = HTML::Filter->new->parse_file("index.html");
16

DESCRIPTION

18       "HTML::Filter" is an HTML parser that by default prints the original
19       text of each HTML element (a slow version of cat(1) basically).  The
20       callback methods may be overridden to modify the filtering for some
21       HTML elements and you can override output() method which is called to
22       print the HTML text.
23
24       "HTML::Filter" is a subclass of "HTML::Parser". This means that the
25       document should be given to the parser by calling the $p->parse() or
26       $p->parse_file() methods.
27

EXAMPLES

29       The first example is a filter that will remove all comments from an
30       HTML file.  This is achieved by simply overriding the comment method to
31       do nothing.
32
33         package CommentStripper;
34         require HTML::Filter;
35         @ISA=qw(HTML::Filter);
36         sub comment { }  # ignore comments
37
38       The second example shows a filter that will remove any <TABLE>s found
39       in the HTML file.  We specialize the start() and end() methods to count
40       table tags and then make output not happen when inside a table.
41
42         package TableStripper;
43         require HTML::Filter;
44         @ISA=qw(HTML::Filter);
45         sub start
46         {
47            my $self = shift;
48            $self->{table_seen}++ if $_[0] eq "table";
49            $self->SUPER::start(@_);
50         }
51
52         sub end
53         {
54            my $self = shift;
55            $self->SUPER::end(@_);
56            $self->{table_seen}-- if $_[0] eq "table";
57         }
58
59         sub output
60         {
61             my $self = shift;
62             unless ($self->{table_seen}) {
63                 $self->SUPER::output(@_);
64             }
65         }
66
67       If you want to collect the parsed text internally you might want to do
68       something like this:
69
70         package FilterIntoString;
71         require HTML::Filter;
72         @ISA=qw(HTML::Filter);
73         sub output { push(@{$_[0]->{fhtml}}, $_[1]) }
74         sub filtered_html { join("", @{$_[0]->{fhtml}}) }
75

SEE ALSO

77       HTML::Parser
78
80       Copyright 1997-1999 Gisle Aas.
81
82       This library is free software; you can redistribute it and/or modify it
83       under the same terms as Perl itself.
84
85
86
87perl v5.28.1                      2016-01-19                   HTML::Filter(3)
Impressum