1 package HTML::Zoom::Parser::BuiltIn;
4 use base qw(HTML::Zoom::SubObject);
7 my ($self, $text) = @_;
9 _hacky_tag_parser($text => sub { push @events, $_[0] });
14 my ($self, $text) = @_;
15 return $self->_zconfig->stream_utils
16 ->stream_from_array(@{$self->html_to_events($text)});
19 sub _hacky_tag_parser {
20 my ($text, $handler) = @_;
21 $text =~ m{^([^<]*)}g;
22 if ( length $1 ) { # leading PCDATA
23 $handler->({ type => 'TEXT', raw => $1 });
29 ( / )? ( [^/!<>\s"'=]+ )
30 ( (?:"[^"]*"|'[^']*'|[^/"'<>])+? )?
32 (!-- .*? -- | ![^\-] .*? )
38 my ($whole, $is_close, $tag_name, $attributes, $is_special,
39 $in_place_close, $content)
40 = ($1, $2, $3, $4, $5, $6, $7, $8);
42 $handler->({ type => 'SPECIAL', raw => $whole });
44 $tag_name =~ tr/A-Z/a-z/;
46 $handler->({ type => 'CLOSE', name => $tag_name, raw => $whole });
48 $attributes = '' if !defined($attributes) or $attributes =~ /^ +$/;
52 is_in_place_close => $in_place_close,
53 _hacky_attribute_parser($attributes),
54 raw_attrs => $attributes||'',
57 if ($in_place_close) {
59 type => 'CLOSE', name => $tag_name, raw => '',
60 is_in_place_close => 1
65 if (length $content) {
66 $handler->({ type => 'TEXT', raw => $content });
71 sub _hacky_attribute_parser {
73 my (%attrs, @attr_names);
76 ([^\s\=\"\']+)(\s*=\s*(?:(")(.*?)"|(')(.*?)'|([^'"\s=]+)['"]*))?
81 my $val = ( $3 ? $4 : ( $5 ? $6 : $7 ));
84 $attrs{$lckey} = _simple_unescape($val);
86 $attrs{$lckey} = $lckey;
88 push(@attr_names, $lckey);
90 (attrs => \%attrs, attr_names => \@attr_names);
93 sub _simple_unescape {
105 $str =~ s/"/"/g;
111 sub html_escape { _simple_escape($_[1]) }
113 sub html_unescape { _simple_unescape($_[1]) }