...err. I was too much self-confident about my code.
The problem seems to be in validate() :)
So, may I ask your fresh eyes to examine my code? :)
sub validate
{
my $text = shift;
my $new_text = '';
my %is_approved = ();
my @approved_tags = (
'a',
'p', 'br',
'b', 'i', 'strong',
'tt', 'small', 'strike',
's', 'u', 'sub', 'sup',
'blockquote',
'table', 'th', 'tr', 'td',
'caption', 'thead', 'tfoot',
'tbody', 'colgroup',
'dl', 'dt', 'dd',
'ul', 'li', 'ol',
);
foreach( @approved_tags ) { $is_approved{ $_ } = 1 }
my $validator = HTML::Parser->new(
start_h => [sub
{
my $self = shift;
my ($tagname, $attr, $origtext) = @_;
$new_text .= $origtext if ($is_approved{ $tagname });
}, "self, tagname, attr, text"],
end_h => [sub
{
my $self = shift;
my ($tagname) = @_;
$new_text .= "</$tagname>" if ($is_approved{ $tagname });
+
}, "self, tagname"],
text_h => [sub
{
my $self = shift;
my ($origtext) = @_;
$new_text .= $origtext;
}, "self, text"]
);
$validator->parse( $text );
return $new_text;
}
|