use strict; use warnings; use HTML::TokeParser; my @tags = @ARGV; @tags || die "Give a list of tags to retain.\n"; my %keep = map { lc($_) => 1, lc("/$_") => 1 } @tags; my $p = HTML::TokeParser->new(\*DATA); while ( my $t = $p->get_token ) { if ( $t->[0] =~ /S|E/ and $keep{$t->[1]} ) { print $t->[-1]; } elsif ( $t->[0] eq 'T' ) { print $t->[1]; } } __DATA__
Did italic and link with bold inside it.
naked linkThe content of the body element is displayed in your browser.
##
use warnings;
use strict;
use XML::LibXML;
my @strip = @ARGV;
@strip || die "Give a list of tags to strip.\n";
my $parser = XML::LibXML->new();
$parser->line_numbers(1);
my $raw = join '', ;
my $doc = $parser->parse_html_string($raw);
my $root = $doc->documentElement();
for my $strip ( @strip )
{
for my $node ( $root->findnodes("//$strip") )
{
my $fragment = $doc->createDocumentFragment();
$fragment->appendChild($_) for $node->childNodes;
$node->replaceNode($fragment);
}
}
print $doc->serialize(1);
__END__
Bang!1
Did italic and link with bold
inside it.
naked link
The content of the body element is
displayed in your browser.