Bug: TOC generated HTML is not closed
The
HTML tags that are generated by TOC do not close properly.
Test case
Environment
--
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'>
<ul>
<li> <a href="/twiki/bin/view/Sandbox/TestTopic4#Level_1">Level 1</a>
<ul>
<li> <a href="/twiki/bin/view/Sandbox/TestTopic4#Level_2">Level 2</a>
</li>
</ul>
</li>
<li> <a href="/twiki/bin/view/Sandbox/TestTopic4#Level_1_2">Level 1 - 2</a>
<ul>
<li> <a href="/twiki/bin/view/Sandbox/TestTopic4#Level_2_2">Level 2 - 2</a>
<ul>
<li> <a href="/twiki/bin/view/Sandbox/TestTopic4#Level_3">Level 3</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
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.
Patch:
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