forked from martinpflaum/latex_to_html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocessor.py
84 lines (73 loc) · 2.13 KB
/
preprocessor.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
#%%
from core import *
import copy
input = load_file("semantic-macros.tex")
toprocess = input + " "
"""
<ol class="enumeration" type="1">
<li value="(O1)">This is item three.</li>
<li value="(O2)">This is item fifty.</li>
<li value="(O3)">
Something Aweakkjlk
<ol class="enumeration" type="1">
<li value="">This is item three.</li>
<li value="(A5)">This is item fifty.</li>
<li value="(A6)">This is item one hundred.</li>
</ol>
</li>
</ol>
"""
def execute_on_pattern(input,arg_num,command_name,command_pattern):
input = input.split(command_name)#save_command_split(input,command_name)
out = input[0]
input = input[1:]
#print(command_name)
for elem in input:
pattern_instance = command_pattern
post = elem
for k in range(arg_num):
if first_char_brace(post):
content,post = split_on_first_brace(post)
pattern_instance = pattern_instance.replace("#"+str(k+1),content)
else:
pattern_instance = pattern_instance.replace("#"+str(k+1),"")
out += pattern_instance + post
return out
def do_commands(input):
toprocess = input
out = ""
all_commands = []
while True:
pre,post = split_on_next(toprocess,"\\newcommand")
out += pre
if toprocess == pre:
print("break")
break
command_name,post = split_on_first_brace(post)
arg_num = 0
if first_char_brace(post,"["):
arg_num,post = split_on_first_brace(post,"[","]")
arg_num = int(arg_num)
command_pattern,post = split_on_first_brace(post)
toprocess = post
all_commands.append((arg_num,command_name,command_pattern))
while True:
tmp = input
for arg_num,command_name,command_pattern in all_commands:
tmp = execute_on_pattern(tmp,arg_num,command_name,command_pattern)
if tmp == input:
break
input = tmp
return input
#%%
# %%
split_on_next("cacbac","x")
# %%
a = "kjk"
b = a
a
# %%
save_command_split("\\huhua jkk \\kre\n \\hui{","\\hu")
# %%
"#"+str(1)
# %%