13 my $tree = HTML::TreeBuilder->new->parse_file($fn);
14 my ($chapter) = $tree->look_down( "_tag", "div", "class", "chapter", );
15 return '' unless ($chapter);
16 my $formatter = HTML::FormatText->new( leftmargin => 0, rightmargin => 72 );
18 my $text = $formatter->format($chapter);
23 sub chapters_in_order {
26 opendir DIR, $dir or die "opendir($dir) failed: $!\n";
27 my @numeric = sort grep {/^ch\d+\.html$/} readdir(DIR);
28 closedir(DIR) or die "closedir($dir) failed: $!\n";
31 $_ = File::Spec->catfile($dir, $_);
34 eval { $t = readlink $_ };
35 $_ = File::Spec->rel2abs($t, $dir) if defined $t;
44 die "Need a directory\n" unless defined $dir;
46 foreach my $fn ( chapters_in_order($dir) ) {
50 print process_chapter($fn);