Post Archive
› September 5, 2003
Auto-generating a Table of Contents
I recently launched a open source product, built on Mozilla naturally, for heuristic review.
One of the notable, if subtle, featues of uzReview is an auto-generated table of contents in the HTML documentation. Using a DOM2 treeWalker with a filter that grabs only heading tags provides a handle from which anchor links can be generated. CSS takes care of indentation.
This approach, as discusssed with Jamie Blustein at Hypertext '03, should be a core part of the web, organizing well structured documents automatically. Alas, the walker DOM2 feature is unimplemented in IE and I've never seen this done. Any prior art or IE implementations?
Comments
1. September 6, 2003 06:23 AM
2. September 6, 2003 01:21 PM
Lon Posted…
Shouldn't we start using XML/XSLT for stuff like this?3. September 6, 2003 02:01 PM
iva Posted…
XML/XSLT is the way to go IMO, as well. TOCs, snail trails, page counters and such are natural candidates for XML/XSLT.
4. September 6, 2003 08:51 PM
liorean Posted…
Yeah, but how about using this as a bookmarklet on sites that lack a ToC? But, really, this is an excellent place for XBL/HTC. They have the added benefit over XML/XSLT that they are nondestructive and preserves all semantics and structure of the original document while still allowing a kind of transformation to take place.
5. September 7, 2003 11:07 AM
iva Posted…
Sure, but XBL/HTCs are not something I've seriously considered so far because of current state/support. I wouldn't worry about an XSLT transformation being distructive in this case, because with something like generating a TOC, it would be for presentation purposes only, no real semantics/structure is lost.
liorean Posted…
Well, actually, a script doing just that, utilising nodeIterator, treeWalker or simply trasersing the DOM tree (forks depending on support for the given feature) was written, at least as a skeleton, in a CF forum some months ago. I don't know exactly the details of how it worked as I never ran it myself.