Ask a Question related to PERL Miscellaneous, Design and Development.
-
Jay Tilton #1
Re: html table tag indent script?
"Andrew" <tech7890@yahoo.com> wrote:
: Does anyone know of a perl script I may download or have a perl script of
: your own that lines up html table tags through indentation?
The code in Synopsis section of the HTML::PrettyPrinter pod is a
pretty good foundation. Season to taste with the set_nl_before() and
set_nl_after() methods, and voila.
Here's the one I've been using for some time now. Not bulletproof,
but it whips most HTML samples into reasonable shape.
#!perl
use warnings;
use strict;
use HTML::TreeBuilder;
use HTML::PrettyPrinter;
use File::Slurp qw(write_file);
die "Usage: $0 file1 [file2 file3 ...]\n"
unless @ARGV;
for(@ARGV) {
print "$_ : reading...";
my $html = pretty( tree($_) );
# Backup original file. No check on whether file exists
# already or if rename succeeds. Use at your own risk.
rename $_, "$_.bak";
print "writing...";
write_file( $_, $html );
print "done.\n";
}
sub tree {
my($filename) = @_;
my $tree = HTML::TreeBuilder->new(
store_comments => 1,
warn => 1,
);
$tree->parse_file($filename);
return $tree;
}
sub pretty {
# tags that get newlines before & after
my @nl_before_after = qw(
h1 h2 h3 h4 h5
dl dd dt
table td th tr
ul li ol
body html p div style img map
);
# tags that get newline before
my @nl_before = qw( a head link meta title script br );
# tags that get newline after
my @nl_after = qw( );
my($tree) = @_;
my $hpp = HTML::PrettyPrinter->new(
tabify => 0,
linelength => 1e6,
quote_attr => 1,
allow_forced_nl => 1,
);
# Screw any defaults. I want it my way.
$hpp->set_nl_before(0, 'all!');
$hpp->set_nl_after(0, 'all!');
$hpp->set_force_nl(1, qw / br /);
$hpp->set_nl_before(1, @nl_before_after, @nl_before);
$hpp->set_nl_after(1, @nl_before_after, @nl_after);
local $" = '';
return "@{ $hpp->format($tree) }";
}
Jay Tilton Guest
-
Left indent affecting right indent in TOC
Hi. I'm an ID newbie, and I've created a TOC. I'm OK with picking up the styles in the doc (there are only 2 I need to use). The problem is that... -
xml to html table
I am trying to get an simpls xml file to display into a simple html table. I can get it to work with IE, but for some reason, nothing comes up with... -
Table and Hanging indent
I have set a table up in InDesign and all appears fine, after the table I have 3 paragraphs each with hanging indents. The table and paragraphs are... -
css table vs. html table
I've been using standard html tags to create tables. Over the past two years I have been reading about the advantages of using CSS to create tables,... -
Changing a html table when new data is entered into SQL table.
Hi all, I was wondering if anyone has any ideas on how I would go about this task. What I have is a html table which is populated from 2 different...



Reply With Quote

