3 # $Cambridge: exim/doc/doc-docbook/Tidytxt,v 1.2 2006/02/01 11:01:01 ph10 Exp $
5 # Script to tidy up the output of w3m when it makes a text file. First we
6 # convert sequences of blank lines into a single blank line, to get everything
7 # uniform. Then we go through and insert blank lines before chapter and
8 # sections, also converting chapter titles to uppercase.
13 foreach $line (@lines)
17 $line = "" if $lastwasblank;
24 # Find start of TOC, uppercasing its title
26 for ($i = 0; $i < scalar @lines; $i++)
28 $lines[$i] = "TABLE OF CONTENTS\n" if $lines[$i] =~ /^Table of Contents/;
29 last if $lines[$i] =~ /^1. /;
32 # Find start of first chapter
34 for ($i++; $i < scalar @lines; $i++)
35 { last if $lines[$i] =~ /^1. /; }
37 # Process the body. We can detect the starts of chapters and sections by
38 # looking for preceding and following blank lines, and then matching against
42 for (; $i < scalar @lines; $i++)
44 next if $lines[$i-1] !~ /^$/ || $lines[$i+1] !~ /^$/;
48 if ($lines[$i] =~ /^(\d+)\. / && $1 == $chapter + 1)
52 $lines[$i] = "\n\n" . ("=" x 79) . "\n" . uc($lines[$i]);
55 # Start of next section
57 elsif ($lines[$i] =~ /^(\d+)\.(\d+) / && $1 == $chapter && $2 == $section + 1)
60 $lines[$i] = "\n$lines[$i]" . "-" x (length($lines[$i]) - 1) . "\n";