3 use Test::More tests => 12;
8 my $p = HTML::Parser->new(api_version => 3, ignore_tags => [qw(b i em tt)]);
9 $p->ignore_elements("script");
12 $p->handler(default => [], "event, text");
13 $p->parse(<<"EOT")->eof;
14 <html><head><title>foo</title><Script language="Perl">
19 This is an <i>italic</i> and <b>bold</b> text.
24 my $t = join("||", map join("|", @$_), @{$p->handler("default")});
27 is($t, "start_document|||start|<html>||start|<head>||start|<title>||text|foo||end|</title>||start|<body>||text|
28 This is an italic and bold text.
31 ||end_document|", 'ignore_elements');
34 #------------------------------------------------------
36 $p = HTML::Parser->new(api_version => 3);
38 $p->handler(start => sub {
39 my($tagname, %attr) = @_;
40 ok($tagname eq "a" && $attr{href} eq "#a", 'report_tags start');
42 $p->handler(end => sub {
44 is($tagname, "a", 'report_tags end');
47 $p->parse(<<EOT)->eof;
51 This is <a href="#a">very nice</a> example.
56 #------------------------------------------------------
59 $p = HTML::Parser->new(api_version => 3);
60 $p->report_tags(qw(a em));
61 $p->ignore_tags(qw(em));
62 $p->handler(end => sub {push @tags, @_;}, 'tagname');
64 $p->parse(<<EOT)->eof;
68 This is <em>yet another</em> <a href="#a">very nice</a> example.
71 is(join('|', @tags), 'a', 'report_tags followed by ignore_tags');
74 #------------------------------------------------------
77 $p = HTML::Parser->new(api_version => 3);
78 $p->report_tags(qw(h1));
80 $p->handler(end => sub {push @tags, @_;}, 'tagname');
82 $p->parse(<<EOT)->eof;
88 is(join('|', @tags), 'h1|h2', 'reset report_tags filter');
91 #------------------------------------------------------
94 $p = HTML::Parser->new(api_version => 3);
95 $p->report_tags(qw(h1 h2));
96 $p->ignore_tags(qw(h2));
97 $p->report_tags(qw(h1 h2));
98 $p->handler(end => sub {push @tags, @_;}, 'tagname');
100 $p->parse(<<EOT)->eof;
102 <h1>Next example</h1>
103 <h2>Next example</h2>
106 is(join('|', @tags), 'h1', 'report_tags does not reset ignore_tags');
109 #------------------------------------------------------
112 $p = HTML::Parser->new(api_version => 3);
113 $p->report_tags(qw(h1 h2));
114 $p->ignore_tags(qw(h2));
116 $p->handler(end => sub {push @tags, @_;}, 'tagname');
118 $p->parse(<<EOT)->eof;
120 <h1>Next example</h1>
121 <h2>Next example</h2>
124 is(join('|', @tags), 'h1', 'reset report_tags does no reset ignore_tags');
127 #------------------------------------------------------
130 $p = HTML::Parser->new(api_version => 3);
131 $p->report_tags(qw(h1 h2));
132 $p->report_tags(qw(h3));
133 $p->handler(end => sub {push @tags, @_;}, 'tagname');
135 $p->parse(<<EOT)->eof;
137 <h1>Next example</h1>
138 <h2>Next example</h2>
139 <h3>Next example</h3>
142 is(join('|', @tags), 'h3', 'report_tags replaces filter');
145 #------------------------------------------------------
149 $p = HTML::Parser->new(api_version => 3);
150 $p->ignore_tags(qw(h1 h2));
151 $p->ignore_tags(qw(h3));
152 $p->handler(end => sub {push @tags, @_;}, 'tagname');
154 $p->parse(<<EOT)->eof;
156 <h1>Next example</h1>
157 <h2>Next example</h2>
158 <h3>Next example</h3>
161 is(join('|', @tags), 'h1|h2', 'ignore_tags replaces filter');
164 #------------------------------------------------------
167 $p = HTML::Parser->new(api_version => 3);
168 $p->ignore_tags(qw(h2));
170 $p->handler(end => sub {push @tags, @_;}, 'tagname');
172 $p->parse(<<EOT)->eof;
174 <h1>Next example</h1>
175 <h2>Next example</h2>
178 is(join('|', @tags), 'h1|h2', 'reset ignore_tags filter');
181 #------------------------------------------------------
184 $p = HTML::Parser->new(api_version => 3);
185 $p->ignore_tags(qw(h2));
186 $p->report_tags(qw(h1 h2));
187 $p->handler(end => sub {push @tags, @_;}, 'tagname');
189 $p->parse(<<EOT)->eof;
191 <h1>Next example</h1>
192 <h2>Next example</h2>
195 is(join('|', @tags), 'h1', 'ignore_tags before report_tags');
196 #------------------------------------------------------
198 $p = HTML::Parser->new(api_version => 3);
199 $p->ignore_elements("script");
201 $p->handler(default=> sub {$res.=$_[0];}, 'text');
202 $p->parse(<<'EOT')->eof;
203 A <script> B </script> C </script> D <script> E </script> F
205 is($res,"A C D F\n","ignore </script> without <script> correctly");