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 The first column || The second 45 .. with the continuation of 46 .. the text without indentation occurring. 47 """ 48 49 attrs, rows = parse(table) 50 expected = 12 51 52 print table 53 print attrs 54 print rows 55 print len(rows) == expected, ": length is", len(rows), "==", expected 56 print 57 for (row_attrs, columns), expected in zip(rows, [3, 2, 3, 3, 3, 2, 2, 2, 3, 3, 2, 2]): 58 print row_attrs 59 print columns 60 non_continuation_columns = [ 61 (column_attrs, content) 62 for (column_attrs, content) in columns 63 if not column_attrs.has_key("colcontinuation") 64 and not column_attrs.has_key("rowcontinuation") 65 and not content is None 66 ] 67 print len(non_continuation_columns) == expected, ": length is", len(non_continuation_columns), "==", expected 68 print 69 70 expected_text = "The second\nwith the continuation of\nthe text without indentation occurring.\n" 71 text = rows[11][1][1][1] 72 print text == expected_text, ": text is", repr(text) 73 74 # vim: tabstop=4 expandtab shiftwidth=4