-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxtree2html.py
More file actions
56 lines (45 loc) · 1.11 KB
/
xtree2html.py
File metadata and controls
56 lines (45 loc) · 1.11 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/python3
import sys
def countstars(string):
count = 0
for char in string:
if char == "*":
count += 1
else:
break
return count
lines = sys.stdin.readlines()
laststars=0
currentline=0
out='<ul id="myUL">'
while(currentline < len(lines)):
stars=countstars(lines[currentline])
levels = laststars - stars
while (levels > 0):
out += '\n'
out += " " * (stars + 1)
out += "</ul>"
levels -=1
if (levels < 0):
out += " " * stars
out += '<ul class="nested">'
out += '\n'
out += " " * stars
out += '<li>'
if currentline+1 < len(lines) and countstars(lines[currentline+1]) > stars:
out += '<span class="caret">'
spanning=True;
else:
spanning=False;
out += lines[currentline].strip().lstrip("*")
if spanning:
out += "</span>\n"
laststars=stars
currentline+=1
out += "\n </ul>"
out += "\n</ul>"
with open("precode.txt", "r") as file:
print(file.read())
print(out)
with open("postcode.txt", "r") as file:
print(file.read())