-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest2.py
executable file
·82 lines (71 loc) · 2.36 KB
/
test2.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
test = "<color:(0, 0, 0)>hjsfjhskd<size: 20 >lfasdasdasda<size:23123;super_offset:3; italic:True>sdasdasda</>dasdhsj</>kdfhkls</aaa>"
tags = {""}
styles = {"int": ["size", "sub_offset", "super_offset", "word_spacing", "letter_spacing", "leading"], "bool": ["italic", "bold", "underline", "shadow", "super", "sub"], "intlist": ["color", "background", "shadow_offset", "shadow_color"], "string": ["font"]}
def process_style(style):
temp = style.replace(" ", "")
temp = temp.split(";")
final = {}
for x in temp:
split_text = x.split(":")
if split_text[0] in styles["int"]:
final[split_text[0]] = int(split_text[1])
elif split_text[0] in styles["bool"]:
final[split_text[0]] = bool(split_text[1])
elif split_text[0] in styles["string"]:
final[split_text[0]] = split_text[1]
elif split_text[0] in styles["intlist"]:
final[split_text[0]] = [int(x) for x in split_text[1][1:-1].split(",")]
return final
def append(levels, lst, item):
temp = lst
for level in levels:
temp = temp[level]
temp.append(item)
return(len(temp))
style = []
text = []
final = []
current_index = 0
state = "between_tags"
close = False
levels = []
temp_final = []
for char in test:
if state == "inside_tags":
text.append(char)
if char == ">":
state = "between_tags"
temp_final.append("".join(text))
text = []
elif state == "between_tags":
if char == "<":
state = "inside_tags"
temp_final.append("".join(text))
text = []
text.append(char)
print(temp_final)
for char in test:
if state == "inside_tags":
if char == ">":
state = "between_tags"
final_style = process_style("".join(style))
if final_style != {}:
append(levels, final, final_style)
style = []
elif char == "/":
try:
levels.pop()
except:
pass
else:
style.append(char)
elif state == "between_tags":
if char == "<":
state = "inside_tags"
if text != []:
append(levels, final, "".join(text))
levels.append(append(levels, final, []) - 1)
text = []
else:
text.append(char)
print(final)