4 use vars qw(@ISA $VERSION);
9 $VERSION = sprintf("%d.%02d", q$Revision: 2.11 $ =~ /(\d+)\.(\d+)/);
11 sub declaration { $_[0]->output("<!$_[1]>") }
12 sub process { $_[0]->output($_[2]) }
13 sub comment { $_[0]->output("<!--$_[1]-->") }
14 sub start { $_[0]->output($_[4]) }
15 sub end { $_[0]->output($_[2]) }
16 sub text { $_[0]->output($_[1]) }
18 sub output { print $_[1] }
26 HTML::Filter - Filter HTML text through the parser
30 B<This module is deprecated.> The C<HTML::Parser> now provides the
31 functionally of C<HTML::Filter> much more efficiently with the the
37 $p = HTML::Filter->new->parse_file("index.html");
41 C<HTML::Filter> is an HTML parser that by default prints the
42 original text of each HTML element (a slow version of cat(1) basically).
43 The callback methods may be overridden to modify the filtering for some
44 HTML elements and you can override output() method which is called to
47 C<HTML::Filter> is a subclass of C<HTML::Parser>. This means that
48 the document should be given to the parser by calling the $p->parse()
49 or $p->parse_file() methods.
53 The first example is a filter that will remove all comments from an
54 HTML file. This is achieved by simply overriding the comment method
57 package CommentStripper;
59 @ISA=qw(HTML::Filter);
60 sub comment { } # ignore comments
62 The second example shows a filter that will remove any E<lt>TABLE>s
63 found in the HTML file. We specialize the start() and end() methods
64 to count table tags and then make output not happen when inside a
67 package TableStripper;
69 @ISA=qw(HTML::Filter);
73 $self->{table_seen}++ if $_[0] eq "table";
74 $self->SUPER::start(@_);
80 $self->SUPER::end(@_);
81 $self->{table_seen}-- if $_[0] eq "table";
87 unless ($self->{table_seen}) {
88 $self->SUPER::output(@_);
92 If you want to collect the parsed text internally you might want to do
95 package FilterIntoString;
97 @ISA=qw(HTML::Filter);
98 sub output { push(@{$_[0]->{fhtml}}, $_[1]) }
99 sub filtered_html { join("", @{$_[0]->{fhtml}}) }
107 Copyright 1997-1999 Gisle Aas.
109 This library is free software; you can redistribute it and/or
110 modify it under the same terms as Perl itself.