New API: "xhtml/1.x/std/toc.wml"

Shlomi Fish <[email protected]> Sat, 26 Nov 2005 22:38:50 +0200
Newsgroups gmane.comp.web.wml
Message-ID <[email protected]>
Hi all!

Today, I wanted to generate a table of contents for my homepage's links page:

http://www.shlomifish.org/links.html 

I had several posssiblities:

1. Use wml::std::toc - only problem with it is that it only handles ancient 
HTML without the <h1>, <h2>, etc. id attributes, as well as doesn't handle <a 
tags inside the <h?> tags. Not such a good idea.

2. Construct the ToC manually - a lot of black labour.

3. Use a custom XML format for the page and generate it. (I already did it 
for: http://www.shlomifish.org/philosophy/Index/ )

4. Write my own ToC framework.

I eventually opted for #4, as the one of the three greatest virtues of a 
programmer is Laziness. It took me some time, and a certain misbehaviour of 
Perl (map { "a", "b", "c" } instead of map { ("a", "b", "c") } ) delayed me a 
bit, as well as some typos, but I eventually did it. You can find the results 
by executing the command "svn checkout" with the following URL:

http://svn.berlios.de/svnroot/repos/thewml/extended-apis/trunk/xhtml/1.x/

This is the first utilisation of the Subversion repository of our project at 
berlios.de.

At the moment, there's still a lot of duplicate code, which I'll have to think 
how to avoid. (possibly by code generation of some sort). And the code may 
have some style issues.

It can only handle <h2> and <h3> at the moment, but it's just a start.

-------------

To use it, add $HOME/apps/wml to your mp4h include path and execute the 
command:

<<<<<<<<
#include "xhtml/1.x/std/toc.wml"
>>>>>>>>
at the top of your WML script.

Use the tag:

<<<<<<<<
<toc />
>>>>>>>>

to render the navigation bar.

Regards,

	Shlomi Fish

---------------------------------------------------------------------
Shlomi Fish      [email protected]
Homepage:        http://www.shlomifish.org/

95% of the programmers consider 95% of the code they did not write, in the
bottom 5%.
_____________________________________________________________________
Website META Language (WML)                         http://thewml.org
User Support Mailing List                        [email protected]
Automated List Manager                            [email protected]