public
anonymous / comment.pl
Created

HTML4 comment parsing issue with Mojo::DOM

  • Download Gist
comment.pl
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
use Mojo::DOM;
use HTML::TreeBuilder;
 
my $content = <<'EOF';
<html>
<body>
<!-- This is a valid comment -- >
<p>Here's a paragraph</p>
</body>
</html>
EOF
 
{
my $dom = Mojo::DOM->new( $content );
say "Mojo:\n" . $dom;
}
{
my $dom = HTML::TreeBuilder->new_from_content($content);
say "Tree:\n" . $dom->as_HTML('<>&', ' ');
}
 
__END__
 
Mojo:
<html>
<body>
<!-- -- a comment is this valid>
<p>Here&#39;s a paragraph</p>
</!--></body>
</html>
 
Tree:
<html>
<head>
</head>
<body>
<p>Here's a paragraph</body>
</html>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.