From: Matt S Trout Date: Wed, 26 May 2010 19:51:55 +0000 (+0100) Subject: make comments and doctypes get passed through X-Git-Tag: release_0.009004~64 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FHTML-Zoom.git;a=commitdiff_plain;h=e32e7b9042cdaf10bded0a43791760617ab45137 make comments and doctypes get passed through --- diff --git a/lib/HTML/Zoom/Parser/BuiltIn.pm b/lib/HTML/Zoom/Parser/BuiltIn.pm index ba6f41a..cfe21de 100644 --- a/lib/HTML/Zoom/Parser/BuiltIn.pm +++ b/lib/HTML/Zoom/Parser/BuiltIn.pm @@ -32,28 +32,31 @@ sub _hacky_tag_parser { ([^<]*) }sxg ) { - my ($whole, $is_close, $tag_name, $attributes, $is_comment, + my ($whole, $is_close, $tag_name, $attributes, $is_special, $in_place_close, $content) = ($1, $2, $3, $4, $5, $6, $7, $8); - next if defined $is_comment; - $tag_name =~ tr/A-Z/a-z/; - if ($is_close) { - $handler->({ type => 'CLOSE', name => $tag_name, raw => $whole }); + if ($is_special) { + $handler->({ type => 'SPECIAL', raw => $whole }); } else { - $attributes = '' if !defined($attributes) or $attributes =~ /^ +$/; - $handler->({ - type => 'OPEN', - name => $tag_name, - is_in_place_close => $in_place_close, - _hacky_attribute_parser($attributes), - raw_attrs => $attributes||'', - raw => $whole, - }); - if ($in_place_close) { + $tag_name =~ tr/A-Z/a-z/; + if ($is_close) { + $handler->({ type => 'CLOSE', name => $tag_name, raw => $whole }); + } else { + $attributes = '' if !defined($attributes) or $attributes =~ /^ +$/; $handler->({ - type => 'CLOSE', name => $tag_name, raw => '', - is_in_place_close => 1 + type => 'OPEN', + name => $tag_name, + is_in_place_close => $in_place_close, + _hacky_attribute_parser($attributes), + raw_attrs => $attributes||'', + raw => $whole, }); + if ($in_place_close) { + $handler->({ + type => 'CLOSE', name => $tag_name, raw => '', + is_in_place_close => 1 + }); + } } } if (length $content) { diff --git a/t/synopsis.t b/t/synopsis.t index 4089bf9..8a3ac11 100644 --- a/t/synopsis.t +++ b/t/synopsis.t @@ -1,3 +1,71 @@ +use strict; +use warnings FATAL => 'all'; use Test::More qw(no_plan); -fail 'You forgot to run maint/synopsis-extract. Go do that.'; +use HTML::Zoom; +my $template = < + + Hello people + + +

Placeholder

+
+ +

Name: Bob

+

Age: 23

+
+
+
+ + +HTML +my $output = HTML::Zoom + ->from_html($template) + ->select('title, #greeting')->replace_content('Hello world & dog!') + ->select('#list')->repeat_content( + [ + sub { + $_->select('.name')->replace_content('Matt') + ->select('.age')->replace_content('26') + }, + sub { + $_->select('.name')->replace_content('Mark') + ->select('.age')->replace_content('0x29') + }, + sub { + $_->select('.name')->replace_content('Epitaph') + ->select('.age')->replace_content('') + }, + ], + { repeat_between => '.between' } + ) + ->to_html; +my $expect = < + + Hello world & dog! + + +

Hello world & dog!

+
+ +

Name: Matt

+

Age: 26

+
+
+ +

Name: Mark

+

Age: 0x29

+
+
+ +

Name: Epitaph

+

Age: <redacted>

+
+ +
+ + +HTML +is($output, $expect, 'Synopsis code works ok');;