Przeglądaj źródła

Fix TOC for pages with no h2 tag

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@59815 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 11 lat temu
rodzic
commit
117a154ad8
1 zmienionych plików z 8 dodań i 5 usunięć
  1. 8 5
      tools/mkhtml.py

+ 8 - 5
tools/mkhtml.py

@@ -125,20 +125,23 @@ def write_toc(data):
     fd.write('<div class="toc">\n')
     fd.write('<ul class="toc">\n')
     first = True
+    has_h2 = False
     in_h3 = False
     indent = 4
     for tag, href, text in data:
-        if tag == 'h3' and not in_h3:
+        if tag == 'h3' and not in_h3 and has_h2:
             fd.write('\n%s<ul class="toc">\n' % (' ' * indent))
             indent += 4
             in_h3 = True
         elif not first:
             fd.write('</li>\n')
             
-        if tag == 'h2' and in_h3:
-            indent -= 4
-            fd.write('%s</ul></li>\n' % (' ' * indent))
-            in_h3 = False
+        if tag == 'h2':
+            has_h2 = True
+            if in_h3:
+                indent -= 4
+                fd.write('%s</ul></li>\n' % (' ' * indent))
+                in_h3 = False
         
         fd.write('%s<li class="toc"><a href="#%s" class="toc">%s</a>' % \
                      (' ' * indent, href, text))