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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#
# $Id: HtmlStripper.pm,v 1.1.1.1 2001/01/16 10:26:38 muhri Exp $
#
package HtmlStripper;
require HTML::Filter;
@ISA=qw(HTML::Filter);
%allowed = ();
foreach (split(/\s+/, $main::prefs{'HtmlAllowed'})) { $allowed{$_} = 1; };
sub comment { }
sub start
{
my ($self, $tag, $attr, $attrseq, $origtext) = @_;
if (! $allowed{$tag})
{
# print STDERR "killing tag $tag\n";
return;
};
# need a better attribute list for this to be ok to use - ai
foreach (keys %$attr)
{
if (! ($allowed{"$tag:$_"} || $allowed{"$tag:*"}))
{
delete $attr->{$_};
$origtext = '';
};
};
$attrseq = [ keys %attr ];
if (! $origtext)
{
$origtext = "<$tag";
foreach (@$attrseq) { $origtext .= " $_=\"$attr->{$_}\" "; };
$origtext .= ">";
};
$self->SUPER::start($tag, $attr, $attrseq, $origtext);
}
sub end
{
my ($self, $tag, $origtext) = @_;
if (! $allowed{$tag}) { return; };
$self->SUPER::end($tag, $origtext);
}
sub output { push(@{$_[0]->{'fhtml'}}, $_[1]) }
sub filtered_html
{
# print main::STDERR join("", @{$_[0]->{'fhtml'}});
return join("", @{$_[0]->{'fhtml'}});
}
1;
|