#!/usr/bin/perl -w use Test::More tests => 12; use strict; use HTML::Parser; my $p = HTML::Parser->new(api_version => 3, ignore_tags => [qw(b i em tt)]); $p->ignore_elements("script"); $p->unbroken_text(1); $p->handler(default => [], "event, text"); $p->parse(<<"EOT")->eof; foo This is an italic and bold text. EOT my $t = join("||", map join("|", @$_), @{$p->handler("default")}); #diag $t; is($t, "start_document|||start|||start|||start|||text|foo||end|||start|||text| This is an italic and bold text. ||end|||text| ||end|||text| ||end_document|", 'ignore_elements'); #------------------------------------------------------ $p = HTML::Parser->new(api_version => 3); $p->report_tags("a"); $p->handler(start => sub { my($tagname, %attr) = @_; ok($tagname eq "a" && $attr{href} eq "#a", 'report_tags start'); }, 'tagname, @attr'); $p->handler(end => sub { my $tagname = shift; is($tagname, "a", 'report_tags end'); }, 'tagname'); $p->parse(<eof;

Next example

This is very nice example. EOT #------------------------------------------------------ my @tags; $p = HTML::Parser->new(api_version => 3); $p->report_tags(qw(a em)); $p->ignore_tags(qw(em)); $p->handler(end => sub {push @tags, @_;}, 'tagname'); $p->parse(<eof;

Next example

This is yet another very nice example. EOT is(join('|', @tags), 'a', 'report_tags followed by ignore_tags'); #------------------------------------------------------ @tags = (); $p = HTML::Parser->new(api_version => 3); $p->report_tags(qw(h1)); $p->report_tags(); $p->handler(end => sub {push @tags, @_;}, 'tagname'); $p->parse(<eof;

Next example

Next example

EOT is(join('|', @tags), 'h1|h2', 'reset report_tags filter'); #------------------------------------------------------ @tags = (); $p = HTML::Parser->new(api_version => 3); $p->report_tags(qw(h1 h2)); $p->ignore_tags(qw(h2)); $p->report_tags(qw(h1 h2)); $p->handler(end => sub {push @tags, @_;}, 'tagname'); $p->parse(<eof;

Next example

Next example

EOT is(join('|', @tags), 'h1', 'report_tags does not reset ignore_tags'); #------------------------------------------------------ @tags = (); $p = HTML::Parser->new(api_version => 3); $p->report_tags(qw(h1 h2)); $p->ignore_tags(qw(h2)); $p->report_tags(); $p->handler(end => sub {push @tags, @_;}, 'tagname'); $p->parse(<eof;

Next example

Next example

EOT is(join('|', @tags), 'h1', 'reset report_tags does no reset ignore_tags'); #------------------------------------------------------ @tags = (); $p = HTML::Parser->new(api_version => 3); $p->report_tags(qw(h1 h2)); $p->report_tags(qw(h3)); $p->handler(end => sub {push @tags, @_;}, 'tagname'); $p->parse(<eof;

Next example

Next example

Next example

EOT is(join('|', @tags), 'h3', 'report_tags replaces filter'); #------------------------------------------------------ @tags = (); $p = HTML::Parser->new(api_version => 3); $p->ignore_tags(qw(h1 h2)); $p->ignore_tags(qw(h3)); $p->handler(end => sub {push @tags, @_;}, 'tagname'); $p->parse(<eof;

Next example

Next example

Next example

EOT is(join('|', @tags), 'h1|h2', 'ignore_tags replaces filter'); #------------------------------------------------------ @tags = (); $p = HTML::Parser->new(api_version => 3); $p->ignore_tags(qw(h2)); $p->ignore_tags(); $p->handler(end => sub {push @tags, @_;}, 'tagname'); $p->parse(<eof;

Next example

Next example

EOT is(join('|', @tags), 'h1|h2', 'reset ignore_tags filter'); #------------------------------------------------------ @tags = (); $p = HTML::Parser->new(api_version => 3); $p->ignore_tags(qw(h2)); $p->report_tags(qw(h1 h2)); $p->handler(end => sub {push @tags, @_;}, 'tagname'); $p->parse(<eof;

Next example

Next example

EOT is(join('|', @tags), 'h1', 'ignore_tags before report_tags'); #------------------------------------------------------ $p = HTML::Parser->new(api_version => 3); $p->ignore_elements("script"); my $res=""; $p->handler(default=> sub {$res.=$_[0];}, 'text'); $p->parse(<<'EOT')->eof; A C D F EOT is($res,"A C D F\n","ignore without