create new tag
, view all tags

Bug: TOC generated HTML is not closed

The HTML tags that are generated by TOC do not close properly.

Test case


TWiki version: TWikiRelease01Feb2003
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS: Any
Web server:  
Perl version:  
Client OS: Any
Web Browser: Any

-- ArthurClemens - 28 Aug 2003

Follow up

The problem lies in the routine handleToc that leaves the list open ended (tags not closed). Closing of tags is postponed to the routine getRenderedVersion that calls routine emitList to finish it off. In the meantime the closing </div> is already placed after the last toc entry, as you can see in the example above.

Fix record

I've added an extra line to handleToc that calls emitList itself, just before it returns. I tested this with various TOCs and it seems to behave correctly. See patch file. Update: see Peter's patch below.

I get this result now with the same topic as above:

<div class='toc'>
<li> <a href="/twiki/bin/view/Sandbox/TestTopic4#Level_1">Level 1</a>
<li> <a href="/twiki/bin/view/Sandbox/TestTopic4#Level_2">Level 2</a>
<li> <a href="/twiki/bin/view/Sandbox/TestTopic4#Level_1_2">Level 1 - 2</a>
<li> <a href="/twiki/bin/view/Sandbox/TestTopic4#Level_2_2">Level 2 - 2</a>
<li> <a href="/twiki/bin/view/Sandbox/TestTopic4#Level_3">Level 3</a>

NOTE: it would be useful to have the <div class='twikitoc'> tags spawned in the handleToc routine, so a style sheet can address the toc. Or you would need to remember to put around every TOC the <div class='toc'> and </div> tags, what is error prone.

-- ArthurClemens - 13 Sep 2003

The proposed fix has a problem. TOC is a variable and should only expand the variable into TWikiML, e.g. into TWiki bullets. The emitList call is part of the rendering, not variable expansion.

There is an easy fix, simply add a new line after the TOC's bullets, that will end the bullet list properly.

I added the <div class="twikitoc"> ... <div> tags, sounds like a useful enhancement.

Both changes are in TWikiAlphaRelease.


Index: TWiki.pm
RCS file: /cvsroot/twiki/twiki/lib/TWiki.pm,v
retrieving revision 1.236
retrieving revision 1.237
diff -C2 -r1.236 -r1.237
*** TWiki.pm    12 Sep 2003 06:17:14 -0000      1.236
--- TWiki.pm    14 Sep 2003 07:20:51 -0000      1.237
*** 116,120 ****
  # ===========================
  # TWiki version:
! $wikiversion      = "11 Sep 2003";
  # ===========================
--- 116,120 ----
  # ===========================
  # TWiki version:
! $wikiversion      = "14 Sep 2003";
  # ===========================
*** 1691,1694 ****
--- 1691,1695 ----
                  # cut TOC exclude '---+ heading !! exclude'
                  $line  =~ s/\s*$headerPatternNoTOC.+$//go;
+                 $line  =~ s/[\n\r]//go;
                  next unless $line;
                  $highest = $level if( $level < $highest );
*** 1718,1721 ****
--- 1719,1723 ----
              $result =~ s/^\t{$highest}//gm;
+         $result = "<div class='twikitoc'>$result\n</div>";
          return $result;

-- PeterThoeny - 14 Sep 2003

Works fine! I've been playing with targetting the twikitoc class in a style sheet, and I would like to propose one small change to the last line.

Moved to AddHeadingToToc. -- ArthurClemens - 22 Sep 2003

Category: TWikiPatches
Topic attachments
I Attachment History Action Size Date Who Comment
Unknown file formatdiff ProperlyClosedTOC.diff r1 manage 0.3 K 2003-09-13 - 23:09 ArthurClemens Patch file to properly close the TOC
Edit | Attach | Watch | Print version | History: r11 < r10 < r9 < r8 < r7 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r11 - 2004-08-20 - ArthurClemens
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2015 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.