diff --git a/tools/parse_markdown.py b/tools/parse_markdown.py index 4de1d2e..b9f41ea 100644 --- a/tools/parse_markdown.py +++ b/tools/parse_markdown.py @@ -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))