1package HTML::Filter;
2
3use strict;
4
5require HTML::Parser;
6our @ISA = qw(HTML::Parser);
7our $VERSION = '3.76';
8
9sub declaration { $_[0]->output("<!$_[1]>")     }
10sub process     { $_[0]->output($_[2])          }
11sub comment     { $_[0]->output("<!--$_[1]-->") }
12sub start       { $_[0]->output($_[4])          }
13sub end         { $_[0]->output($_[2])          }
14sub text        { $_[0]->output($_[1])          }
15
16sub output      { print $_[1] }
17
181;
19
20__END__
21
22=head1 NAME
23
24HTML::Filter - Filter HTML text through the parser
25
26=head1 NOTE
27
28B<This module is deprecated.> The C<HTML::Parser> now provides the
29functionally of C<HTML::Filter> much more efficiently with the
30C<default> handler.
31
32=head1 SYNOPSIS
33
34 require HTML::Filter;
35 $p = HTML::Filter->new->parse_file("index.html");
36
37=head1 DESCRIPTION
38
39C<HTML::Filter> is an HTML parser that by default prints the
40original text of each HTML element (a slow version of cat(1) basically).
41The callback methods may be overridden to modify the filtering for some
42HTML elements and you can override output() method which is called to
43print the HTML text.
44
45C<HTML::Filter> is a subclass of C<HTML::Parser>. This means that
46the document should be given to the parser by calling the $p->parse()
47or $p->parse_file() methods.
48
49=head1 EXAMPLES
50
51The first example is a filter that will remove all comments from an
52HTML file.  This is achieved by simply overriding the comment method
53to do nothing.
54
55  package CommentStripper;
56  require HTML::Filter;
57  @ISA=qw(HTML::Filter);
58  sub comment { }  # ignore comments
59
60The second example shows a filter that will remove any E<lt>TABLE>s
61found in the HTML file.  We specialize the start() and end() methods
62to count table tags and then make output not happen when inside a
63table.
64
65  package TableStripper;
66  require HTML::Filter;
67  @ISA=qw(HTML::Filter);
68  sub start
69  {
70     my $self = shift;
71     $self->{table_seen}++ if $_[0] eq "table";
72     $self->SUPER::start(@_);
73  }
74
75  sub end
76  {
77     my $self = shift;
78     $self->SUPER::end(@_);
79     $self->{table_seen}-- if $_[0] eq "table";
80  }
81
82  sub output
83  {
84      my $self = shift;
85      unless ($self->{table_seen}) {
86	  $self->SUPER::output(@_);
87      }
88  }
89
90If you want to collect the parsed text internally you might want to do
91something like this:
92
93  package FilterIntoString;
94  require HTML::Filter;
95  @ISA=qw(HTML::Filter);
96  sub output { push(@{$_[0]->{fhtml}}, $_[1]) }
97  sub filtered_html { join("", @{$_[0]->{fhtml}}) }
98
99=head1 SEE ALSO
100
101L<HTML::Parser>
102
103=head1 COPYRIGHT
104
105Copyright 1997-1999 Gisle Aas.
106
107This library is free software; you can redistribute it and/or
108modify it under the same terms as Perl itself.
109
110=cut
111