Patch #1857

Make {{toc}} render as properly nested list + skip support

Added by Jim Jones about 9 years ago. Updated almost 7 years ago.

Status:NewStart date:2008-09-04
Priority:NormalDue date:
Assignee:-% Done:

50%

Category:Wiki
Target version:-

Description

The attached patch changes the {{toc}}-macro to render as a properly nested HTML unordered list.
Furthermore it adds a parameter to skip the first n headlines, because at least the first one is usually not interesting:

Example: {{toc:1}} skips the first headline. {{toc:3}} skips the first three headlines.

The patch also removes the (now superflous) css indentation rules for the <li> elements.

redmine_wiki_toc.patch Magnifier (2.07 KB) Jim Jones, 2008-09-04 16:34

Associated revisions

Revision 4377
Added by Jean-Philippe Lang almost 7 years ago

Render TOC as nested lists (#1857).

History

#1 Updated by Jean-Philippe Lang about 9 years ago

This patch produces invalid HTML when h1 > h2 > h3 hierarchy is not strictly respected.

Example:

h1. Heading 1

h3. Heading 3

produces non-matching closing tags:

<ul class="toc">
  <li class="heading1">
    <a href="#Heading-1">Heading 1</a>
  </li>
  <li>
    <ul>
      <li class="heading3"><a href="#Heading-3">Heading 3</a></li>
    </ul>
  </li>
</ul>
</li>
</ul>

#2 Updated by Jim Jones about 9 years ago

Sorry, no time to work on a patch right now.
Please try to replace line 107-113 (after applying the old patch) with this:

if level > lastlevel
  i = level
  while i > lastlevel
      out << "<li><ul>" 
      i-=1
  end
end

if level < lastlevel 
  while i < lastlevel
      out << "</ul></li>" 
      i+=1
  end
end

That should create valid HTML even in the face of invalid nesting, I think.

#3 Updated by Jean-Philippe Lang almost 7 years ago

  • % Done changed from 0 to 50

TOC is now rendered as nested lists (r4377).

Also available in: Atom PDF