#!/usr/bin/perl
use LWP::Simple;
use HTML::Parse;
use HTML::Entities;
use HTML::FormatText;
use Getopt::Long;

use strict;
require 5.0;

=pod

=head 1 hp -- HTML prettyprinter

Online documentation will go here

=cut

# initialize variables local to main loop 

my ($tabspace) = 3;  # default num. of columns per tabstop
my ($wrapcols) = 70; # default page width for line wrap
my ($implicit) = 1;  # flag: insert implicit tags, or not
my ($help)     = 0;  # do we want help?
my ($target) = "";   # name of current file to process

# set up command line options

GetOptions("w=i"       => \$wrapcols,
           "wrap=i"    => \$wrapcols,
           "t=i"       => \$tabspace,
           "tab=i"     => \$tabspace,
           "implicit!" => \$implicit,
           "h"         => \$help,
           "help"      => \$help);

# issue help message, if needed

if (($help > 0)|| ($ARGV[0] eq"")) {
   print "\nhppt -- html to text (formatter)\n",
         "reformat an HTML document to be more easily maintainable.\n",
         "\nOptions:\n",
         "-h, --help            (print this message) \n",
         "\n\nTypical usage:\n",
         "hppt index.html >index.asc\n\n";
   exit 0;  
}

# foreach specified file, prettyprint it!

foreach $target (@ARGV) {
    my ($p) = HTML::Parser->new;
    $HTML::Parse::IMPLICIT_TAGS = $implicit;
    $p = parse_htmlfile($target);
    my ($formatter) = new HTML::FormatText;
    print $formatter->format($p);
}

exit 0;
