Hannes Magnusson wrote:
> Hmh. I don't think adding a TOC to the html output is the
> right-way-to-go, but you are right, we do need some sort of real index
> on the front page.
Attached is a hack that adds a classic style Table of Contents to the
index.html/manual.html pages as an interim solution. It could be made
cleaner if the navigation-ification code in format_root_chunk was
factored into its own method. This technique may also work for the
bightml theme.
It occurs to me that, since each "book" generates its own table of
contents, we only need links to those sections. format_root_chunk works
pseudo-recursively (it goes two levels deep), so once it is factored out
we could add that as a parameter, and convert the function into a truly
recursive one.
The special treatment of manual.html worries me slightly; I think the
hierarchy should be an index.html with special treatment (in this case,
including some of the contents of manual.html) while manual.html is just
a standard root page. This would also be more conducive to a TOC.
Also attached is a documentation patch for PhDReader, which clarifies
what notXPath does.
--
Edward Z. Yang GnuPG: 0x869C48DA
HTML Purifier <http://htmlpurifier.org> Anti-XSS Filter
[[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]
Index: chunkedhtml.php
===================================================================
RCS file: /repository/phd/themes/php/chunkedhtml.php,v
retrieving revision 1.6
diff -u -r1.6 chunkedhtml.php
--- chunkedhtml.php 21 Oct 2007 11:42:33 -0000 1.6
+++ chunkedhtml.php 5 Nov 2007 18:48:21 -0000
@@ -1,4 +1,4 @@
-<?php
+<?php require_once 'themes/php/phpweb.php';
class chunkedhtml extends phpweb {
private $nav = "";
@@ -48,6 +48,19 @@
copy("html/manual.html", "html/index.html");
}
}
+ public function format_root_chunk($open, $name, $attrs) {
+ if ($attrs[PhDReader::XMLNS_XML]['id'] == 'manual' && !$open) {
+ // HACK!
+ $toc = '<h2>Table of Contents</h2>';
+ $toc .= parent::format_root_chunk(false, 'index', array(
+ PhDReader::XMLNS_XML => array(
+ 'id' => 'index'
+ )
+ ));
+ }
+ $content = parent::format_root_chunk($open, $name, $attrs) . $toc;
+ return $content;
+ }
}
/*
Index: PhDReader.class.php
===================================================================
RCS file: /repository/phd/include/PhDReader.class.php,v
retrieving revision 1.12
diff -u -r1.12 PhDReader.class.php
--- PhDReader.class.php 21 Oct 2007 17:08:44 -0000 1.12
+++ PhDReader.class.php 5 Nov 2007 19:17:28 -0000
@@ -70,6 +70,7 @@
$this->opts = $opts;
}
+ /* Reduce an array map entry into a string based on parent elements */
public function notXPath($tag, $depth = 0) {
if(!$depth) {
$depth = $this->depth;
@@ -78,6 +79,7 @@
if (isset($tag[$this->STACK[--$depth]])) {
$tag = $tag[$this->STACK[$depth]];
} else {
+ // no match found, fall back to default
$tag = $tag[0];
}
} while (is_array($tag));