changeset 3803:5afc0a9e3fc3

TOC: skip outer-most <ol> levels when page isn't using the biggest headings
author Johannes Berg <johannes AT sipsolutions DOT net>
date Wed, 25 Jun 2008 21:01:58 +0200
parents c62beb39c64c
children 6f3dbd8430db
files MoinMoin/macro/TableOfContents.py
diffstat 1 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/macro/TableOfContents.py	Tue Jun 24 11:52:01 2008 +0200
+++ b/MoinMoin/macro/TableOfContents.py	Wed Jun 25 21:01:58 2008 +0200
@@ -163,7 +163,21 @@
         macro.formatter.paragraph(0),
     ]
 
-    lastlvl = 0
+
+    # find smallest used level and use that as the outer-most indentation,
+    # to fix pages like HelpOnMacros that only use h2 and lower levels.
+    lastlvl = 100
+    for lvl, id, txt in macro.request._tocfm_collected_headings:
+        if txt is None:
+            incl_id = id
+            continue
+        if lvl > maxdepth or id is None:
+            continue
+        if lvl < lastlvl:
+            lastlvl = lvl
+
+    # headings are 1-based, lastlvl needs to be one less so that one is closed
+    lastlvl -= 1
 
     for lvl, id, txt in macro.request._tocfm_collected_headings:
         if txt is None: