From 6f368e06d6b4e793aa055a38a849f786d9f59c8a Mon Sep 17 00:00:00 2001 From: carry <2641257231@qq.com> Date: Sun, 16 Mar 2025 00:35:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E4=BA=86markdown?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E6=97=B6=E4=BB=A3=E7=A0=81=E5=9D=97=E4=B8=AD?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E8=A2=AB=E8=AF=86=E5=88=AB=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/parse_markdown.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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))