[pmwiki-users] Table of content generation
Patrick R. Michaud
pmichaud at pobox.com
Wed Feb 16 21:12:41 CST 2005
On Wed, Feb 16, 2005 at 11:27:14PM +0100, Pierre Rouzeau wrote:
> I am building the content of the table during interpretation of the
> title markups. Then, the interpretation is finished, and i want the
> table to be set 'before' the contents it is supposed to link to.
Also, John Rankin writes:
> Every time I go back to the table of contents script, I find myself
> wondering how on earth I ever got it to work. ;-)
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.)
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
The "split" markup is the point at which PmWiki breaks the text into
separate lines (i.e., after conditional markup and includes), thus by
performing the (:toc:) conversion before the split takes place the
$x variable will contain the *entire contents* of the markup text.
You can thereby scan the entire text for any heading markups needed to
build the table of contents, and replace the (:toc:) with an appropriately
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):
"\$out = str_replace('(:toc:)', \$_GLOBALS['TableContents'], \$out); ";
This would scan the HTML output for any instances of '(:toc:)' and
replace them with $TableContents.
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.
More information about the pmwiki-users