[pmwiki-users] Table of content generation
John Rankin
john.rankin at affinity.co.nz
Thu Feb 17 15:44:00 CST 2005
On Thursday, 17 February 2005 4:12 PM, Patrick R. Michaud <pmichaud at pobox.com> wrote:
>I have a number of suggestions which may or may not be helpful here.
>First, I'll note that I've never looked in depth at the existing
>table of contents recipe, so I'm not sure how it works. But if it's
>still based on the v1 recipe, then it may be a bit more complex than
>necessary. (In fact, one of the reasons for v2 was to make it
>more possible to support things like table of contents.)
Yes, it generates nested <ol> and <ul> markup which I think pmwiki 2
ought to be able to do for me. I need to get a round toit.
>
>I can envision two approaches to the problem that Pierre is
>trying to resolve...
>
>Approach #1: Instead of building the table contents during interpretation
>of the heading markups, build the table when the entire markup text
>is available to be examined; i.e., *before* the split into separate
>lines occurs:
>
> Markup("toc", "<split"
> '/\\(:toc:\\)/e',
> "TableOfContents(\$pagename, \$x)");
The toc directive generates a toc using headings that fall /after/ the
directive. It currently runs >nl0 to handle cases where the (:toc:) is
in a GroupHeader and (ignoring toc qualifiers) matches on
'/\\(:toc:\\)(.*)$/se'
Also, at that point it inserts anchors into the headings of any entries
that don't have them.
It looks as if I could change >nl0 to <split.
>
>Approach #2: You can accumulate table-of-contents data as the headings
>are processed as you are doing now, then place it into the markup output
>via the 'posteval' section of MarkupToHTML(). To do this, you add
>an entry to $MarkupFrameBase['posteval'] with the code to be executed
>after all of the markups have been processed (the current output is
>stored in $out):
>
> $MarkupFrameBase['posteval']['toc'] =
> "\$out = str_replace('(:toc:)',
>\$_GLOBALS['TableContents'], \$out); ";
>
>This would scan the HTML output for any instances of '(:toc:)' and
>replace them with $TableContents.
That's very interesting!! I'll have to remember it.
>
>Hope this helps.
>
>I'm interested in adding a numbered headings scheme (and table of
>contents) to PmWiki's distribution, but I'm not completely satisfied
>with the markups involved.
We'll have to resurrect Christian's amazing toc test cases, which
uncovered many a bug and misfeature.
--
JR
--
John Rankin
More information about the pmwiki-users
mailing list