####
#!/usr/bin/perl
# note, warnings are off because this shouldn't generate
# 'em except where there is no "style" attribute on
# image tags.
use strict;
use HTML::Parser;
my $p=HTML::Parser->new( default_h => [ sub { print $_[0] }, 'text' ],
start_h => [\&start_tag, 'tagname, attr, text']);
$p->parse_file(*DATA);
sub start_tag {
my($tagname, $attr, $origtext) = @_;
if ( ! ( $tagname eq "img") ) {
print $origtext;
return;
}
if ($attr->{style} !~/display:block/) {
# avoid messy issues with other styles that may have been defined
$attr->{style} = "display:block;". $attr->{style};
}
print "<$tagname";
foreach ( keys %$attr) {
print qq{ $_="} .$attr->{$_}.qq{"};
}
print ">";
}
__DATA__
Boo
Hello
Hi there