Skip to content

Commit 64ea2c0

Browse files
authored
Merge pull request #1 from WwwwwyDev/develop
fix bugs
2 parents ebccc25 + 5015803 commit 64ea2c0

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

compiler.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def syntax_check(markdown, variable, root, file_path, max_depth=0):
6060
"maximum recursion depth exceeded")
6161
try:
6262
_markdown = load_markdown(import_path)
63-
variable.update(load_variable(import_path))
64-
syntax_check(_markdown, variable, root, import_path, max_depth + 1)
63+
_variable = {**variable, **load_variable(import_path)}
64+
syntax_check(_markdown, _variable, root, import_path, max_depth + 1)
6565
except RecursionError:
6666
raise SyntaxCheckError(file_path, match_line[i], command,
6767
"maximum recursion depth exceeded")
@@ -138,8 +138,8 @@ def compile_markdown(markdown, variable, root, file_path):
138138
else:
139139
import_path = _root + "/" + relative_path
140140
_markdown = load_markdown(import_path)
141-
variable.update(load_variable(import_path))
142-
up_content = compile_markdown(_markdown, variable, root, import_path)
141+
_variable = {**variable, **load_variable(import_path)}
142+
up_content = compile_markdown(_markdown, _variable, root, import_path)
143143
start_pos, end_pos = match.span()
144144
markdown = markdown[:start_pos + offset] + up_content + markdown[end_pos + offset:]
145145
offset += len(up_content) - len(match.group())
@@ -163,8 +163,8 @@ def compile_markdown(markdown, variable, root, file_path):
163163
start_pos, end_pos = match.span()
164164
if "if" in condition.keys():
165165
if_match = condition["match"]
166-
is_start_line = 1 if markdown[if_match.span()[1] + offset] == "\n" and markdown[
167-
if_match.span()[0] + offset - 1] == "\n" else 0
166+
is_start_line = 1 if (markdown[if_match.span()[1] + offset] == "\n") and (if_match.span()[0] == 0 or markdown[
167+
if_match.span()[0] + offset - 1] == "\n") else 0
168168
is_end_line = 1 if (markdown[start_pos + offset - 1] == "\n" and (end_pos + offset >= len(markdown)
169169
or markdown[
170170
end_pos + offset] == "\n")) else 0
@@ -184,8 +184,8 @@ def compile_markdown(markdown, variable, root, file_path):
184184
elif "for" in condition.keys():
185185
for_match = condition["match"]
186186
for_variable = condition["for"]
187-
is_start_line = 1 if markdown[for_match.span()[1] + offset] == "\n" and markdown[
188-
for_match.span()[0] + offset - 1] == "\n" else 0
187+
is_start_line = 1 if markdown[for_match.span()[1] + offset] == "\n" and (for_match.span()[0] == 0 or markdown[
188+
for_match.span()[0] + offset - 1] == "\n") else 0
189189
is_end_line = 1 if (markdown[start_pos + offset - 1] == "\n" and (end_pos + offset >= len(markdown)
190190
or markdown[
191191
end_pos + offset] == "\n")) else 0
@@ -194,7 +194,6 @@ def compile_markdown(markdown, variable, root, file_path):
194194
for i, for_element in enumerate(for_variable):
195195
up_content = markdown[
196196
for_match.span()[1] + offset + is_start_line:start_pos + offset - is_end_line]
197-
up_content = compile_markdown(up_content, variable, root, file_path)
198197
temp_for_offset = 0
199198
for temp_for_match in re.finditer(for_variable_pattern, up_content):
200199
temp_for_variable_key = temp_for_match.group()[6:-5].strip()
@@ -205,6 +204,7 @@ def compile_markdown(markdown, variable, root, file_path):
205204
:temp_for_start_pos + temp_for_offset] + temp_for_up_content + up_content[
206205
temp_for_end_pos + temp_for_offset:]
207206
temp_for_offset += len(temp_for_up_content) - len(temp_for_match.group())
207+
up_content = compile_markdown(up_content, variable, root, file_path)
208208
total_up_content += up_content
209209

210210
if is_end_line and i != len(for_variable) - 1:
@@ -224,6 +224,7 @@ def compile_file_or_dir(path, name="build.md"):
224224
path = path.joinpath("main.md")
225225
if not path.exists():
226226
log("cannot find the file {}".format(str(path)))
227+
return
227228
file_path = filter_path(str(path))
228229
markdown = load_markdown(file_path)
229230
variable = load_variable(file_path)

0 commit comments

Comments
 (0)