|
Cookbook /
PageTableOfContentsSummary: Adds a clickable table of contents to a page
Version: 2.0.38 (released 2012-08-03)
Status: Stable
Prerequisites: pmwiki 2.0 and above; 2.1 recommended
Maintainer: jr
Discussion: PageTableOfContents-Talk
GoalGenerate a table of contents for a wiki page, using any headings found on the page. SolutionPlease note. The PublishPDF library includes the PageTableOfContents recipe. When typesetting a page as PDF, the toc entries gain page number references. pagetoc.phpΔ -- this is a stable release. It uses the new directive markup and works with version 2.0 dev 17 and later. (if you notice strange font, try this pagetoc.phpΔ, "&ensp" are changed in " ", so it's displayed better in most browsers)
Put pagetoc.php in your cookbook/ directory. Add the following line to local/config.php Some usage notes in relation to other scripts:
DiscussionThe simplest usage is to add the following line on any wiki page That's it. Any headings and questions after the toc directive will be listed, to 2 levels. Once Some Page contains a
You can make the anchors a toc creates visible by writing
If you have entered your own anchors, it uses these. If you want to make your own anchors visible, write You can change the default heading text by writing
You can combine visible anchors and a replacement heading by writing You can change the numbered list (in case $NumberToc is true) to an itemised list by writing
You can change the itemized list (in case $NumberToc is false) to a numbered list by writing
You can make the anchors visible and replace the heading here too. You can control inclusion or exclusion of Q: markups by writing
This will cause toc to omit Q: markups. An administrator can also set $OmitQMarkup to true in config.php to omit Q: markups by default. In this case, You can use wiki markup in your headings and toc will work out suitable link text. Well, it's supposed to... Standard PmWiki 2 markup supports
To create a link back to the table of contents (which automatically has a
To specify the text to be used for the link back, write (for example): Subsequent If you use PmWiki/WikiStyles in headings that will appear in the toc, be sure to close them explicitly with %% markup. Otherwise, the style will apply to all following toc item entries. If you have the MarkupExtensions installed, you can omit a heading from the toc by using "invisible stop" markup: `.!!An omitted heading See http://intranet.affinity.co.nz/pmwiki2/index.php?n=PmWiki.TextFormattingRules -- the sample headings do not appear in the toc. If you don't have the MarkupExtensions recipe installed and want to omit headings, add the following to your config.php file Markup("`.",'>links',"/`\./",'');
To generate a table of contents for a remote page write
Some Page must include a
directive on Some Page. This will cause toc-page to pick up headings after the toc-hide directive, insert the necessary anchors, but does not display a table of contents. The toc-hide directive supports all toc variants; for example By default, (:toc-page:) doesn't display a toc if the page name is the current page. You can override this by writing:
You can configure the floating of the table of contents by using the
The $TocFloat configuration variable (see below) specifies the default position of the table of contents. By default, (:toc-float:) floats the TOC on the right. Configuration variables
LimitationsThe code that builds the table of contents is messy. To extend this to support more than 2 levels would require a complete re-write of the History03 Aug 2012 include $GroupHeaderFmt in text for toc-page option
04 Aug 2006 remove alignment styles and improve toc styling
11 April 2006 fix show/hide problem with toc-page in sidebars
30 March 2006 add self=1 option to (:toc-page:) and use different toggle-id
15 Mar 2006 add (:toc-hide:) directive
09 Feb 2006 make the toc clickable (show / hide link)
07 Nov 2005 add $DefaultTocAnchor and (:toc-float:)
02 Oct 2005 adjust number styles and indents
20 Sep 2005 add numbering to headings if the toc is numbered
21 Sep 2005 add border and light grey background colour by default
04 Jul 2005 add option to float toc to the right of the page
27 Mar 2005 add (:toc-page Some Page:) to create a toc for a remote page
22 Feb 2005 add a capability to omit headings defined with (:markup:), eg so PmWiki/TextFormattingRules can have a nice toc
13 Feb 2005 fix bug that omitted a start of page heading when the toc directive is in a GroupHeader page -- thanks to Jota
27 Jan 2005 add support for (:toc Q:) markup to control inclusion or omission of Q: markups -- thanks to Christian
25 Jan 2005 fix incompatibility with pmwiki beta 19, which led to invalid html being generated
4 & 10 Jan 2005 add (:toc-back:) directive for a link back to the table of contents -- thanks to Christian
17 Nov 2004 fix offset notice when processing definition list markup for autonumbered anchors -- thanks to Christian
8 Nov 2004 remove style that controls indenting of itemised lists -- thanks to PRZ
7 Nov 2004 add support for a (:#toc:) variant to create a numbered toc when $NumberToc is false
4 Nov 2004 really fixed the invalid HTML bug; added itemised list markup option and font-size control
3 Nov 2004 fixed invalid HTML bug (I think) -- thanks to Val
ContributorSee also
CommentsSee discussion at PageTableOfContents-Talk User notes +5 -1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki. |
||||||||||||||||||||||||||||||||||||