From: Barry Dmytro Date: 2005-03-18T03:04:45+09:00 Subject: Re: *cloth and ToC I did this exact thing in a wiki I'm writting. Here is the code for what I did: $toc = "" headreg = /^\s*h([1-6])\.\s+(.*)/ $document.gsub!(headreg) do |m| number = $1 name = $2 header = name.gsub(/\s/,"+") $toc << '#'*num.to_i + ' "' + name + '":#' + header + "\n" 'h' + num + '. ==^' + name + '==' end This will go through a textile document ($document) and add a link to the top of the page every time it finds a header and build a table of contents as it goes along. The table of contents it builds is a textile document itself so you'd have to run it through redcloth as well, but it will link to each header found throughout the page. As far as nameing the header it takes the contents of the header and strips out the spaces so that it is a valid url. Guillaume Marcais wrote: > Is there a way to extract a table of content of a text with redcloth of > bluecloth? > > What I have in mind is the ability to extract all the headers of a text > (h1., h2., etc. in textile) and generate: anchors within the html page > on these headers and a table of content with links to the headers. > > So at the end of a wiki page I could add something like: > >
> ToC. <-- Replaced by *cloth bye the table of content --> >
> > and get a beautiful and well linked table of content for free. > > Is there already such a feature? Is it a reasonable feature request? > > Guillaume. -- Barry Dmytro badcherry@mailc.net http://badcherry.org/