mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
pyrofork: parser: markdown: Ignore markdown inside <code> tags
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
ced07dd421
commit
8902f8be9e
1 changed files with 10 additions and 0 deletions
|
|
@ -57,6 +57,7 @@ OPENING_TAG = "<{}>"
|
|||
CLOSING_TAG = "</{}>"
|
||||
URL_MARKUP = '<a href="{}">{}</a>'
|
||||
FIXED_WIDTH_DELIMS = [CODE_DELIM, PRE_DELIM]
|
||||
CODE_TAG_RE = re.compile(r"<code>.*?</code>")
|
||||
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue