If you want to allow some HTML but not all, you can add a set of rules to allow arbitrary elements and attributes:
#!/usr/bin/perl
use strict;
use warnings;
use HTML::Restrict;
my $hr = HTML::Restrict->new();
# use default rules to start with (strip away all HTML)
my $processed = $hr->process('i am bold');
# $processed now equals: i am bold
#!/usr/bin/perl
use strict;
use warnings;
use HTML::Restrict;
my $hr = HTML::Restrict->new();
$hr->set_rules({
b => [],
img => [qw( src alt )]
});
my $html = q[hello ];
my $processed = $hr->process( $html );
# $processed now equals: hello
This has now been released as Open Source software and is available on the CPAN
3 comments:
Hi,
just wanted to say that it's awesome.
Nice module. One thing I want to ask is that why doesn't
body => [qw(onLoad)],
works? neither does any javascript function like "onClick, onMouseDOwn" etc?
One thing more is that I don't want the HTML comments to be deleted. How can I do this?
Thanks in advance.
@chankey I've dealt with your question on your original StackOverflow question.
Post a Comment