1 package HTML::Zoom::Parser::BuiltIn;
4 use warnings FATAL => 'all';
5 use base qw(HTML::Zoom::SubObject);
8 my ($self, $text) = @_;
10 _hacky_tag_parser($text => sub { push @events, $_[0] });
15 my ($self, $text) = @_;
16 return $self->_zconfig->stream_utils
17 ->stream_from_array(@{$self->html_to_events($text)});
20 sub _hacky_tag_parser {
21 my ($text, $handler) = @_;
26 ( / )? ( [^/!<>\s"'=]+ )
27 ( (?:"[^"]*"|'[^']*'|[^"'<>])+? )?
29 (!-- .*? -- | ![^\-] .*? )
35 my ($whole, $is_close, $tag_name, $attributes, $is_special,
36 $in_place_close, $content)
37 = ($1, $2, $3, $4, $5, $6, $7, $8);
39 $handler->({ type => 'SPECIAL', raw => $whole });
41 $tag_name =~ tr/A-Z/a-z/;
43 $handler->({ type => 'CLOSE', name => $tag_name, raw => $whole });
45 $attributes = '' if !defined($attributes) or $attributes =~ /^ +$/;
49 is_in_place_close => $in_place_close,
50 _hacky_attribute_parser($attributes),
51 raw_attrs => $attributes||'',
54 if ($in_place_close) {
56 type => 'CLOSE', name => $tag_name, raw => '',
57 is_in_place_close => 1
62 if (length $content) {
63 $handler->({ type => 'TEXT', raw => $content });
68 sub _hacky_attribute_parser {
70 my (%attrs, @attr_names);
73 ([^\s\=\"\']+)(\s*=\s*(?:(")(.*?)"|(')(.*?)'|([^'"\s=]+)['"]*))?
78 my $val = ( $3 ? $4 : ( $5 ? $6 : $7 ));
81 $attrs{$lckey} = _simple_unescape($val);
83 $attrs{$lckey} = $lckey;
85 push(@attr_names, $lckey);
87 (attrs => \%attrs, attr_names => \@attr_names);
90 sub _simple_unescape {
102 $str =~ s/"/"/g;
108 sub html_escape { _simple_escape($_[1]) }
110 sub html_unescape { _simple_unescape($_[1]) }