# HG changeset patch # User Paul Boddie # Date 1533130540 -7200 # Node ID 8874a2ac2c6dae1a1763d297cf01285b7a0cb898 # Parent 413a230ce132de4a5501b96494d8b0c465c61511 Fixed tables of contents where headings appear at more significant levels (with lower level values) than the minimum level, potentially interrupting the occurrence of relevant headings. diff -r 413a230ce132 -r 8874a2ac2c6d moinformat/macros/toc.py --- a/moinformat/macros/toc.py Wed Aug 01 15:07:14 2018 +0200 +++ b/moinformat/macros/toc.py Wed Aug 01 15:35:40 2018 +0200 @@ -80,30 +80,46 @@ while level < new_level: level += 1 + # Ignore levels outside the range of interest. + if not (min_level <= level <= max_level): continue # Determine whether the heading should be generated at this - # level. + # level or whether there are intermediate levels being + # produced. nodes = level == new_level and heading.nodes[:] + nl or [] indent = level - 1 - # Make a list and add an item to it. + # Create a new item for the heading or sublists. + + new_item = ListItem(nodes, indent, marker, space, None) + + # Either revive an existing list. - new_items = [] - new_list = List(new_items, indent, marker, num) - new_item = ListItem(nodes, indent, marker, space, None) - new_items.append(new_item) + if level == min_level and lists: + new_list = lists[-1] + new_items = new_list.nodes + + # Or make a list and add an item to it. - # Add the list to the current item, if any. + else: + new_items = [] + new_list = List(new_items, indent, marker, num) + + # Add the list to the current item, if any. - if item: - item.nodes.append(new_list) + if item: + item.nodes.append(new_list) + + # Record the new list. - # Record the new list. + lists.append(new_list) - lists.append(new_list) + # Add the item to the new or revived list. + + new_items.append(new_item) # Reference the new list's items and current item. @@ -115,8 +131,12 @@ if new_level < level: while level > new_level: - if min_level <= level <= max_level: + + # Retain a list at the minimum level. + + if min_level < level <= max_level: lists.pop() + level -= 1 # Obtain the existing list and the current item. @@ -136,7 +156,7 @@ # Replace the macro node's children with the top-level list. # The macro cannot be replaced because it will be appearing inline. - self.node.nodes = [lists[0]] + self.node.nodes = lists and [lists[0]] or [] def find_headings(self, node, headings):