From: Simon Elliott Date: Mon, 10 Mar 2014 17:50:37 +0000 (+0000) Subject: merge X-Git-Tag: 0.009009~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FHTML-Zoom.git;a=commitdiff_plain;h=0c58a1e1705f0eafd1c6457ed5f26104e2bb4ad4;hp=57076fa16f45eb212dac6cda4cf9231938479802 merge --- diff --git a/lib/HTML/Zoom/FilterBuilder.pm b/lib/HTML/Zoom/FilterBuilder.pm index 8374e91..ed7fef1 100644 --- a/lib/HTML/Zoom/FilterBuilder.pm +++ b/lib/HTML/Zoom/FilterBuilder.pm @@ -44,7 +44,7 @@ sub _parse_attribute_args { die "Long form arg (name => 'class', value => 'x') is no longer supported" if(@_ == 1 && $_[0]->{'name'} && $_[0]->{'value'}); - + my $opts = ref($_[0]) eq 'HASH' ? $_[0] : {$_[0] => $_[1]}; for (values %{$opts}) { $self->_zconfig->parser->html_escape($_); } return $opts; @@ -71,7 +71,7 @@ sub add_to_attribute { +{ %$evt, raw => undef, raw_attrs => undef, attrs => { %$a, - map {$_ => join(' ', (exists $a->{$_} ? $a->{$_} : ()), $attr->{$_}) } + map {$_ => join(' ', (exists $a->{$_} ? $a->{$_} : ()), $attr->{$_}) } keys %$attr }, @kadd ? (attr_names => [ @{$evt->{attr_names}}, @kadd ]) : () @@ -88,7 +88,7 @@ sub remove_from_attribute { attrs => { %$a, #TODO needs to support multiple removes - map { my $tar = $_; $_ => join ' ', + map { my $tar = $_; $_ => join ' ', map {$attr->{$tar} ne $_} split ' ', $a->{$_} } grep {exists $a->{$_}} keys %$attr }, @@ -677,9 +677,9 @@ Similar to add_before, but adds the content to the match. ->select('p') ->prepend_content("Hello ") ->to_html - + ##

Hello World

- + Acceptable values are strings, scalar refs and L objects =head2 append_content @@ -691,7 +691,7 @@ Similar to add_after, but adds the content to the match. ->select('p') ->prepend_content("World") ->to_html - + ##

Hello World

Acceptable values are strings, scalar refs and L objects @@ -728,7 +728,7 @@ pre-generated) } } @list ]); - + Subroutines would be run with $_ localized to result of L (of collected elements), and with said result passed as parameter to subroutine. diff --git a/lib/HTML/Zoom/Parser/BuiltIn.pm b/lib/HTML/Zoom/Parser/BuiltIn.pm index de65f08..1e87919 100644 --- a/lib/HTML/Zoom/Parser/BuiltIn.pm +++ b/lib/HTML/Zoom/Parser/BuiltIn.pm @@ -16,6 +16,15 @@ sub html_to_stream { ->stream_from_array(@{$self->html_to_events($text)}); } +# DO NOT BE AFRAID. +# +# Well, ok. Be afraid. A little. But this is lexing HTML with a regexp, +# not really parsing (since the structure nesting isn't handled here) so +# it's relatively not dangerous. +# +# Certainly it's not really any more or any less heinous than anything else +# I could do in a handful of lines of pure perl. + sub _hacky_tag_parser { my ($text, $handler) = @_; $text =~ m{^([^<]*)}g;