да, решил, так:
Код: Выделить всё
...............................................
$text =~ s/<table(.*?)>(.*?)</table>/&dumptt($2)/egs;
sub dumptt {
my($html) = (@_);
$html = " <table> ". $html." </table>";
my $t = HTML::TreeBuilder->new();
$t->parse($html);
$t->eof;
foreach my $em ($t->find_by_tag_name('table')) {
my $em2 = $em;
my @tar = $em2->find_by_tag_name('tr');
if ($#tar > 3) {
my $ttt = Encode::encode( 'cp1252',DumpTable( $em )), $/, $/;
$ttt =~ s/ /-/isg;
$ttt = "1111111111111111".$ttt."2222222222222222";
return $ttt;
}
else {
return "";
}
#
}
}
sub DumpTable {
my($ht, $depth) = (@_,0);
die "$ht is not a table" unless $ht->tag eq 'table';
my $tt = Text::ASCIITable::->new;
my @co;
my @da;
my $da = [];
for my $ro ( @{ $ht->content() } ) {
if( $ro->tag eq 'tr' ) {
push @da, $da if @$da;
$da = [];
for my $ce ( @{ $ro->content() } ) {
if( $ce->tag eq 'td' ) {
if( $ce->look_down( '_tag', 'table' ) ) {
my $string = '';
for my $i ( @{ $ce->content() } ) {
if( not ref $i ) {
$string .= $i;
}
elsif( $i->tag eq 'table' ) {
$string .= "\n";
$string .= DumpTable($i,$depth+1);
$string .= "\n";
}
else {
$string .= $i->as_text;
}
}
push @$da, $string;
}
else {
push @$da, $ce->as_text;
}
}
elsif( $ce->tag eq 'th' ) {
push @co, $ce->as_text;
}
}
}
}
push @da, $da if @$da;
unless(@co) {
use List::Util qw(max);
my $max = 1 + max( 0, map { $#$_ } @da );
( @co ) = (' ') x $max ;
$tt->setOptions( hide_HeadRow => 1 );
$tt->setOptions( hide_HeadLine => 1 );
}
# warn " co ", map {"{$_}"} @co;
$tt->setCols( @co );
if( $depth == 0 ){
my $maxcolwidth = 120;
$maxcolwidth -= 1 for split //, '.==.'; # bad guesstimation
$maxcolwidth -= 2 for @co; # '| ' and '| '
$tt->setColWidth( $_, $maxcolwidth/(0+@co), 1) for @co;
}
$tt->addRow($_) for @da;
$tt->setOptions( 'drawRowLine', 1) if $ht->attr('border');
# return $tt->draw();
return $tt->draw(
[ '.=', '=.', '-', '-' ], # .=-----------=.
[ '|', '|', '|' ], # | info | info |
[ '|-', '-|', '=', '=' ], # |-===========-|
[ '|', '|', '|' ], # | info | info |
[ "'=", "='", '-', '-' ], # '=-----------='
[ '|=', '=|', '-', '*' ] # rowseperator
);
}
Pеrl FAQ
perl -e 'print join"",map $$_[rand@$_],([0..9,'a'..'z','A'..'Z'])x30'

