# HG changeset patch # User Paul Boddie # Date 1330115952 -3600 # Node ID 97d956649bff056affcae67994de939ebe2c8c41 # Parent 2a15a0299b4e6b69ef5ab91a7439579cfd66cca6 Fixed row detection to avoid headings causing new rows to be found erroneously. Fixed the test of the table to handle continuation cells and empty cells produced in cell usage propagation. diff -r 2a15a0299b4e -r 97d956649bff ImprovedTableParser.py --- a/ImprovedTableParser.py Thu Feb 23 23:47:36 2012 +0100 +++ b/ImprovedTableParser.py Fri Feb 24 21:39:12 2012 +0100 @@ -22,7 +22,7 @@ # At start of line: "sections" : (r"(^\s*{{{.*?^\s*}}})", re.MULTILINE | re.DOTALL), # {{{ ... }}} - "rows" : (r"^==", re.MULTILINE), # == + "rows" : (r"^==(?!.*?==$)", re.MULTILINE), # == not-heading # Within text: "columns" : (r"\|\|[ \t]*", 0), # || ws-excl-nl diff -r 2a15a0299b4e -r 97d956649bff tests/test_table.py --- a/tests/test_table.py Thu Feb 23 23:47:36 2012 +0100 +++ b/tests/test_table.py Fri Feb 24 21:39:12 2012 +0100 @@ -25,6 +25,13 @@ Some preformatted text. \\}\\}\\} || Preformatted text in a separate section +== +== Heading 2 == +This is in the first column. +|| And this is in the second. +== This, despite the == is in a new row. +|| +And this is the second column. """ attrs, rows = parse(table) @@ -32,12 +39,19 @@ print table print attrs print rows -print len(rows) == 6, ": length is", len(rows), "==", 6 +print len(rows) == 8, ": length is", len(rows), "==", 8 print -for (row_attrs, columns), expected in zip(rows, [3, 2, 3, 3, 3, 2]): +for (row_attrs, columns), expected in zip(rows, [3, 2, 3, 3, 3, 2, 2, 2]): print row_attrs print columns - print len(columns) == expected, ": length is", len(columns), "==", expected + non_continuation_columns = [ + (column_attrs, content) + for (column_attrs, content) in columns + if not column_attrs.has_key("colcontinuation") + and not column_attrs.has_key("rowcontinuation") + and not content is None + ] + print len(non_continuation_columns) == expected, ": length is", len(non_continuation_columns), "==", expected print # vim: tabstop=4 expandtab shiftwidth=4