|
Cookbook /
PageTableOfContentsSummary: Adds a clickable table of contents to a page
Version: 2.0.31
Status: Stable
Prerequisites: pmwiki 2.0 and above; 2.1 recommended
Maintainer: jr
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 History04 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
ContributorI'm having trouble using (:toc:) in a Group.Header page. It doesn't show the first Header in the Group.Page. If i use the (:toc:) markup in the Group.Page it works fine. See http://rtr.inesc-id.pt/~rjc/Sala/OutrosDetalhes for error example Update: If i add a line to the page start, the header (:toc:) works. This unfortunately isn't a good solution. One has to add a line every time the page gets updated.
~Jota It looks as if this is caused by the order in which directives are evaluated. The toc script only picks up heading markup with a preceding "\n". I have changed the sequence of toc processing so it gets evaluated after the (:nl:) markup in the group header has been translated into "\n". I was able to replicate the problem and it went away after I changed the markup sequence. Download the latest version (2.0.13) and see if it fixes the problem. jr
Yep. It works! :) Thanks! Although this isn't a problem if the Header only contains the following code Toc didn't work. Again, this isn't a problem. Inserting a line between instructions solves the problem. <Header Start> (:toc:) <Header End> ~Jota Would it be possible to have the If you have the MarkupExtensions installed, put =>(:toc-back:) on a line by itself. This right aligns the paragraph and omits it from the printable view. jr
Thank you for your help. It works. Wonderfully useful recipe--thanks for sharing it! Is it possible to turn off the $TocFloat for a page? I have $TocFloat=TRUE in my config file, so I tried using a page customization file, setting $TocFloat=FALSE, for a page, but it's not being recognized for some reason. Is there a directive setting to do this? Best, Brent Brent, you need to include the $TocFloat=False statement before the include statement because of the way the css properties are set. David A Spitzley
Thanks, David. That explains it. Brent
TOC is in printable view as of the 20 Sep 2005 version. If the toc is numbered, the headings are also numbered. If you have the PublishPDF library installed, the toc gets page numbers in the pdf version.
Space after numbers wont show correctly. I had to replace " " with a normal (not html formated) space should be 2005-09-21
This will require a bit of code juggling to accomplish. In the mean time, an administrator could create local/Group.Page.php files to set the desired float characteristics on a per-page basis. The toc syntax will probably need to change so it can have a number of parameters in any order, for example like the pagelist directive.
I've tried local/<Group>.<Page>.php method, but it does not have any effect. Could you, please, verify it? Roman
<?php $TocFloat = false; ?>
You should be able to set $RemoteTocFmt = '<b>On page [[$Toc#toc |+ ]]...</b>'; to show the remote page's title. jr
For me it doesn't work but $RemoteTocFmt = '<b>[[$Toc |+ ]]...</b>'; is fine. nico
Roman
In order to translate via *.XLPage, all the texts in pagetoc.php should be enclosed by Good idea. At the moment, all text is in variables or controlled through the directive itself. I will investigate adding XLPage support.
21-Feb-2006 Christoph Claus How do I disable the At the moment, Show/Hide is, by popular request, a given. You want to be able to turn this off, so the toc is always displayed?
Yes please
!!Article 1\\ Name This shows up as expected in the table of contents during a preview, but only shows Article1\\ when browsed. Scott
KM Do the headings include %center% wiki styles? If so, the code will pick these up in the toc entry text. Any center and right styles are removed in version 2.0.31. jr
If I use toc-float, can I show the table of contents with the text on the left? The fastest way to achieve this is to change "float: right;" to "float: left;" in the definition of div.tocfloat. But we can probably make this a parameter...
-she Ensure the ToC in on the first line of the page. In your include include from the second line onwards.
Answer:
![]()
It would be very helpful if the pagetoc recipe supported suppression of the "In this page line". To change the default width follow the above instructions for customising your template. Then add the following to the skin's css file
div.tocfloat {
width: auto;
min-width: 12em;
maxwidth: 24em;
}
Des August 13, 2006, at 11:51 AM
Hi, I am trying to implement the new pagetoc2.php (which seems to be a real improvement) but I am getting numbering two times: 1. 1. A “Má Fama” da Monografia
2. 2. A Cultura do Processador de Textos
3. 3. Lógica da Edição de Textos
The problem happens both in Mozilla and IE. Unfortunately I cannot test with different skins because the site I am building is very customized and uses my homegrown, three-colum skin. I have succeded in removing the unwanted extra numbers using José Geraldo
Is it possible to have all headings displayed at the same level of indentation (ie none)?
Is it possible to specify the range of headings to be shown in the page toc, eg say I only want to display h2, h3, and h4?
Is it possible to have the toc also pick up included pages (pmwiki-2.2.0-beta15) (they are being included by a pagelist fmt variant). Alternatively can I use a wildcard, eg (:toc-page SomeGroup/*:)?
thanks Simon
Are there any plans to add the level=n feature ? http://thread.gmane.org/gmane.comp.web.wiki.pmwiki.user/29915/focus=29999 Francis
Two questions: 1. Is it possible to have the default view hidden, with only the "On this page...(show)" visible?
-can anyone explain this more? I would really like to add this customization. 2. Can someone please expand on the (:toc-page:) information? I am not clear on how to remove the table of contents for one page. In my case I do not want it visible on my homepage. Currently I have (:*toc:) in Site.Allgroupheader. Garth McMillan
Is it possible to generate table of contents entries to invisible headers, or alternatively, to list items? My page has this: ! section
I want the notes to be referred to in the toc so that readers can see their existence. However, I don't want to promote the list items to subsection headers since then they're typeset too large.
Thanks.
Is it possible to include the TOC in the skin's template file so that it will be visible on all pages? Thanks
This recipe isn't compatible with Creole headings. Would it be terribly difficult to fix that? -- JonHaupt November 13, 2007, at 05:04 PM
Right now this only displays two levels of headers (!! and !!!), no more. While I can understand wanting a cutoff, there are times that I'd really like to see at least one further level of hierarchy displayed; I write highly-structured documents, and sometimes that third level of depth is significant. (Also, better instructions in the "Discussion" section of this page on modifying the ToC display via CSS would be nice.) --CrazyDreamer see "Limitations" on this Page
I use this recipe in a german wiki and I have include some translations ($[On this page], $[hide], $[show] ...). No problems, except for the (:toc-page ...:)-directive. The output is $[show]. Does anybody know why?
I use this recipe along. I like the floating TOC. But it stops floating reaching a new section. I have to mention that we use section-edit, too. Can't the script float over sections using this recipe? kt007 March 11, 2008, at 12:06 PM I'm having the same problem. TOC, Section-edit, and the TriadSkin. Float works just fine in preview - TOC on the right, text on the left then below. But in regular view, TOC is on the right, and text is only below... OtherMichael June, 2008
I like this script very well. I search a possibility that the script shows a table of content like a line (A B C D E ...). Could anybody help me? Casio ---
There's a bug in the code that breaks the "view Source" function of the browser for large TOCs. The problem is that the HTML code for TOC is one long line, instead of having one line per TOC item. The solution:
D'de |
||||||||||||||||||||||||||||||||||||