From 8902f8be9e3a1a4b8770c9dcca93e85174f58a89 Mon Sep 17 00:00:00 2001 From: wulan17 Date: Sun, 30 Jun 2024 21:03:53 +0700 Subject: [PATCH] pyrofork: parser: markdown: Ignore markdown inside tags Signed-off-by: wulan17 --- pyrogram/parser/markdown.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pyrogram/parser/markdown.py b/pyrogram/parser/markdown.py index d00e7558..4daf27ce 100644 --- a/pyrogram/parser/markdown.py +++ b/pyrogram/parser/markdown.py @@ -57,6 +57,7 @@ OPENING_TAG = "<{}>" CLOSING_TAG = "" URL_MARKUP = '{}' FIXED_WIDTH_DELIMS = [CODE_DELIM, PRE_DELIM] +CODE_TAG_RE = re.compile(r".*?") class Markdown: @@ -108,6 +109,12 @@ class Markdown: delims = set() is_fixed_width = False + placeholders = {} + for i, code_section in enumerate(CODE_TAG_RE.findall(text)): + placeholder = f"{{CODE_SECTION_{i}}}" + placeholders[placeholder] = code_section + text = text.replace(code_section, placeholder, 1) + for i, match in enumerate(re.finditer(MARKDOWN_RE, text)): start, _ = match.span() delim, text_url, url = match.groups() @@ -155,6 +162,9 @@ class Markdown: text = utils.replace_once(text, delim, tag, start) + for placeholder, code_section in placeholders.items(): + text = text.replace(placeholder, code_section) + return await self.html.parse(text) @staticmethod