#! /usr/bin/perl # $Cambridge: exim/doc/doc-docbook/TidyHTML-filter,v 1.1 2005/06/16 10:32:31 ph10 Exp $ # Script to tidy up the filter HTML file that is generated by xmlto. The # following changes are made: # # 1. Split very long lines. # 2. Create reverse links from chapter and section titles back to the TOC. $tocref = 1; # Read in the filter.html file. open(IN, "filter.html") || die "Failed to open filter.html for reading: $!\n"; @text = ; close(IN); # Insert a newline after every > because the whole toc 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 (@text) { $line =~ s/>\s*/>\n/g; } for ($i = 0; $i < scalar(@text); $i++) { splice @text, $i, 1, (split /(?<=\n)/, $text[$i]); } # We want to create reverse links from each chapter and section title back to # the relevant place in the TOC. Scan the TOC for the relevant entries. Add # an id to each entry, and create tables that remember the new link ids. We # detect the start of the TOC by
/) { my($ss) = $1; my($id) = sprintf "%04d", $tocref++; $text[$i] =~ s/$/) { my($ref) = $backref{"#$2"}; $text[$i++] = "\n"; my($temp) = $text[$i]; $text[$i] = $text[$i+1]; $text[++$i] = $temp; } } } # Write out the revised file open(OUT, ">filter.html") || die "Failed to open filter.html for writing: $!\n"; print OUT @text; close(OUT); # End