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