#!/usr/bin/perl -w use strict; my $tag; my $text; use HTML::Parser (); my $p = HTML::Parser->new(start_h => [sub { $tag = shift }, "tagname"], text_h => [sub { $text .= shift }, "dtext"], ); use Test::More tests => 14; SKIP: { eval { $p->marked_sections(1); }; skip $@, 14 if $@; $p->parse(""); is($text, "foo"); $p->parse(""); is($text, "foobar"); $p->parse("]]>\n
"); is($text, "foobarfoo\n"); $text = ""; $p->parse("parse(",bar>]]>
"); is($text, "<foo]]>"); $text = ""; $p->parse("]]>]]>å
"); is($text, "å
åå"); is($tag, "br"); $text = ""; $p->parse("]]>
"); is($text, ""); $text = ""; $p->parse("]]>
"); is($text, "fooå
"); $text = ""; $p->parse("]]>
"); is($text, "fooå
"); $text = ""; $p->parse("]]>
"); is($text, "fooå"); $text = ""; $p->parse("]]>
"); is($text, "fooå"); # offsets/line/column numbers $p = HTML::Parser->new(default_h => [\&x, "line,column,offset,event,text"], marked_sections => 1, ); $p->parse(<<'EOT')->eof; Test ]]>

Test

EOT my @x; sub x { my($line, $col, $offset, $event, $text) = @_; $text =~ s/\n/\\n/g; $text =~ s/ /./g; push(@x, "$line.$col:$offset $event \"$text\"\n"); } #diag @x; is(join("", @x), <<'EOT'); 1.0:0 start_document "" 1.0:0 start "" 1.7:7 text "Test" 1.11:11 end "" 1.19:19 text "\n" 3.3:32 text "fooå
\n" 4.3:49 text "\n" 5.4:54 text "\nINCLUDE\nSTUFF\n" 8.3:72 text "\n.." 9.2:75 start "

" 9.6:79 text "Test" 9.10:83 end "

" 9.15:88 text "\n" 10.0:89 end_document "" EOT my $doc = ""; my $result = ""; $p = HTML::Parser->new( marked_sections => 1, handlers => { default => [ sub { $result .= join("",@_); }, "skipped_text,text" ] } )->parse($doc)->eof; is($doc, $result); $text = ""; $p = HTML::Parser->new( text_h => [sub { $text .= shift }, "dtext"], marked_sections => 1, ); $p->parse(""); is($text, "foo [1]", "CDATA text ending in square bracket"); } # SKIP