# HG changeset patch # User Paul Boddie # Date 1532774962 -7200 # Node ID bf23f3f334c9ca39bdd498621cb0b7a39a17b13c # Parent d3fb25874a0a8e7a3eb9a2797f78ff543be548ae Tidied slightly, moving the general region end handler into the base class, also retaining the use of the same pattern name attribute for region parsing in the table parser (for clarity). diff -r d3fb25874a0a -r bf23f3f334c9 moinformat/parsers/common.py --- a/moinformat/parsers/common.py Thu Jul 26 20:42:37 2018 +0200 +++ b/moinformat/parsers/common.py Sat Jul 28 12:49:22 2018 +0200 @@ -441,4 +441,19 @@ self.add_node(region, Block([])) + # Common handler methods. + + def parse_region_end(self, node): + + "Handle the end of a region occurring within 'node'." + + level = self.match_group("level") + feature = self.match_group("feature") + self.region.extra = self.match_group("extra") + + if self.region.have_end(level): + raise StopIteration + else: + node.append_inline(Text(feature)) + # vim: tabstop=4 expandtab shiftwidth=4 diff -r d3fb25874a0a -r bf23f3f334c9 moinformat/parsers/moin.py --- a/moinformat/parsers/moin.py Thu Jul 26 20:42:37 2018 +0200 +++ b/moinformat/parsers/moin.py Sat Jul 28 12:49:22 2018 +0200 @@ -330,19 +330,6 @@ if region.allow_blocks: self.new_block(region) - def parse_section_end(self, region): - - "Handle the end of a new section within 'region'." - - level = self.match_group("level") - feature = self.match_group("feature") - region.extra = self.match_group("extra") - - if region.have_end(level): - raise StopIteration - else: - region.append_inline(Text(feature)) - def parse_table_attrs(self, cell): "Handle the start of table attributes within 'cell'." @@ -448,6 +435,13 @@ + def inline_patterns_for(self, name): + names = self.inline_pattern_names[:] + names[names.index(name)] = "%send" % name + return names + + + # Inline formatting handlers. def parse_inline(self, region, cls, pattern_name): @@ -719,22 +713,21 @@ "regionend", "rule", ] - region_pattern_names = region_without_table_pattern_names + ["tablerow"] - table_region_pattern_names = inline_pattern_names + [ "tableattrs", "tablecell", "tableend" ] - def inline_patterns_for(self, name): - names = self.inline_pattern_names[:] - names[names.index(name)] = "%send" % name - return names + # The region pattern names are specifically used by the common parser + # functionality. + + region_pattern_names = region_without_table_pattern_names + ["tablerow"] # Pattern handlers. end_region = ParserBase.end_region + parse_section_end = ParserBase.parse_region_end handlers = { None : end_region, diff -r d3fb25874a0a -r bf23f3f334c9 moinformat/parsers/table.py --- a/moinformat/parsers/table.py Thu Jul 26 20:42:37 2018 +0200 +++ b/moinformat/parsers/table.py Sat Jul 28 12:49:22 2018 +0200 @@ -37,12 +37,13 @@ def parse_region_content(self, items, region): - "Parse the data provided by 'items' to populate the given 'region'." + """ + Parse the data provided by 'items' to populate the given 'region'. For + table regions, normal region handling is wrapped by management of the + table structure. + """ self.set_region(items, region) - self.parse_table_region() - - def parse_table_region(self): # Start to populate table rows. @@ -52,7 +53,7 @@ self.append_node(self.region, table) while True: - self.parse_region_details(cell, self.table_region_pattern_names) + self.parse_region_details(cell, self.region_pattern_names) # Detect the end of the table. @@ -80,18 +81,7 @@ feature = self.match_group("feature") cell.append(Continuation(feature)) - def parse_table_end(self, cell): - "Handle the end of a region within 'cell'." - - level = self.match_group("level") - feature = self.match_group("feature") - self.region.extra = self.match_group("extra") - - if self.region.have_end(level): - raise StopIteration - else: - cell.append_inline(Text(feature)) # Regular expressions. @@ -122,7 +112,7 @@ # Pattern details. - table_region_pattern_names = [ + region_pattern_names = [ "columnsep", "continuation", "rowsep", ] + MoinParser.region_without_table_pattern_names @@ -130,12 +120,15 @@ # Pattern handlers. + end_region = MoinParser.end_region + parse_table_end = MoinParser.parse_region_end + handlers = {} handlers.update(MoinParser.handlers) handlers.update({ - "columnsep" : MoinParser.end_region, + "columnsep" : end_region, "continuation" : parse_continuation, - "rowsep" : MoinParser.end_region, + "rowsep" : end_region, "regionend" : parse_table_end, }) diff -r d3fb25874a0a -r bf23f3f334c9 moinformat/serialisers/html/moin.py --- a/moinformat/serialisers/html/moin.py Thu Jul 26 20:42:37 2018 +0200 +++ b/moinformat/serialisers/html/moin.py Sat Jul 28 12:49:22 2018 +0200 @@ -41,8 +41,12 @@ return "span" def start_region(self, level, indent, type, extra): + + # Generate attributes, joining them when preparing the tag. + l = [] out = l.append + if level: out("level-%d" % level)