Reputation: 63
Consider the following script:
#!/usr/bin/perl
use strict;
use HTML::TreeBuilder;
sub test
{
my ($content) = @_;
my $tree = HTML::TreeBuilder->new;
$tree->implicit_tags(0);
$tree->no_expand_entities(1);
$tree->parse_content($content);
return $tree->as_HTML(q{<>&});
}
print test('test«');
print "\n";
print test('<a href="#" title="«"></a>')
It'll print:
<html>test«</html>
<html><a href="#" title="?"></a></html>
Due to calling no_expand_entities(1)
HTML entity «
is not expanded within HTML element. However for some reason this mode does not change default behavior for attributes - the same entity is expanded and displayed as garbage.
Could you please advise how to force disabling entities expansion within HTML attributes?
Upvotes: 0
Views: 286
Reputation: 4581
As a workaround, you can call
$tree->attr_encoded(1);
before calling the parser. This would disable HTML::Parser
's automatic decoding of attributes.
But best is to ask the author of HTML::TreeBuilder
(e.g. via rt.cpan.org) to do this automatically if no_expand_entities
is set.
Upvotes: 1