1.1 --- a/moinformat/parsers/moin.py Mon Jul 16 19:19:31 2018 +0200
1.2 +++ b/moinformat/parsers/moin.py Tue Jul 17 19:19:59 2018 +0200
1.3 @@ -275,15 +275,30 @@
1.4
1.5 indent = len(self.match_group("indent"))
1.6 level = len(self.match_group("level"))
1.7 - self.add_node(region, self.parse_region(level, indent, "inline"))
1.8 - self.new_block(region)
1.9 +
1.10 + section = self.parse_region(level, indent, "inline")
1.11 +
1.12 + # If the section is inline, treat it like any other inline element.
1.13 +
1.14 + if section.type == "inline":
1.15 + region.append_inline(section)
1.16 +
1.17 + # Otherwise, add it as a new block element.
1.18 +
1.19 + else:
1.20 + self.add_node(region, section)
1.21 + if region.allow_blocks:
1.22 + self.new_block(region)
1.23
1.24 def parse_section_end(self, region):
1.25
1.26 "Handle the end of a new section within 'region'."
1.27
1.28 - feature = self.match_group("level")
1.29 - if region.have_end(feature):
1.30 + level = self.match_group("level")
1.31 + feature = self.match_group("feature")
1.32 + region.extra = self.match_group("extra")
1.33 +
1.34 + if region.have_end(level):
1.35 raise StopIteration
1.36 else:
1.37 region.append_inline(Text(feature))
1.38 @@ -317,6 +332,9 @@
1.39 # All nodes were valid: preserve the collection.
1.40
1.41 else:
1.42 + # Add the attributes as a node, also recording their presence.
1.43 +
1.44 + cell.append(attrs)
1.45 cell.attrs = attrs
1.46 return
1.47
1.48 @@ -354,8 +372,7 @@
1.49 if not row.nodes or not cell.empty():
1.50 for node in row.nodes:
1.51 region.append_inline(Text(serialise(node)))
1.52 - region.append_inline(Text(serialise(cell)))
1.53 - region.append_inline(Text(trailing))
1.54 + region.append_inline(Text(serialise(cell) + trailing))
1.55
1.56 self.new_block(region)
1.57 return
1.58 @@ -463,7 +480,10 @@
1.59 group("level", repeat("[{]", 3)))), # {{{...
1.60
1.61 "regionend" : join((r"\N*", # ws... (optional)
1.62 - group("level", repeat("[}]", 3)))), # }}}...
1.63 + group("feature", join((
1.64 + group("level", repeat("[}]", 3)), # }}}...
1.65 + group("extra", r"\n"),
1.66 + "?"))))), # nl (optional)
1.67
1.68 "header" : join(("#!", # #!
1.69 group("args", ".*?"), "\n")), # text-excl-nl