# HG changeset patch # User Paul Boddie # Date 1330194538 -3600 # Node ID d748d8831b745da6903ea17372b3564fe9cd89e9 # Parent 97d956649bff056affcae67994de939ebe2c8c41 Added support for inline preformatted text and more flexible nested region positioning. diff -r 97d956649bff -r d748d8831b74 ImprovedTableParser.py --- a/ImprovedTableParser.py Fri Feb 24 21:39:12 2012 +0100 +++ b/ImprovedTableParser.py Sat Feb 25 19:28:58 2012 +0100 @@ -17,11 +17,11 @@ syntax = { # For section markers. - "markers" : (r"^\s*(?P\\+)(?P{|})(?P=n)(?P=b)(?P=n)(?P=b)", re.MULTILINE), + "markers" : (r"(?P\\+)(?P{|})(?P=n)(?P=b)(?P=n)(?P=b)", re.MULTILINE), "marker" : (r"(\\+)", 0), # At start of line: - "sections" : (r"(^\s*{{{.*?^\s*}}})", re.MULTILINE | re.DOTALL), # {{{ ... }}} + "sections" : (r"({{{.*?}}})", re.MULTILINE | re.DOTALL), # {{{ ... }}} "rows" : (r"^==(?!.*?==$)", re.MULTILINE), # == not-heading # Within text: diff -r 97d956649bff -r d748d8831b74 tests/test_sections.py --- a/tests/test_sections.py Fri Feb 24 21:39:12 2012 +0100 +++ b/tests/test_sections.py Sat Feb 25 19:28:58 2012 +0100 @@ -7,7 +7,7 @@ Hello \\{\\{\\{ Hello again -But not \\{\\{\\{ this \\}\\}\\} +And also \\\\{\\\\{\\\\{ this \\\\}\\\\}\\\\} \\\\{\\\\{\\\\{ And once again \\\\}\\\\}\\\\} diff -r 97d956649bff -r d748d8831b74 tests/test_table.py --- a/tests/test_table.py Fri Feb 24 21:39:12 2012 +0100 +++ b/tests/test_table.py Sat Feb 25 19:28:58 2012 +0100 @@ -32,16 +32,19 @@ == This, despite the == is in a new row. || And this is the second column. +== +Some \\{\\{\\{preformatted text\\}\\}\\} || Some `preformatted text` || Observe the region notation inline. """ attrs, rows = parse(table) +expected = 9 print table print attrs print rows -print len(rows) == 8, ": length is", len(rows), "==", 8 +print len(rows) == expected, ": length is", len(rows), "==", expected print -for (row_attrs, columns), expected in zip(rows, [3, 2, 3, 3, 3, 2, 2, 2]): +for (row_attrs, columns), expected in zip(rows, [3, 2, 3, 3, 3, 2, 2, 2, 3]): print row_attrs print columns non_continuation_columns = [