1.1 --- a/moinformat/parsers/moin.py Sun Apr 19 21:20:21 2020 +0200
1.2 +++ b/moinformat/parsers/moin.py Sun May 03 23:44:19 2020 +0200
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Moin wiki format parser.
1.6
1.7 -Copyright (C) 2017, 2018, 2019 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2017, 2018, 2019, 2020 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -422,6 +422,15 @@
1.13 attrs = TableAttrs([])
1.14 self.parse_region_details(attrs, self.table_attr_pattern_names)
1.15
1.16 + # If no end marker was found, consider that the text was not table
1.17 + # attributes at all.
1.18 +
1.19 + if attrs.incomplete:
1.20 + cell.append_inline(Text(serialise(attrs, self.get_serialiser())))
1.21 + if attrs.found_cell:
1.22 + self.end_region(cell)
1.23 + return
1.24 +
1.25 # Test the validity of the attributes.
1.26
1.27 last = None
1.28 @@ -653,17 +662,25 @@
1.29
1.30 attrs.append(TableAttr(pattern_name, self.match_group("value"), True))
1.31
1.32 - def parse_colour(self, cell):
1.33 - self.parse_table_attr(cell, "bgcolor")
1.34 + def parse_colour(self, attrs):
1.35 + self.parse_table_attr(attrs, "bgcolor")
1.36
1.37 - def parse_colspan(self, cell):
1.38 - self.parse_table_attr(cell, "colspan")
1.39 + def parse_colspan(self, attrs):
1.40 + self.parse_table_attr(attrs, "colspan")
1.41 +
1.42 + def parse_rowspan(self, attrs):
1.43 + self.parse_table_attr(attrs, "rowspan")
1.44
1.45 - def parse_rowspan(self, cell):
1.46 - self.parse_table_attr(cell, "rowspan")
1.47 + def parse_width(self, attrs):
1.48 + self.parse_table_attr(attrs, "width")
1.49
1.50 - def parse_width(self, cell):
1.51 - self.parse_table_attr(cell, "width")
1.52 + def parse_table_attrs_end(self, attrs):
1.53 + attrs.incomplete = False
1.54 + self.end_region(attrs)
1.55 +
1.56 + def parse_table_attrs_cell(self, attrs):
1.57 + attrs.found_cell = True
1.58 + self.end_region(attrs)
1.59
1.60
1.61
1.62 @@ -889,6 +906,8 @@
1.63 "attrvalue" : join(("=", group("quote", r"\Q"), # quote
1.64 group("value", ".*?"), # non-quote... (optional)
1.65 recur("quote"))), # quote
1.66 +
1.67 + "bad_tablecell" : r"\|\|", # ||
1.68 }
1.69
1.70 patterns = get_patterns(syntax)
1.71 @@ -899,7 +918,8 @@
1.72
1.73 table_attr_pattern_names = [
1.74 "attrname", "colour", "colspan", "halign", "rowspan", "tableattrsend",
1.75 - "valign", "width"
1.76 + "valign", "width",
1.77 + "bad_tablecell"
1.78 ]
1.79
1.80 inline_without_links_pattern_names = [
1.81 @@ -990,7 +1010,7 @@
1.82 "super" : parse_super,
1.83 "superend" : end_region,
1.84 "tableattrs" : parse_table_attrs,
1.85 - "tableattrsend" : end_region,
1.86 + "tableattrsend" : parse_table_attrs_end,
1.87 "tablerow" : parse_table_row,
1.88 "tablecell" : end_region,
1.89 "tableend" : end_region,
1.90 @@ -998,6 +1018,7 @@
1.91 "transclusionend" : end_region,
1.92 "underline" : parse_underline,
1.93 "underlineend" : end_region,
1.94 + "bad_tablecell" : parse_table_attrs_cell,
1.95 "valign" : parse_valign,
1.96 "verbatim" : parse_verbatim,
1.97 "width" : parse_width,
2.1 --- a/moinformat/tree/moin.py Sun Apr 19 21:20:21 2020 +0200
2.2 +++ b/moinformat/tree/moin.py Sun May 03 23:44:19 2020 +0200
2.3 @@ -3,7 +3,7 @@
2.4 """
2.5 Moin wiki format document tree nodes.
2.6
2.7 -Copyright (C) 2017, 2018, 2019 Paul Boddie <paul@boddie.org.uk>
2.8 +Copyright (C) 2017, 2018, 2019, 2020 Paul Boddie <paul@boddie.org.uk>
2.9
2.10 This program is free software; you can redistribute it and/or modify it under
2.11 the terms of the GNU General Public License as published by the Free Software
2.12 @@ -466,6 +466,15 @@
2.13
2.14 "A collection of table attributes."
2.15
2.16 + def __init__(self, nodes):
2.17 + Container.__init__(self, nodes)
2.18 +
2.19 + # Parsing state flags, inconsequential to any final document tree.
2.20 + # If incomplete remains set, the attributes are discarded.
2.21 +
2.22 + self.incomplete = True
2.23 + self.found_cell = False
2.24 +
2.25 def __repr__(self):
2.26 return "TableAttrs(%r)" % self.nodes
2.27
2.28 @@ -476,7 +485,8 @@
2.29 def to_string(self, out):
2.30 out.start_table_attrs()
2.31 out.table_attrs(self.nodes)
2.32 - out.end_table_attrs()
2.33 + if not self.incomplete:
2.34 + out.end_table_attrs()
2.35
2.36 class Table(Container):
2.37