1.1 --- a/moinformat/__init__.py Thu May 04 16:04:52 2017 +0200
1.2 +++ b/moinformat/__init__.py Thu May 04 17:11:52 2017 +0200
1.3 @@ -459,7 +459,35 @@
1.4
1.5 attrs = TableAttrs([])
1.6 parse_region_details(items, attrs, table_pattern_names)
1.7 - cell.attrs = attrs
1.8 +
1.9 + # Test the validity of the attributes.
1.10 +
1.11 + last = None
1.12 +
1.13 + for node in attrs.nodes:
1.14 +
1.15 + # Text separator nodes must be whitespace.
1.16 +
1.17 + if isinstance(node, Text):
1.18 + if node.s.strip():
1.19 + break
1.20 +
1.21 + # Named attributes must be preceded by space if not the first.
1.22 +
1.23 + elif last and not node.concise and not isinstance(last, Text):
1.24 + break
1.25 +
1.26 + last = node
1.27 +
1.28 + # All nodes were valid: preserve the collection.
1.29 +
1.30 + else:
1.31 + cell.attrs = attrs
1.32 + return
1.33 +
1.34 + # Invalid nodes were found: serialise the attributes as text.
1.35 +
1.36 + cell.append_inline(Text(serialise(attrs)))
1.37
1.38 def parse_table_row(items, region):
1.39
2.1 --- a/tests/test12.txt Thu May 04 16:04:52 2017 +0200
2.2 +++ b/tests/test12.txt Thu May 04 17:11:52 2017 +0200
2.3 @@ -5,3 +5,6 @@
2.4 || Also not a table
2.5 || Almost a table || ...
2.6 || A table, trailing space ||
2.7 +
2.8 +||<20%%name="value"> Bad separator ||
2.9 +||<20%xx-2> Strange attributes ||