-
Notifications
You must be signed in to change notification settings - Fork 1
/
tabler.py
41 lines (35 loc) · 966 Bytes
/
tabler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import re
import sys
infile = sys.argv[1]
with open(infile) as f:
content = f.readlines()
outfile = open(sys.argv[1] + ".html","wb")
for line in content:
line = line.rstrip()
if line.strip() == "=":
outfile.write("<table border='1'>\n")
elif line.strip() == "==":
outfile.write("</table>\n")
else:
outfile.write("\t<tr>\n")
cells = re.split(r'\t+',line)
z = "\t\t"
td_colspan = 0
heading_colspan = 0
for c in cells:
for letter in c:
if letter == "-":
td_colspan = td_colspan + 1
elif letter == "+":
heading_colspan = heading_colspan + 1
else:
break
if td_colspan > 1:
z = z + "<td colspan=" + str(td_colspan) + ">" + c[td_colspan:] + "</td>"
elif heading_colspan > 0:
z = z + "<td colspan=" + str(heading_colspan) + "><h1>" + c[heading_colspan:] + "</h1></td>"
else:
z = z + "<td>" + c[td_colspan:] + "</td>"
td_colspan = 0
heading_colspan = 0
outfile.write(z + "</tr>\n")