Thomas Counsell
3/17/2005 4:30:00 PM
Hello
On 17 Mar 2005, at 15:44, 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:
>
> <div class="ToC">
> ToC. <-- Replaced by *cloth bye the table of content -->
> </div>
>
> and get a beautiful and well linked table of content for free.
>
> Is there already such a feature?
Not in Redcloth at the moment AFAIK.
> Is it a reasonable feature request?
It wouldn't be hard to write. Maybe an hours work? I think it could
be more or less added to the Redcloth class without changing any
existing code.
I would go about it by adding two extra methods:
# refs_toc(text) that would text.gsub! for h1,h2 etc, and put the
anchor next to each
# block_toc(text) that would text.gsub! for ToC and replace it with the
table html.
It could then be activated by passing :refs_toc, :block_toc,
:textile_rules to the to_html method or changing the DEFAULT_RULES
constant.
It is one of the things I've been considering writing for my Soks wiki,
so if you can wait I'll get to it, or someone else could step into the
breach?
Tom