1.1 --- a/moinformat/parsers/moin.py Fri Jul 13 12:58:09 2018 +0200
1.2 +++ b/moinformat/parsers/moin.py Fri Jul 13 16:59:27 2018 +0200
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Moin wiki format parser.
1.6
1.7 -Copyright (C) 2017 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2017, 2018 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -212,31 +212,38 @@
1.13 marker = self.read_match(2)
1.14 space = self.read_match(3)
1.15
1.16 + last = region.node(-1)
1.17 + new_list = not isinstance(last, (List, ListItem))
1.18 +
1.19 + # If the marker is different or the indent is smaller, queue the item
1.20 + # and end the list.
1.21 +
1.22 + if not new_list and (last.marker != marker or indent < last.indent):
1.23 + self.queue_match()
1.24 + self.end_region(region)
1.25 +
1.26 + # Obtain a list item and populate it.
1.27 +
1.28 item = ListItem([], indent, marker, space)
1.29 self.parse_region_details(item, self.listitem_pattern_names)
1.30
1.31 - last = region.node(-1)
1.32 + # Start a new list if not preceded by a list item or if the indent is
1.33 + # greater.
1.34
1.35 - # Start a new list if not preceded by a list item.
1.36 -
1.37 - if not isinstance(last, ListItem):
1.38 + if new_list or indent > last.indent:
1.39 item = self.parse_list(item)
1.40
1.41 - # End the current list if the indent or marker is different from the
1.42 - # last list item.
1.43 + # Add a new or completed nested list.
1.44
1.45 - elif last.indent != indent or last.marker != marker:
1.46 -
1.47 - # Queue the new list, end this list, causing the new list to be
1.48 - # added after this one.
1.49 + self.add_node(region, item)
1.50
1.51 - self.queue_region(self.parse_list(item), region)
1.52 - self.end_region(region)
1.53 + if new_list:
1.54 + self.new_block(region)
1.55
1.56 - # Add a new item in a list or a completed nested list.
1.57 + # Add the item to the current list.
1.58
1.59 - self.add_node(region, item)
1.60 - self.new_block(region)
1.61 + else:
1.62 + self.add_node(region, item)
1.63
1.64 def parse_rule(self, region):
1.65