1.1 --- a/moinformat/parsers/table.py Wed Oct 06 00:16:28 2021 +0200
1.2 +++ b/moinformat/parsers/table.py Sat Oct 09 00:34:01 2021 +0200
1.3 @@ -65,11 +65,13 @@
1.4 break
1.5
1.6 elif pattern == "columnsep":
1.7 - cell = TableCell([])
1.8 + cell = TableCell([], leading=self.match_group("leading"),
1.9 + padding=self.match_group("padding"))
1.10 row.append(cell)
1.11
1.12 elif pattern == "rowsep":
1.13 - row = TableRow([])
1.14 + row = TableRow([], leading=self.match_group("leading"),
1.15 + padding=self.match_group("padding"))
1.16 table.append(row)
1.17 cell = TableCell([])
1.18 row.append(cell)
1.19 @@ -92,20 +94,25 @@
1.20 syntax.update({
1.21 # At start of line:
1.22
1.23 - "rowsep" : join(("^==", # ==
1.24 + "rowsep" : join((group("leading", r"\s*"), # ws... (optional)
1.25 + "^==", # ==
1.26 excl(r".*==\s*?$"), # not-heading
1.27 - expect(r"\N*?"))), # ws-excl-nl
1.28 + group("padding", r"\s*"))), # ws... (optional)
1.29
1.30 "continuation" : group("feature",
1.31 - join(("^",
1.32 - group("indent", r"\N*"), # ws... (optional)
1.33 + join((group("leading", r"\s*"), # ws... (optional)
1.34 + "^",
1.35 + group("indent", r"\s*"), # ws... (optional)
1.36 r"\.\.", # ..
1.37 - excl(r"\.")))), # not-.
1.38 + excl(r"\."), # not-.
1.39 + group("padding", r"\s*")))),# ws... (optional)
1.40
1.41 # Within text:
1.42
1.43 - "columnsep" : join((r"\|\|", # ||
1.44 - excl(r"\|"))), # not-|
1.45 + "columnsep" : join((group("leading", r"\s*"), # ws... (optional)
1.46 + r"\|\|", # ||
1.47 + excl(r"\|"), # not-|
1.48 + group("padding", r"\s*"))), # ws... (optional)
1.49 })
1.50
1.51 patterns = get_patterns(syntax)
2.1 --- a/moinformat/serialisers/html/moin.py Wed Oct 06 00:16:28 2021 +0200
2.2 +++ b/moinformat/serialisers/html/moin.py Sat Oct 09 00:34:01 2021 +0200
2.3 @@ -221,7 +221,7 @@
2.4 def end_table_attrs(self):
2.5 pass
2.6
2.7 - def start_table_cell(self, attrs):
2.8 + def start_table_cell(self, attrs, leading, padding):
2.9 self.out("<td")
2.10
2.11 # Handle the attributes separately from their container.
2.12 @@ -235,7 +235,7 @@
2.13 def end_table_cell(self):
2.14 self.out("</td>")
2.15
2.16 - def start_table_row(self):
2.17 + def start_table_row(self, leading, padding):
2.18 self.out("<tr>")
2.19
2.20 def end_table_row(self, trailing):
3.1 --- a/moinformat/serialisers/moin/moin.py Wed Oct 06 00:16:28 2021 +0200
3.2 +++ b/moinformat/serialisers/moin/moin.py Sat Oct 09 00:34:01 2021 +0200
3.3 @@ -149,13 +149,13 @@
3.4 def end_table_attrs(self):
3.5 self.out(">")
3.6
3.7 - def start_table_cell(self, attrs):
3.8 + def start_table_cell(self, attrs, leading, padding):
3.9 self.out("||")
3.10
3.11 def end_table_cell(self):
3.12 pass
3.13
3.14 - def start_table_row(self):
3.15 + def start_table_row(self, leading, padding):
3.16 pass
3.17
3.18 def end_table_row(self, trailing):
4.1 --- a/moinformat/serialisers/moin/table.py Wed Oct 06 00:16:28 2021 +0200
4.2 +++ b/moinformat/serialisers/moin/table.py Sat Oct 09 00:34:01 2021 +0200
4.3 @@ -34,16 +34,20 @@
4.4 def start_table(self):
4.5 self.first_row = True
4.6
4.7 - def start_table_cell(self, attrs):
4.8 + def start_table_cell(self, attrs, leading, padding):
4.9 if not self.first_cell:
4.10 + self.out(leading)
4.11 self.out("||")
4.12 + self.out(padding)
4.13 else:
4.14 self.first_cell = False
4.15
4.16 - def start_table_row(self):
4.17 + def start_table_row(self, leading, padding):
4.18 self.first_cell = True
4.19 if not self.first_row:
4.20 + self.out(leading)
4.21 self.out("==")
4.22 + self.out(padding)
4.23 else:
4.24 self.first_row = False
4.25
5.1 --- a/moinformat/tree/moin.py Wed Oct 06 00:16:28 2021 +0200
5.2 +++ b/moinformat/tree/moin.py Sat Oct 09 00:34:01 2021 +0200
5.3 @@ -3,7 +3,7 @@
5.4 """
5.5 Moin wiki format document tree nodes.
5.6
5.7 -Copyright (C) 2017, 2018, 2019, 2020 Paul Boddie <paul@boddie.org.uk>
5.8 +Copyright (C) 2017, 2018, 2019, 2020, 2021 Paul Boddie <paul@boddie.org.uk>
5.9
5.10 This program is free software; you can redistribute it and/or modify it under
5.11 the terms of the GNU General Public License as published by the Free Software
5.12 @@ -508,19 +508,23 @@
5.13
5.14 "A table cell."
5.15
5.16 - def __init__(self, nodes, attrs=None):
5.17 + def __init__(self, nodes, attrs=None, leading="", padding=""):
5.18 Container.__init__(self, nodes)
5.19 self.attrs = attrs
5.20 + self.leading = leading
5.21 + self.padding = padding
5.22
5.23 def __repr__(self):
5.24 - return "TableCell(%r, %r)" % (self.nodes, self.attrs)
5.25 + return "TableCell(%r, %r, %r, %r)" % (self.nodes, self.attrs,
5.26 + self.leading, self.padding)
5.27
5.28 def prettyprint(self, indent=""):
5.29 - l = ["%sTableCell:" % indent]
5.30 + l = ["%sTableCell: leading=%r padding=%r" % (indent, self.leading,
5.31 + self.padding)]
5.32 return self._prettyprint(l, indent)
5.33
5.34 def to_string(self, out):
5.35 - out.start_table_cell(self.attrs)
5.36 + out.start_table_cell(self.attrs, self.leading, self.padding)
5.37 self._to_string(out)
5.38 out.end_table_cell()
5.39
5.40 @@ -528,19 +532,23 @@
5.41
5.42 "A table row."
5.43
5.44 - def __init__(self, nodes, trailing=""):
5.45 + def __init__(self, nodes, trailing="", leading="", padding=""):
5.46 Container.__init__(self, nodes)
5.47 self.trailing = trailing
5.48 + self.leading = leading
5.49 + self.padding = padding
5.50
5.51 def __repr__(self):
5.52 - return "TableRow(%r, %r)" % (self.nodes, self.trailing)
5.53 + return "TableRow(%r, %r, %r, %r)" % (self.nodes, self.trailing,
5.54 + self.leading, self.padding)
5.55
5.56 def prettyprint(self, indent=""):
5.57 - l = ["%sTableRow: trailing=%r" % (indent, self.trailing)]
5.58 + l = ["%sTableRow: trailing=%r leading=%r padding=%r" % (
5.59 + indent, self.trailing, self.leading, self.padding)]
5.60 return self._prettyprint(l, indent)
5.61
5.62 def to_string(self, out):
5.63 - out.start_table_row()
5.64 + out.start_table_row(self.leading, self.padding)
5.65 self._to_string(out)
5.66 out.end_table_row(self.trailing)
5.67
7.1 --- a/tests/test_table_parser.tree Wed Oct 06 00:16:28 2021 +0200
7.2 +++ b/tests/test_table_parser.tree Sat Oct 09 00:34:01 2021 +0200
7.3 @@ -8,7 +8,6 @@
7.4 TableCell
7.5 FontStyle
7.6 Text
7.7 - Text
7.8 TableCell
7.9 Text
7.10 TableRow
7.11 @@ -28,13 +27,11 @@
7.12 TableAttr
7.13 Text
7.14 TableCell
7.15 - Text
7.16 TableAttrs
7.17 TableAttr
7.18 Text
7.19 TableRow
7.20 TableCell
7.21 - Text
7.22 TableAttrs
7.23 TableAttr
7.24 Text