This plugin generates a table of contents for a page by using the !!!headings as the content entries.

Version 2.1.111 and above.#

A JSP Wiki Core Plugins in all versions 2.1.111 and above.

Parameters#

title
The title that is used for the TOC. Default is "Table of Contents"
numbered
If true, generates automatically numbers for the headings.
start
If using a numbered list, sets the start number.
prefix
If using a numbered list, sets the prefix used for the list.

Example#

[{TableOfContents}]
[{TableOfContents title='Page contents' numbered='true' prefix='Chap. '}]

Discussion#

This plugin is not strictly required, the BrushedTemplate shows how to get a table of contents built using CSS and javascript on the client side. JohnV chooses to use the CSS/javascript approach because the way this plugin scrounges thru the wikitext each time it is invoked offends my sense of preformance, I mean the plugin is instantiated on each page view and slurps thru the String of wikitext to generate a new String to concatenate, ick ack ook. The CSS and javascript might not work with all browsers, but it is known to work with IE and firefox, so I'm satisfied with it.

The BrushedTemplate scripting also insert a back to top link after each header, which is usefull especially on longer pages - where you probably need a toc. This is harder to achieve through a server side plugin. --DF

The performance can be improved through caching. It's just the first iteration. --JanneJalkanen

The downside of the CSS/JavaScript solution is that not only is content of the page changed when a user either has JavaScript turned off or is unavailable, but it's navigational content that ends up missing. I realize that programmers (i.e., the kind of people who design wiki and wiki features) probably always have JavaScript turned on, but it seems like a huge concession to accessibility and interoperability to make for what doesn't seem like a significant performance issue. Yes, the engine must parse the page, but there's a lot of servers that autogenerate pages on database lookups for each request, so this seems (by comparison) much less. -- MurrayAltheim

---

I think it would be useful to have an option that specifies the maximum level of content depth. Right now, it seems to be three, but there is no way to change it.

--AnonymousCoward, 09-Jan-2006 +1 - Subheadings are a pain in the neck on big pages -- Kwhit


It would be very nice if the ToC indented the entries based on the header level and, yes if you could specify the header depth you wanted to include.

--Carl Borgstrom, 03-May-2006


A careless user can edit any page to have

![{TableOfContents}]


This causes the page plugin to recursively loop through the page until it eats up the entire memory heap and causes the server to dump.

Any way to fix this so a careless user can't bring down the entire wiki Server?

-CJackson0

Hi!

This is fixed in the current CVS...

-- JanneJalkanen

Can we set a param to use numbered lists instead of unordered lists - it is currently hardcoded in the TableOfContents

--D Bacci, 2nd Feb 2006

Yes, there's a param: "numbered" for just that.

-- JanneJalkanen

What value do I need to supply to the numbered attribute? I have tried 'true', 'yes', 1. None worked.

--MarcelDullaart, 04-Apr-2006

The "numbered" is available in 2.3 onwards...

-- JanneJalkanen

--JérômeDuprez Can you give an example (along with other attributes the plugin might support too)? I've tried it on 2.4.0 with no luck. Even on this site (JSPWiki v2.4.2-cvs as of today, says the footer )

--MatthiasOpitz Is it possible to get a toc for another page by giving the other pagename as a parameter?


Table Of Contents bites with FCKedior. In normal text mode I cannot set !!!, in plain text mode it is no comfortable working with FCKeditor's html code. Does someone have a solution?

--AnonymousCoward, 30-Aug-2006


Diggin' the ToC! Is there a way to default the ToC to be collapsed instead of expanded?

--GrasshopperQ, 09-Mar-2007


This plugin does not scan the headings of included pages. Sad, as this prevents my Idea of having a (long) printable version of all my wiki pages.

--Al, 20-Apr-2007


When will the bug/feature added, that inserted pages are also scanned to create the TOC? Inserting pages and using TOC by now is some kind of useless.

--Matthias, 23-Aug-2007


Not very soon. It's a very complicated thing to do correctly.

--JanneJalkanen, 24-Aug-2007


Doesn't recognize Creole headings (==. ===, etc.)

--StephenBlack, 10-Dec-2007


The plugin documentation or example should make it clear that the TOC is built up by looking for headings that start with an exclamation mark:

!!!large heading
!!medium heading 1
!small heading
!!medium heading 2

--Chris Clauss, 19-Aug-2008


Second the option to indent the entries based on the header level; indent=true|false (default is false, I guess, for backward compatibility)


Would be nice to have a way of ignoring first level headings so the heading at the top of the page isn't included.

-- Sam Hasler 18-Aug-2010

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-70) was last changed on 18-Aug-2010 11:05 by 91.84.38.65