1 #!/usr/bin/env python 2 3 from ImprovedTableParser import parse 4 5 table = """<tablestyle="border: 2px solid red; border-collapse: collapse;" rowstyle="background-color: #f77;"> 6 Test||Outcome||Comments 7 == 8 Colspan 9 ||<colspan="2"> Test a column with attributes 10 == 11 Normal || <style=" 12 text-align: center" colspan=1> Three columns || Adjacent column 13 == 14 Split 15 || Three columns 16 || Separate lines 17 == 18 * Item #1 19 * Item #2 20 || 21 * Item #A 22 || Not a list 23 == 24 \\{\\{\\{ 25 Some preformatted text. 26 \\}\\}\\} 27 ||<colspan="2"> Preformatted text in a separate section 28 == 29 == Heading 2 == 30 This is in the first column. 31 || And this is in the second. 32 == This, despite the == is in a new row. 33 || 34 And this is the second column. 35 == 36 Some \\{\\{\\{preformatted text\\}\\}\\} || Some `preformatted text` || Observe the region notation inline. 37 == 38 <rowspan=2> 1 || 2 || 3 39 == 40 <rowstyle="background-color: #f33"> 2 || 3 41 """ 42 43 attrs, rows = parse(table) 44 expected = 11 45 46 print table 47 print attrs 48 print rows 49 print len(rows) == expected, ": length is", len(rows), "==", expected 50 print 51 for (row_attrs, columns), expected in zip(rows, [3, 2, 3, 3, 3, 2, 2, 2, 3, 3, 2]): 52 print row_attrs 53 print columns 54 non_continuation_columns = [ 55 (column_attrs, content) 56 for (column_attrs, content) in columns 57 if not column_attrs.has_key("colcontinuation") 58 and not column_attrs.has_key("rowcontinuation") 59 and not content is None 60 ] 61 print len(non_continuation_columns) == expected, ": length is", len(non_continuation_columns), "==", expected 62 print 63 64 # vim: tabstop=4 expandtab shiftwidth=4