#!/usr/bin/perl -w
use strict;
use HTML::PullParser;
use HTML::Tagset;
my $data;
if( defined($ARGV[0]) ) {
open IN, $ARGV[0] || die "cannot open source file $ARGV[0]";
undef $/;
$data= ;
}
else {
undef $/;
$data= ;
}
my $p= HTML::PullParser->new( doc => \$data,
text => '"v", text',
start => '"s", text, tagname',
end => '"e", text' );
my $ind= 0;
open OUT, "| less" and select OUT;
while( defined(my $tok= $p->get_token()) )
{
if( $tok->[0] eq "e" && $ind > 0 ) {
--$ind;
}
$tok->[1] =~ s/\s+$//;
print " " x $ind, $tok->[1], "\n" if $tok->[1];
if( $tok->[0] eq "s" && ! $HTML::Tagset::emptyElement{$tok->[2]} ) {
++$ind;
}
}