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