Here's something I did for https://www.rosettacode.org/wiki/Display_an_outline_as_a_nested_table#Perl
It's not exactly what I think you want, but it may be close.
#!/usr/bin/perl
# http://www.rosettacode.org/wiki/Display_an_outline_as_a_nested_table
use strict;
use warnings;
my @rows;
my $row = -1;
my $width = 0;
my $color = 0;
our $bg = 'e0ffe0';
parseoutline( do { local $/; <DATA> =~ s/\t/ /gr } );
print "<table border=1 cellspacing=0>\n";
for ( @rows )
{
my $start = 0;
print " <tr>\n";
for ( @$_ ) # columns
{
my ($data, $col, $span, $bg) = @$_;
print " <td></td>\n" x ( $col - $start ),
" <td colspan=$span align=center bgcolor=#$bg> $data </td>\n"
+;
$start = $col + $span;
}
print " <td></td>\n" x ( $width - $start ), " </tr>\n";
}
print "</table>\n";
sub parseoutline
{
++$row;
while( $_[0] =~ /^( *)(.*)\n((?:\1 .*\n)*)/gm )
{
my ($head, $body, $col) = ($2, $3, $width);
$row == 1 and local $bg = qw( ffffe0 ffe0e0 )[ $color ^= 1];
if( length $body ) { parseoutline( $body ) } else { ++$width }
push @{ $rows[$row] }, [ $head, $col, $width - $col, $bg ];
}
--$row;
}
__DATA__
insects
large wings
butterfly
small or no wings
very long rear legs
antenna front
mosquito
antenna rear
grasshopper
shorter rear legs
horned head
rhino beetle
not horned head
small eyes
termite solder
large eyes
beetle
I used the information from the "Insects" drawing.
When the output is run through links -dump filename it
outputs:
+------------------------------------------------------------------
+------+
| insects
+ |
|------------------------------------------------------------------
+------|
| large wings | small or no wings
+ |
|-------------+----------------------------------------------------
+------|
| butterfly | very long rear legs | shorter rear legs
+ |
|-------------+--------------------------+-------------------------
+------|
| | antenna | antenna rear | horned | not horned h
+ead |
| | front | | head |
+ |
|-------------+-----------+--------------+---------+---------------
+------|
| | mosquito | grasshopper | rhino | small | l
+arge |
| | | | beetle | eyes | e
+yes |
|-------------+-----------+--------------+---------+-----------+---
+------|
| | | | | termite | be
+etle |
| | | | | solder |
+ |
+------------------------------------------------------------------
+------+
Of course, it can also be viewed in a browser.
insects |
large wings |
small or no wings |
butterfly |
very long rear legs |
shorter rear legs |
|
antenna front |
antenna rear |
horned head |
not horned head |
|
mosquito |
grasshopper |
rhino beetle |
small eyes |
large eyes |
|
|
|
|
termite solder |
beetle |
Wow, that worked :)
UPDATE: fixed typo in comment