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 Not another row. 28 }}} 29 ||<colspan="2"> Preformatted text in a separate section 30 == 31 == Heading 2 == 32 This is in the first column. 33 || And this is in the second. 34 == This, despite the == is in a new row. 35 || 36 And this is the second column. 37 == 38 Some {{{{preformatted text}}}} || Some `preformatted text` || Observe the region notation inline. 39 == 40 <rowspan=2> 1 || 2 || 3 41 == 42 <rowstyle="background-color: #f33"> 2 || 3 43 """ 44 45 attrs, rows = parse(table) 46 expected = 11 47 48 print table 49 print attrs 50 print rows 51 print len(rows) == expected, ": length is", len(rows), "==", expected 52 print 53 for (row_attrs, columns), expected in zip(rows, [3, 2, 3, 3, 3, 2, 2, 2, 3, 3, 2]): 54 print row_attrs 55 print columns 56 non_continuation_columns = [ 57 (column_attrs, content) 58 for (column_attrs, content) in columns 59 if not column_attrs.has_key("colcontinuation") 60 and not column_attrs.has_key("rowcontinuation") 61 and not content is None 62 ] 63 print len(non_continuation_columns) == expected, ": length is", len(non_continuation_columns), "==", expected 64 print 65 66 # vim: tabstop=4 expandtab shiftwidth=4