# HG changeset patch # User Paul Boddie # Date 1531863088 -7200 # Node ID 7df3759147017ecf6e75b36a61290079603f0e63 # Parent bcf9eb5f2fc5d690db8305bb6e88476d76fa1963# Parent fe4054485f21caba4ef3b73976e26a9273b688c9 Merged changes from the default branch. diff -r bcf9eb5f2fc5 -r 7df375914701 moinformat/parsers/common.py --- a/moinformat/parsers/common.py Tue Jul 17 19:31:41 2018 +0200 +++ b/moinformat/parsers/common.py Tue Jul 17 23:31:28 2018 +0200 @@ -345,12 +345,28 @@ self.set_region(items, region) - # Define a block to hold text and start parsing. + # Parse inline and opaque regions. + + if not region.transparent: + pattern_names = ["regionend"] + + # Define a block to hold text. + + else: + self.new_block(region) + pattern_names = self.region_pattern_names - self.new_block(region) + # Start parsing. + + if pattern_names: + self.parse_region_details(region, pattern_names) - if self.region_pattern_names: - self.parse_region_details(region, self.region_pattern_names) + # Reset the type if the region was not inline. + + if region.type == "inline": + first = region.nodes and region.nodes[0] + if first and isinstance(first, Text) and first.multiline(): + region.type = None # Top-level parser handler methods. @@ -376,23 +392,13 @@ Use configured parsers to parse 'region' based on its type. """ - # Handle potentially inline regions. - - if region.type == "inline": - self.parse_region_inline(region) - return - # Find an appropriate parser given the type. parser = self.get_parser(region.type) - - if parser: - parser.parse_region_content(self.items, region) - - # Otherwise, treat the section as opaque. - - else: - self.parse_region_opaque(region) + if not parser: + region.transparent = False + parser = parser or self.get_parser("moin") + parser.parse_region_content(self.items, region) def parse_region_header(self, region): @@ -403,27 +409,6 @@ if self.read_until(["header"], False) == "": # None means no header region.type = self.match_group("args") - def parse_region_opaque(self, region): - - "Parse the data to populate an opaque 'region'." - - region.transparent = False - self.parse_region_details(region, ["regionend"]) - - def parse_region_inline(self, region): - - "Parse the data to populate an inline 'region'." - - region.transparent = False - self.parse_region_details(region, ["regionend"]) - - # Reset the type if the region was not inline. - - if region.type == "inline": - first = region.nodes and region.nodes[0] - if first and isinstance(first, Text) and first.multiline(): - region.type = None - # Parsing utilities. def parse_region_details(self, region, pattern_names, strict=False): diff -r bcf9eb5f2fc5 -r 7df375914701 moinformat/parsers/table.py --- a/moinformat/parsers/table.py Tue Jul 17 19:31:41 2018 +0200 +++ b/moinformat/parsers/table.py Tue Jul 17 23:31:28 2018 +0200 @@ -22,7 +22,8 @@ from moinformat.parsers.common import get_patterns, \ excl, expect, group from moinformat.parsers.moin import MoinParser -from moinformat.tree import Table, TableAttrs, TableCell, TableRow, Text +from moinformat.tree import Continuation, Table, TableAttrs, TableCell, \ + TableRow, Text join = "".join @@ -73,7 +74,11 @@ # Parser handler methods. def parse_continuation(self, cell): - pass + + "Handle continuation padding." + + feature = self.match_group("feature") + cell.append(Continuation(feature)) def parse_table_end(self, cell): @@ -99,17 +104,16 @@ excl(r".*==\s*?$"), # not-heading expect(r"\N*?"))), # ws-excl-nl - "continuation" : join(("^", + "continuation" : group("feature", + join(("^", group("indent", r"\N*"), # ws... (optional) r"\.\.", # .. - excl(r"\."), # not-. - expect(r"\N"))), # ws + excl(r"\.")))), # not-. # Within text: "columnsep" : join((r"\|\|", # || - excl(r"\|"), # not-| - expect(r"\N"))), # ws + excl(r"\|"))), # not-| }) patterns = get_patterns(syntax) @@ -118,9 +122,9 @@ # Pattern details. - table_region_pattern_names = MoinParser.region_without_table_pattern_names + [ + table_region_pattern_names = [ "columnsep", "continuation", "rowsep", - ] + ] + MoinParser.region_without_table_pattern_names diff -r bcf9eb5f2fc5 -r 7df375914701 moinformat/serialisers/html.py --- a/moinformat/serialisers/html.py Tue Jul 17 19:31:41 2018 +0200 +++ b/moinformat/serialisers/html.py Tue Jul 17 23:31:28 2018 +0200 @@ -211,6 +211,9 @@ def break_(self): pass + def continuation(self, text): + pass + def rule(self, length): self.out("
" % min(length, 10)) diff -r bcf9eb5f2fc5 -r 7df375914701 moinformat/serialisers/moin.py --- a/moinformat/serialisers/moin.py Tue Jul 17 19:31:41 2018 +0200 +++ b/moinformat/serialisers/moin.py Tue Jul 17 23:31:28 2018 +0200 @@ -172,6 +172,9 @@ def break_(self): self.out("\n") + def continuation(self, text): + self.out(text) + def rule(self, length): self.out("-" * length) diff -r bcf9eb5f2fc5 -r 7df375914701 moinformat/tree.py --- a/moinformat/tree.py Tue Jul 17 19:31:41 2018 +0200 +++ b/moinformat/tree.py Tue Jul 17 23:31:28 2018 +0200 @@ -151,6 +151,8 @@ +# Block nodes. + class Block(Container): "A block in the page." @@ -400,6 +402,8 @@ +# Inline nodes. + class Inline(Container): "Generic inline formatting." @@ -499,6 +503,8 @@ +# Nodes without children. + class Node: "A document node without children." @@ -519,6 +525,22 @@ def to_string(self, out): out.break_() +class Continuation(Node): + + "Continuation padding for table content." + + def __init__(self, text): + self.text = text + + def __repr__(self): + return "Continuation(%r)" % self.text + + def prettyprint(self, indent=""): + return "%sContinuation: %r" % (indent, self.text) + + def to_string(self, out): + out.continuation(self.text) + class Rule(Node): "A horizontal rule." diff -r bcf9eb5f2fc5 -r 7df375914701 tests/test_continuation.tree --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_continuation.tree Tue Jul 17 23:31:28 2018 +0200 @@ -0,0 +1,27 @@ +Region + Region + Table + TableRow + TableCell + FontStyle + Text + Text + TableCell + Text + FontStyle + Text + Text + TableRow + TableCell + Text + TableCell + Text + Link + Text + Text + Continuation + Text + Link + Text + Text + Block diff -r bcf9eb5f2fc5 -r 7df375914701 tests/test_continuation.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_continuation.txt Tue Jul 17 23:31:28 2018 +0200 @@ -0,0 +1,6 @@ +{{{#!table +'''Release''' || '''Details''' +== +0.1 || [[http://hgweb.boddie.org.uk/Lichen/rev/rel-0-1|changeset]] + .. [[http://hgweb.boddie.org.uk/Lichen/file/rel-0-1|files]] +}}}