fix:修复了markdown解析时代码块中内容被识别的问题
This commit is contained in:
parent
0a8b9633de
commit
6f368e06d6
@ -29,9 +29,24 @@ def parse_markdown(markdown):
|
||||
root = MarkdownNode()
|
||||
stack = [root]
|
||||
|
||||
in_code_block = False
|
||||
for line in lines:
|
||||
if line.strip() == "":
|
||||
continue
|
||||
|
||||
# 检测代码块开始/结束
|
||||
if line.strip().startswith("```") or line.strip().startswith("~~~"):
|
||||
in_code_block = not in_code_block
|
||||
continue
|
||||
|
||||
# 如果当前在代码块中,直接作为内容处理
|
||||
if in_code_block:
|
||||
if stack[-1].content:
|
||||
stack[-1].content += '\n'
|
||||
stack[-1].content += line
|
||||
continue
|
||||
|
||||
# 处理标题
|
||||
match = re.match(r'^(#+)\s*(.*)', line)
|
||||
if match:
|
||||
level = len(match.group(1))
|
||||
|
Loading…
x
Reference in New Issue
Block a user