generic text markup tools
Revisión | 525f9b8a7032ccc3862f4b411e8f9cef69a405e3 (tree) |
---|---|
Tiempo | 2014-02-05 19:42:36 |
Autor | hylom <hylom@hylo...> |
Commiter | hylom |
editing ctable...
@@ -5,6 +5,7 @@ | ||
5 | 5 | import re |
6 | 6 | |
7 | 7 | table_rows = [] |
8 | +table_attrs = {} | |
8 | 9 | |
9 | 10 | def tableRow(context, args): |
10 | 11 | line = args[0] |
@@ -13,15 +14,49 @@ def tableRow(context, args): | ||
13 | 14 | return [] |
14 | 15 | |
15 | 16 | def tableHeaderRow(context, args): |
16 | - return tableRow(context, args) | |
17 | + tableRow(context, args) | |
18 | + row_count = len(table_rows) | |
19 | + for i in range(0, len(table_rows[-1])): | |
20 | + table_attrs[(row_count-1, i)] = {"header": True} | |
21 | + return [] | |
22 | + | |
23 | +def start_tag(tag, attrs={}): | |
24 | + if len(attrs) > 0: | |
25 | + attr = " " + " ".join([x + "=" + '"' + attrs[x] + '"' for x in attrs.keys()]) | |
26 | + else: | |
27 | + attr = "" | |
28 | + return "<" + tag + attr + ">" | |
29 | + | |
30 | +def end_tag(tag): | |
31 | + return "</" + tag + ">" | |
17 | 32 | |
18 | 33 | def renderTable(context, args): |
19 | 34 | buf = "" |
20 | - for row in table_rows: | |
35 | + height = len(table_rows) | |
36 | + for i in range(0, height): | |
21 | 37 | buf += "<tr>\n " |
22 | - for cell in row: | |
23 | - buf += "<td>" + cell + "</td>" | |
38 | + width = len(table_rows[i]) | |
39 | + for j in range(0, width): | |
40 | + print ":" + str(i) + "," + str(j) | |
41 | + attrs = {} | |
42 | + # check: cell is header? | |
43 | + if table_attrs.get((i, j), False): | |
44 | + tag = "th" | |
45 | + else: | |
46 | + tag = "td" | |
47 | + # check: | |
48 | + if i == 0: | |
49 | + rowspan = 0 | |
50 | + for x in range(i+1, height): | |
51 | + if table_rows[x][j] != "": | |
52 | + break; | |
53 | + rowspan += 1; | |
54 | + if rowspan > 0: | |
55 | + attrs["rowspan"] = rowspan | |
56 | + | |
57 | + buf += start_tag(tag, attrs) + table_rows[i][j] + end_tag(tag) | |
24 | 58 | buf += "\n</tr>" |
59 | + | |
25 | 60 | return [('ctable', buf)] |
26 | 61 | |
27 | 62 | def flushTable(context, args): |