xmltwig
xmltwig copied to clipboard
#TEXT handler not called for text that precedes an element
In this testcase, I have elements inside text blocks:
<ul>
<li>This is <?Fm Condstart _COND4_?>item 1.</li>
<li>This is <b>boldfaced</b> text in item 2.</li>
</ul>
I define a handler to wrap all #TEXT blocks in <TEXT> elements:
'#TEXT' => sub { $_->wrap_in('TEXT'); return 1; }
In the resulting twig, I see that the handler is called for text that follows the bisecting elements, but not before (both "This is" strings):
<ul>
<li>This is <?Fm Condstart _COND4_?><TEXT>item 1.</TEXT></li>
<li>This is <b><TEXT>boldfaced</TEXT></b><TEXT> text in item 2.</TEXT></li>
</ul>
Testcase:
#!/usr/bin/perl
use strict;
use warnings;
use XML::Twig;
my $xml = <<EOF;
<ul>
<li>This is <?Fm Condstart _COND4_?>item 1.</li>
<li>This is <b>boldfaced</b> text in item 2.</li>
</ul>
EOF
my $twig = XML::Twig->new(
pi => 'process',
twig_handlers => {
'#TEXT' => sub { $_->wrap_in('TEXT'); return 1; },
},
)->parse($xml);
$twig->print(pretty_print => 'indented');