Fix: Correct regex pattern to accurately match code blocks in Markdown

This commit is contained in:
shenchucheng 2024-06-18 11:57:49 +08:00
parent 93e4c12610
commit 991bfd6f68

View file

@ -275,7 +275,7 @@ class CodeParser:
def parse_code(cls, text: str, lang: str = "", block: Optional[str] = None) -> str:
if block:
text = cls.parse_block(block, text)
pattern = rf"```{lang}.*?\s+(.*?)```"
pattern = rf"```{lang}.*?\s+(.*?)\n```"
match = re.search(pattern, text, re.DOTALL)
if match:
code = match.group(1)