forked from martinpflaum/latex_to_html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathantibugs.py
100 lines (79 loc) · 2.04 KB
/
antibugs.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#%%
def raw_remove_comments(input):
"""
takes a raw string
"""
comment = False
out = ""
empty = True
for elem in input:
if comment == False:
if elem == "%":
comment = True
empty = False
else:
out += elem
else:
if elem == "%":
if empty == False:
comment = False
else:
empty = False
if elem == "\n":
comment = False
return out
def no_more_html_bugs(input):
"""
if <n is any where in your html file there will be a bug...
so we need to fix that
"""
input = input.replace("<"," < ")
input = input.replace(">"," > ")
return input
def no_more_dolar_bugs_begin(input):
input = input.replace("\\$","BACKSLASHDOLLAR")
return input
def no_more_dolar_bugs_end(input):
input = input.replace("BACKSLASHDOLLAR","$")
return input
def no_more_textup_bugs_begin(input):
input = input.replace("\\textup","")
return input
def remove_empty_at_begin(input):
out = 0
for k,elem in enumerate(input):
if elem == " " or elem == "\n":
out = k + 1
else:
break
return input[out:]
def only_two_breaks(input):
"""
todo fixbugs
"""
input += " "
input = input.split("<br>")
out = ""
for elem in input[:-1]:
out += (remove_empty_at_begin(elem)) + "<br>"
out += input[-1]
while True:
tmp = out.replace("<br><br><br>","<br><br>")
if tmp == out:
out.replace("<br>","\n<br>")
return out
else:
out = tmp
def no_more_bugs_begin(input):
input = raw_remove_comments(input)
input = no_more_html_bugs(input)
input = no_more_dolar_bugs_begin(input)
input = no_more_textup_bugs_begin(input)
return input
def no_more_bugs_end(input):
input = no_more_dolar_bugs_end(input)
#input = only_two_breaks(input)
return input
# %%
# %%
# %%