Commits

Luke Plant committed 7854c39

Improved support for showing the indentation level of documents that don't start with a H1 or any headings

  • Participants
  • Parent commits e0319ee

Comments (0)

Files changed (1)

File semanticeditor/utils/presentation.py

     heading_names = set()
     cur_level = 1
     last_heading_num = 0
-    first_heading_level = 0
+    first_heading_level = 1
     for n in root.getiterator():
         if n.tag in blockdef:
             text = flatten(n)
                     name = _find_next_available_name(name, names)
                 # Paragraphs etc within a section should be indented
                 # one further than the heading above them.
-                level = cur_level + 1
+                if len(heading_names) == 0:
+                    level = 1
+                else:
+                    level = cur_level + 1
             names.add(name)
-            retval.append((level, name, n.tag.upper(), n))
+            # Level is adjusted so that e.g. H3 is level 1, if it is
+            # the first to appear in the document.
+            retval.append((level - first_heading_level + 1, name, n.tag.upper(), n))
 
     return retval