summaryrefslogtreecommitdiff
path: root/doc/doc-docbook/TidyHTML-spec
diff options
context:
space:
mode:
authorPhilip Hazel <ph10@hermes.cam.ac.uk>2005-06-16 10:32:31 +0000
committerPhilip Hazel <ph10@hermes.cam.ac.uk>2005-06-16 10:32:31 +0000
commit168e428fc4dfcf7f4d377d137743d8332784fa35 (patch)
treeafdd32a3a7f9f28dfce516421077baf3383c87d0 /doc/doc-docbook/TidyHTML-spec
parent612ba564e598548543eb4d3e2313d7be687beb9b (diff)
Install all the files that comprise the new DocBook way of making the
documentation.
Diffstat (limited to 'doc/doc-docbook/TidyHTML-spec')
-rwxr-xr-xdoc/doc-docbook/TidyHTML-spec139
1 files changed, 139 insertions, 0 deletions
diff --git a/doc/doc-docbook/TidyHTML-spec b/doc/doc-docbook/TidyHTML-spec
new file mode 100755
index 000000000..8459bcf17
--- /dev/null
+++ b/doc/doc-docbook/TidyHTML-spec
@@ -0,0 +1,139 @@
+#! /usr/bin/perl
+
+# $Cambridge: exim/doc/doc-docbook/TidyHTML-spec,v 1.1 2005/06/16 10:32:31 ph10 Exp $
+
+# Script to tidy up the spec HTML files that are generated by xmlto. The
+# following changes are made:
+#
+# 1. Tidy the index.html file by splitting the very long lines.
+# 2. Create reverse links from chapter and section titles back to the TOC.
+# 3. Tidy the ix01.html file - the actual index - by splitting long lines.
+# 4. Insert links from the letter divisions to the top of the Index.
+
+chdir "spec.html";
+
+$tocref = 1;
+
+# Read in the index.html file. It's really the TOC.
+
+open(IN, "index.html") || die "Failed to open index.html for reading: $!\n";
+@toc = <IN>;
+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 (@toc) { $line =~ s/>\s*/>\n/g; }
+for ($i = 0; $i < scalar(@toc); $i++)
+ { splice @toc, $i, 1, (split /(?<=\n)/, $toc[$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 file names and the
+# new link ids.
+
+foreach $line (@toc)
+ {
+ if ($line =~ /^<a href="((?:ch|ix)\d+\.html)(#[^"]+)?">/)
+ {
+ my($chix) = $1;
+ my($ss) = $2;
+ my($id) = sprintf "%04d", $tocref++;
+ $line =~ s/<a/<a id="toc$id"/;
+ $backref{"$chix$ss"} = "toc$id";
+ push @chlist, $chix;
+ }
+ }
+
+# Write out the modified index.html file.
+
+open (OUT, ">index.html") || die "Failed to open index.html for writing: $!\n";
+print OUT @toc;
+close(OUT);
+
+# Now scan each of the other page files and insert the reverse links.
+
+foreach $file (@chlist)
+ {
+ open(IN, "$file") || die "Failed to open $file for reading: $!\n";
+ @text = <IN>;
+ close(IN);
+
+ foreach $line (@text)
+ {
+ if ($line =~ /^(.*?)<a( xmlns="[^"]+")? id="([^"]+)"><\/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
+ $line = "$pre<a$opt href=\"index.html#$ref\" id=\"$id\">$title</a></h$post";
+ }
+ }
+
+ 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 = <IN>;
+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 = "<h4>\n";
+for (; $i < scalar(@index); $i++)
+ {
+ if ($index[$i] =~ /^(.)<\/h3>$/)
+ {
+ $letter = $1;
+ $index[$i-1] =~ s/^/<a id="${letter}B" href="#${letter}T">/;
+ $index[$i] =~ s/$/<\/a>/;
+ $list .= "<a id=\"${letter}T\" href=\"#${letter}B\"> $letter</a>\n";
+ }
+ }
+
+# Now we know which letters we have, we can insert the list.
+
+$list .= "</h4>\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