1.1 --- a/moinformat/parsers/common.py Thu Jul 26 20:42:37 2018 +0200
1.2 +++ b/moinformat/parsers/common.py Sat Jul 28 12:49:22 2018 +0200
1.3 @@ -441,4 +441,19 @@
1.4
1.5 self.add_node(region, Block([]))
1.6
1.7 + # Common handler methods.
1.8 +
1.9 + def parse_region_end(self, node):
1.10 +
1.11 + "Handle the end of a region occurring within 'node'."
1.12 +
1.13 + level = self.match_group("level")
1.14 + feature = self.match_group("feature")
1.15 + self.region.extra = self.match_group("extra")
1.16 +
1.17 + if self.region.have_end(level):
1.18 + raise StopIteration
1.19 + else:
1.20 + node.append_inline(Text(feature))
1.21 +
1.22 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/moinformat/parsers/moin.py Thu Jul 26 20:42:37 2018 +0200
2.2 +++ b/moinformat/parsers/moin.py Sat Jul 28 12:49:22 2018 +0200
2.3 @@ -330,19 +330,6 @@
2.4 if region.allow_blocks:
2.5 self.new_block(region)
2.6
2.7 - def parse_section_end(self, region):
2.8 -
2.9 - "Handle the end of a new section within 'region'."
2.10 -
2.11 - level = self.match_group("level")
2.12 - feature = self.match_group("feature")
2.13 - region.extra = self.match_group("extra")
2.14 -
2.15 - if region.have_end(level):
2.16 - raise StopIteration
2.17 - else:
2.18 - region.append_inline(Text(feature))
2.19 -
2.20 def parse_table_attrs(self, cell):
2.21
2.22 "Handle the start of table attributes within 'cell'."
2.23 @@ -448,6 +435,13 @@
2.24
2.25
2.26
2.27 + def inline_patterns_for(self, name):
2.28 + names = self.inline_pattern_names[:]
2.29 + names[names.index(name)] = "%send" % name
2.30 + return names
2.31 +
2.32 +
2.33 +
2.34 # Inline formatting handlers.
2.35
2.36 def parse_inline(self, region, cls, pattern_name):
2.37 @@ -719,22 +713,21 @@
2.38 "regionend", "rule",
2.39 ]
2.40
2.41 - region_pattern_names = region_without_table_pattern_names + ["tablerow"]
2.42 -
2.43 table_region_pattern_names = inline_pattern_names + [
2.44 "tableattrs", "tablecell", "tableend"
2.45 ]
2.46
2.47 - def inline_patterns_for(self, name):
2.48 - names = self.inline_pattern_names[:]
2.49 - names[names.index(name)] = "%send" % name
2.50 - return names
2.51 + # The region pattern names are specifically used by the common parser
2.52 + # functionality.
2.53 +
2.54 + region_pattern_names = region_without_table_pattern_names + ["tablerow"]
2.55
2.56
2.57
2.58 # Pattern handlers.
2.59
2.60 end_region = ParserBase.end_region
2.61 + parse_section_end = ParserBase.parse_region_end
2.62
2.63 handlers = {
2.64 None : end_region,
3.1 --- a/moinformat/parsers/table.py Thu Jul 26 20:42:37 2018 +0200
3.2 +++ b/moinformat/parsers/table.py Sat Jul 28 12:49:22 2018 +0200
3.3 @@ -37,12 +37,13 @@
3.4
3.5 def parse_region_content(self, items, region):
3.6
3.7 - "Parse the data provided by 'items' to populate the given 'region'."
3.8 + """
3.9 + Parse the data provided by 'items' to populate the given 'region'. For
3.10 + table regions, normal region handling is wrapped by management of the
3.11 + table structure.
3.12 + """
3.13
3.14 self.set_region(items, region)
3.15 - self.parse_table_region()
3.16 -
3.17 - def parse_table_region(self):
3.18
3.19 # Start to populate table rows.
3.20
3.21 @@ -52,7 +53,7 @@
3.22 self.append_node(self.region, table)
3.23
3.24 while True:
3.25 - self.parse_region_details(cell, self.table_region_pattern_names)
3.26 + self.parse_region_details(cell, self.region_pattern_names)
3.27
3.28 # Detect the end of the table.
3.29
3.30 @@ -80,18 +81,7 @@
3.31 feature = self.match_group("feature")
3.32 cell.append(Continuation(feature))
3.33
3.34 - def parse_table_end(self, cell):
3.35
3.36 - "Handle the end of a region within 'cell'."
3.37 -
3.38 - level = self.match_group("level")
3.39 - feature = self.match_group("feature")
3.40 - self.region.extra = self.match_group("extra")
3.41 -
3.42 - if self.region.have_end(level):
3.43 - raise StopIteration
3.44 - else:
3.45 - cell.append_inline(Text(feature))
3.46
3.47 # Regular expressions.
3.48
3.49 @@ -122,7 +112,7 @@
3.50
3.51 # Pattern details.
3.52
3.53 - table_region_pattern_names = [
3.54 + region_pattern_names = [
3.55 "columnsep", "continuation", "rowsep",
3.56 ] + MoinParser.region_without_table_pattern_names
3.57
3.58 @@ -130,12 +120,15 @@
3.59
3.60 # Pattern handlers.
3.61
3.62 + end_region = MoinParser.end_region
3.63 + parse_table_end = MoinParser.parse_region_end
3.64 +
3.65 handlers = {}
3.66 handlers.update(MoinParser.handlers)
3.67 handlers.update({
3.68 - "columnsep" : MoinParser.end_region,
3.69 + "columnsep" : end_region,
3.70 "continuation" : parse_continuation,
3.71 - "rowsep" : MoinParser.end_region,
3.72 + "rowsep" : end_region,
3.73 "regionend" : parse_table_end,
3.74 })
3.75
4.1 --- a/moinformat/serialisers/html/moin.py Thu Jul 26 20:42:37 2018 +0200
4.2 +++ b/moinformat/serialisers/html/moin.py Sat Jul 28 12:49:22 2018 +0200
4.3 @@ -41,8 +41,12 @@
4.4 return "span"
4.5
4.6 def start_region(self, level, indent, type, extra):
4.7 +
4.8 + # Generate attributes, joining them when preparing the tag.
4.9 +
4.10 l = []
4.11 out = l.append
4.12 +
4.13 if level:
4.14 out("level-%d" % level)
4.15