\n/g;
$line =~ s/<\/p>\s*(?!\n)/<\/p>\n/g;
$line =~ s/<\/div>\s*(?!\n)/<\/div>\n/g;
$line =~ s/
]*)>(?!\n)/
\n/g;
}
for ($i = 0; $i < scalar(@text); $i++)
{ splice @text, $i, 1, (split /(?<=\n)/, $text[$i]); }
$thisdiv = 0;
for ($i = 0; $i < scalar(@text); $i++)
{
if ($text[$i] =~ /^(.*?)
<\/a>(.+?)<\/h(.*)$/)
{
my($pre, $opt, $id, $title, $post) = ($1, $2, $3, $4, $5);
# Section reference
my($ref) = $backref{"$file#$id"};
# If not found, try for a chapter reference
$ref = $backref{"$file"} if !defined $ref;
# Adjust the line
$text[$i]= "$pre$title\n" && $text[$i+1] eq "
\n")
{
$text[++$i] = "";
$thisdiv = 1;
}
elsif ($thisdiv && $text[$i] eq "
\n" && $text[$i+1] eq "
\n")
{
$text[$i] = "";
$thisdiv = 0;
}
elsif ($text[$i] =~ /^\s*<\/td>/)
{
$text[$i] = " $text[$i]";
}
}
open(OUT, ">$file") || die "Failed to open $file for writing: $!\n";
print OUT @text;
close(OUT);
}
# Now process the ix01.html file
open(IN, "ix01.html") || die "Failed to open ix01.html for reading: $!\n";
@index =
;
close(IN);
# Insert a newline after every > because the whole index is generated as one
# humungous line that is hard to check. Then split the lines so that each one
# is a separate element in the vector.
foreach $line (@index) { $line =~ s/>\s*/>\n/g; }
for ($i = 0; $i < scalar(@index); $i++)
{ splice @index, $i, 1, (split /(?<=\n)/, $index[$i]); }
# We want to add a list of letters at the top of the index, and link back
# to them from each letter heading. First find the index title and remember
# where to insert the list of letters.
for ($i = 0; $i < scalar(@index); $i++)
{
if ($index[$i] =~ /^<\/h2>$/)
{
$listindex = $i;
last;
}
}
# Now scan through for the letter headings and build the cross references,
# while also building up the list to insert.
$list = "\n";
for (; $i < scalar(@index); $i++)
{
if ($index[$i] =~ /^(.)<\/h3>$/)
{
$letter = $1;
$index[$i-1] =~ s/^//;
$index[$i] =~ s/$/<\/a>/;
$list .= " $letter\n";
}
}
# Now we know which letters we have, we can insert the list.
$list .= "
\n";
splice @index, $listindex, 0, $list;
# Write out the modified index.html file.
open (OUT, ">ix01.html") || die "Failed to open ix01.html for writing: $!\n";
print OUT @index;
close(OUT);
# End