# HG changeset patch # User Paul Boddie # Date 1633732441 -7200 # Node ID 8a1de3e6b7ef9c2b42f994d3611eac922c10ec52 # Parent e71317bede9b3d32c09074cccca56ec01c42a5fc Incorporate whitespace into table parser features to avoid spurious line breaks being introduced, although any initial blank lines in a region will still cause breaks to appear at that point. diff -r e71317bede9b -r 8a1de3e6b7ef moinformat/parsers/table.py --- a/moinformat/parsers/table.py Wed Oct 06 00:16:28 2021 +0200 +++ b/moinformat/parsers/table.py Sat Oct 09 00:34:01 2021 +0200 @@ -65,11 +65,13 @@ break elif pattern == "columnsep": - cell = TableCell([]) + cell = TableCell([], leading=self.match_group("leading"), + padding=self.match_group("padding")) row.append(cell) elif pattern == "rowsep": - row = TableRow([]) + row = TableRow([], leading=self.match_group("leading"), + padding=self.match_group("padding")) table.append(row) cell = TableCell([]) row.append(cell) @@ -92,20 +94,25 @@ syntax.update({ # At start of line: - "rowsep" : join(("^==", # == + "rowsep" : join((group("leading", r"\s*"), # ws... (optional) + "^==", # == excl(r".*==\s*?$"), # not-heading - expect(r"\N*?"))), # ws-excl-nl + group("padding", r"\s*"))), # ws... (optional) "continuation" : group("feature", - join(("^", - group("indent", r"\N*"), # ws... (optional) + join((group("leading", r"\s*"), # ws... (optional) + "^", + group("indent", r"\s*"), # ws... (optional) r"\.\.", # .. - excl(r"\.")))), # not-. + excl(r"\."), # not-. + group("padding", r"\s*")))),# ws... (optional) # Within text: - "columnsep" : join((r"\|\|", # || - excl(r"\|"))), # not-| + "columnsep" : join((group("leading", r"\s*"), # ws... (optional) + r"\|\|", # || + excl(r"\|"), # not-| + group("padding", r"\s*"))), # ws... (optional) }) patterns = get_patterns(syntax) diff -r e71317bede9b -r 8a1de3e6b7ef moinformat/serialisers/html/moin.py --- a/moinformat/serialisers/html/moin.py Wed Oct 06 00:16:28 2021 +0200 +++ b/moinformat/serialisers/html/moin.py Sat Oct 09 00:34:01 2021 +0200 @@ -221,7 +221,7 @@ def end_table_attrs(self): pass - def start_table_cell(self, attrs): + def start_table_cell(self, attrs, leading, padding): self.out("") - def start_table_row(self): + def start_table_row(self, leading, padding): self.out("") def end_table_row(self, trailing): diff -r e71317bede9b -r 8a1de3e6b7ef moinformat/serialisers/moin/moin.py --- a/moinformat/serialisers/moin/moin.py Wed Oct 06 00:16:28 2021 +0200 +++ b/moinformat/serialisers/moin/moin.py Sat Oct 09 00:34:01 2021 +0200 @@ -149,13 +149,13 @@ def end_table_attrs(self): self.out(">") - def start_table_cell(self, attrs): + def start_table_cell(self, attrs, leading, padding): self.out("||") def end_table_cell(self): pass - def start_table_row(self): + def start_table_row(self, leading, padding): pass def end_table_row(self, trailing): diff -r e71317bede9b -r 8a1de3e6b7ef moinformat/serialisers/moin/table.py --- a/moinformat/serialisers/moin/table.py Wed Oct 06 00:16:28 2021 +0200 +++ b/moinformat/serialisers/moin/table.py Sat Oct 09 00:34:01 2021 +0200 @@ -34,16 +34,20 @@ def start_table(self): self.first_row = True - def start_table_cell(self, attrs): + def start_table_cell(self, attrs, leading, padding): if not self.first_cell: + self.out(leading) self.out("||") + self.out(padding) else: self.first_cell = False - def start_table_row(self): + def start_table_row(self, leading, padding): self.first_cell = True if not self.first_row: + self.out(leading) self.out("==") + self.out(padding) else: self.first_row = False diff -r e71317bede9b -r 8a1de3e6b7ef moinformat/tree/moin.py --- a/moinformat/tree/moin.py Wed Oct 06 00:16:28 2021 +0200 +++ b/moinformat/tree/moin.py Sat Oct 09 00:34:01 2021 +0200 @@ -3,7 +3,7 @@ """ Moin wiki format document tree nodes. -Copyright (C) 2017, 2018, 2019, 2020 Paul Boddie +Copyright (C) 2017, 2018, 2019, 2020, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -508,19 +508,23 @@ "A table cell." - def __init__(self, nodes, attrs=None): + def __init__(self, nodes, attrs=None, leading="", padding=""): Container.__init__(self, nodes) self.attrs = attrs + self.leading = leading + self.padding = padding def __repr__(self): - return "TableCell(%r, %r)" % (self.nodes, self.attrs) + return "TableCell(%r, %r, %r, %r)" % (self.nodes, self.attrs, + self.leading, self.padding) def prettyprint(self, indent=""): - l = ["%sTableCell:" % indent] + l = ["%sTableCell: leading=%r padding=%r" % (indent, self.leading, + self.padding)] return self._prettyprint(l, indent) def to_string(self, out): - out.start_table_cell(self.attrs) + out.start_table_cell(self.attrs, self.leading, self.padding) self._to_string(out) out.end_table_cell() @@ -528,19 +532,23 @@ "A table row." - def __init__(self, nodes, trailing=""): + def __init__(self, nodes, trailing="", leading="", padding=""): Container.__init__(self, nodes) self.trailing = trailing + self.leading = leading + self.padding = padding def __repr__(self): - return "TableRow(%r, %r)" % (self.nodes, self.trailing) + return "TableRow(%r, %r, %r, %r)" % (self.nodes, self.trailing, + self.leading, self.padding) def prettyprint(self, indent=""): - l = ["%sTableRow: trailing=%r" % (indent, self.trailing)] + l = ["%sTableRow: trailing=%r leading=%r padding=%r" % ( + indent, self.trailing, self.leading, self.padding)] return self._prettyprint(l, indent) def to_string(self, out): - out.start_table_row() + out.start_table_row(self.leading, self.padding) self._to_string(out) out.end_table_row(self.trailing) diff -r e71317bede9b -r 8a1de3e6b7ef tests/test_continuation.tree --- a/tests/test_continuation.tree Wed Oct 06 00:16:28 2021 +0200 +++ b/tests/test_continuation.tree Sat Oct 09 00:34:01 2021 +0200 @@ -5,23 +5,17 @@ TableCell FontStyle Text - Text TableCell - Text FontStyle Text - Text TableRow TableCell Text TableCell - Text Link LinkLabel Text - Text Continuation - Text Link LinkLabel Text diff -r e71317bede9b -r 8a1de3e6b7ef tests/test_table_parser.tree --- a/tests/test_table_parser.tree Wed Oct 06 00:16:28 2021 +0200 +++ b/tests/test_table_parser.tree Sat Oct 09 00:34:01 2021 +0200 @@ -8,7 +8,6 @@ TableCell FontStyle Text - Text TableCell Text TableRow @@ -28,13 +27,11 @@ TableAttr Text TableCell - Text TableAttrs TableAttr Text TableRow TableCell - Text TableAttrs TableAttr Text