# HG changeset patch # User Paul Boddie # Date 1588542259 -7200 # Node ID e07397f18b2e1e9e0268bc9e6cdbcea84c3acbec # Parent 287fada5a8a418827b87a38b713e91cd36dc5086 Fixed table cell attribute parsing where attributes are not actually being used. This tends to occur when the "<" attribute opening character is used to start normal cell text. diff -r 287fada5a8a4 -r e07397f18b2e moinformat/parsers/moin.py --- a/moinformat/parsers/moin.py Sun Apr 19 21:20:21 2020 +0200 +++ b/moinformat/parsers/moin.py Sun May 03 23:44:19 2020 +0200 @@ -3,7 +3,7 @@ """ Moin wiki format parser. -Copyright (C) 2017, 2018, 2019 Paul Boddie +Copyright (C) 2017, 2018, 2019, 2020 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 @@ -422,6 +422,15 @@ attrs = TableAttrs([]) self.parse_region_details(attrs, self.table_attr_pattern_names) + # If no end marker was found, consider that the text was not table + # attributes at all. + + if attrs.incomplete: + cell.append_inline(Text(serialise(attrs, self.get_serialiser()))) + if attrs.found_cell: + self.end_region(cell) + return + # Test the validity of the attributes. last = None @@ -653,17 +662,25 @@ attrs.append(TableAttr(pattern_name, self.match_group("value"), True)) - def parse_colour(self, cell): - self.parse_table_attr(cell, "bgcolor") + def parse_colour(self, attrs): + self.parse_table_attr(attrs, "bgcolor") - def parse_colspan(self, cell): - self.parse_table_attr(cell, "colspan") + def parse_colspan(self, attrs): + self.parse_table_attr(attrs, "colspan") + + def parse_rowspan(self, attrs): + self.parse_table_attr(attrs, "rowspan") - def parse_rowspan(self, cell): - self.parse_table_attr(cell, "rowspan") + def parse_width(self, attrs): + self.parse_table_attr(attrs, "width") - def parse_width(self, cell): - self.parse_table_attr(cell, "width") + def parse_table_attrs_end(self, attrs): + attrs.incomplete = False + self.end_region(attrs) + + def parse_table_attrs_cell(self, attrs): + attrs.found_cell = True + self.end_region(attrs) @@ -889,6 +906,8 @@ "attrvalue" : join(("=", group("quote", r"\Q"), # quote group("value", ".*?"), # non-quote... (optional) recur("quote"))), # quote + + "bad_tablecell" : r"\|\|", # || } patterns = get_patterns(syntax) @@ -899,7 +918,8 @@ table_attr_pattern_names = [ "attrname", "colour", "colspan", "halign", "rowspan", "tableattrsend", - "valign", "width" + "valign", "width", + "bad_tablecell" ] inline_without_links_pattern_names = [ @@ -990,7 +1010,7 @@ "super" : parse_super, "superend" : end_region, "tableattrs" : parse_table_attrs, - "tableattrsend" : end_region, + "tableattrsend" : parse_table_attrs_end, "tablerow" : parse_table_row, "tablecell" : end_region, "tableend" : end_region, @@ -998,6 +1018,7 @@ "transclusionend" : end_region, "underline" : parse_underline, "underlineend" : end_region, + "bad_tablecell" : parse_table_attrs_cell, "valign" : parse_valign, "verbatim" : parse_verbatim, "width" : parse_width, diff -r 287fada5a8a4 -r e07397f18b2e moinformat/tree/moin.py --- a/moinformat/tree/moin.py Sun Apr 19 21:20:21 2020 +0200 +++ b/moinformat/tree/moin.py Sun May 03 23:44:19 2020 +0200 @@ -3,7 +3,7 @@ """ Moin wiki format document tree nodes. -Copyright (C) 2017, 2018, 2019 Paul Boddie +Copyright (C) 2017, 2018, 2019, 2020 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 @@ -466,6 +466,15 @@ "A collection of table attributes." + def __init__(self, nodes): + Container.__init__(self, nodes) + + # Parsing state flags, inconsequential to any final document tree. + # If incomplete remains set, the attributes are discarded. + + self.incomplete = True + self.found_cell = False + def __repr__(self): return "TableAttrs(%r)" % self.nodes @@ -476,7 +485,8 @@ def to_string(self, out): out.start_table_attrs() out.table_attrs(self.nodes) - out.end_table_attrs() + if not self.incomplete: + out.end_table_attrs() class Table(Container): diff -r 287fada5a8a4 -r e07397f18b2e tests/test_tables.tree --- a/tests/test_tables.tree Sun Apr 19 21:20:21 2020 +0200 +++ b/tests/test_tables.tree Sun May 03 23:44:19 2020 +0200 @@ -49,4 +49,40 @@ TableCell Macro Text + Break + Table + TableRow + TableCell + Text + FontStyle + Text + Text + TableCell + Text + FontStyle + Text + Text + TableRow + TableCell + Text + TableCell + Text + TableRow + TableCell + Text + TableCell + Text + TableRow + TableCell + Text + TableCell + Text + TableRow + TableCell + Text + TableCell + Text + FontStyle + Text + Text Block diff -r 287fada5a8a4 -r e07397f18b2e tests/test_tables.txt --- a/tests/test_tables.txt Sun Apr 19 21:20:21 2020 +0200 +++ b/tests/test_tables.txt Sun May 03 23:44:19 2020 +0200 @@ -9,3 +9,9 @@ ||<20%%name="value"> Bad separator || ||<20%xx-2> Strange attributes || ||<
> Macro, not attributes || + +|| '''Value''' || '''Frequency''' || +|| 0x01e0 || <= 45.25MHz || +|| 0x0140 || <= 92.50MHz || +|| 0x00a0 || <= 148.50MHz || +|| 0x0000 || ''Other'' ||