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) = @_;
25 ( / )? ( [^/!<>\s"'=]+ )
26 ( (?:"[^"]*"|'[^']*'|[^/"'<>])+? )?
28 (!-- .*? -- | ![^\-] .*? )
34 my ($whole, $is_close, $tag_name, $attributes, $is_special,
35 $in_place_close, $content)
36 = ($1, $2, $3, $4, $5, $6, $7, $8);
38 $handler->({ type => 'SPECIAL', raw => $whole });
40 $tag_name =~ tr/A-Z/a-z/;
42 $handler->({ type => 'CLOSE', name => $tag_name, raw => $whole });
44 $attributes = '' if !defined($attributes) or $attributes =~ /^ +$/;
48 is_in_place_close => $in_place_close,
49 _hacky_attribute_parser($attributes),
50 raw_attrs => $attributes||'',
53 if ($in_place_close) {
55 type => 'CLOSE', name => $tag_name, raw => '',
56 is_in_place_close => 1
61 if (length $content) {
62 $handler->({ type => 'TEXT', raw => $content });
67 sub _hacky_attribute_parser {
69 my (%attrs, @attr_names);
72 ([^\s\=\"\']+)(\s*=\s*(?:(")(.*?)"|(')(.*?)'|([^'"\s=]+)['"]*))?
77 my $val = ( $3 ? $4 : ( $5 ? $6 : $7 ));
80 $attrs{$lckey} = _simple_unescape($val);
82 $attrs{$lckey} = $lckey;
84 push(@attr_names, $lckey);
86 (attrs => \%attrs, attr_names => \@attr_names);
89 sub _simple_unescape {
101 $str =~ s/"/"/g;
107 sub html_escape { _simple_escape($_[1]) }
109 sub html_unescape { _simple_unescape($_[1]) }