File: HtmlStripper.pm

package info (click to toggle)
pronto 2.4.0-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,112 kB
  • ctags: 487
  • sloc: perl: 22,159; makefile: 127; sh: 34; sql: 7
file content (60 lines) | stat: -rw-r--r-- 1,099 bytes parent folder | download | duplicates (3)
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;