table --> pre?

H

hymie!

Greetings.

Can somebody recommend to me a perl script or a perl module that
takes an HTML-formatted <table> and produces a space-formatted
output that would be suitable for use within a <pre> tag?

I currently have a black-box java script that does this, but doesn't
do it well, and I don't have the ability to adjust it. At least with a
perl script, I can probably tweak it to meet my needs.

Thanks.

--hymie! http://lactose.homelinux.net/~hymie (e-mail address removed)
-------------------------------------------------------------------------------
 
K

Keith Keller

Can somebody recommend to me a perl script or a perl module that
takes an HTML-formatted <table> and produces a space-formatted
output that would be suitable for use within a <pre> tag?

You can use the HTML::TreeBuilder module to parse the HTML, and use a
loop around your table to print it out however you want. (You might
also look at the HTML::FormatText module, which claims not to support
HTML tables, but might print out something minimal that's still usable.)

--keith
 
M

Mart van de Wege

Greetings.

Can somebody recommend to me a perl script or a perl module that
takes an HTML-formatted <table> and produces a space-formatted
output that would be suitable for use within a <pre> tag?
I use Text::FormatTable to create those kind of text-only formatted
tables.

Mart
 
D

Dr.Ruud

Can somebody recommend to me a perl script or a perl module that
takes an HTML-formatted<table> and produces a space-formatted
output that would be suitable for use within a<pre> tag?

I currently have a black-box java script that does this, but doesn't
do it well, and I don't have the ability to adjust it. At least with a
perl script, I can probably tweak it to meet my needs.

Or use links/lynx?
 
C

ccc31807

Greetings.

Can somebody recommend to me a perl script or a perl module that
takes an HTML-formatted <table> and produces a space-formatted
output that would be suitable for use within a <pre> tag?
Greetings.

Can somebody recommend to me a perl script or a perl module that
takes an HTML-formatted <table> and produces a space-formatted
output that would be suitable for use within a <pre> tag?

This obviously depends on what you content looks like, but the
following is a start.

SCRIPT
#! perl
use strict;
use warnings;

my $content = '';
while (<DATA>)
{
next unless /\w/;
chomp;
if ($_ =~ m!<(\/?)table!)
{
$content .= "<$1pre>
";
next;
}
elsif ($_ =~ m!<\/?tr!)
{
$content .= "
\n";
next;
}
elsif ($_ =~ m!<t[dh]>([^<]*)<\/t[dh]>!)
{
$content .= sprintf("%-20s", $1);
next;
}
else
{
warn "ERROR: $_\n";
}
}
print $content;

exit(0);

__DATA__
<table>
<tr>
<td>George</td>
<td>Washington</td>
<td>Virginia</td>
<td>1788</td>
</tr>
<tr>
<td>George</td>
<td>Washington</td>
<td>Virginia</td>
<td>1792</td>
</tr>
<tr>
<td>John</td>
<td>Adams</td>
<td>Massachesetts</td>
<td>1796</td>
</tr>
<tr>
<td>Thomas</td>
<td>Jefferson</td>
<td>Virginia</td>
<td>1800</td>
</tr>
<tr>
<td>Thomas</td>
<td>Jefferson</td>
<td>Virginia</td>
<td>1804</td>
</tr>
</table>

OUTPUT'
<pre>
George Washington Virginia 1788

George Washington Virginia 1792

John Adams Massachesetts 1796

Thomas Jefferson Virginia 1800

Thomas Jefferson Virginia 1804
</pre>
 
H

hymie!

In our last episode, the evil Dr. Lacto had captured our hero,
I use Text::FormatTable to create those kind of text-only formatted
tables.

Thanks for the tip. It would be nice if this could manage colspans,
but I think this is the way I'm going to end up going.

--hymie! http://lactose.homelinux.net/~hymie (e-mail address removed)
 
H

Helmut Richter

Thanks for the tip. It would be nice if this could manage colspans,
but I think this is the way I'm going to end up going.

Of the ready-for-use tools (not exactly what you were asking), w3m seems
the one that does the job best to convert text/html to text/plain.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top