Browse Source

Fix escape behaviour for lists and headers in escape_markdown

Fixes #9516
pull/10109/head
Rapptz 2 years ago
committed by dolfies
parent
commit
278b9eb970
  1. 6
      discord/utils.py

6
discord/utils.py

@ -1021,13 +1021,13 @@ def resolve_gift(code: Union[Gift, str]) -> str:
_MARKDOWN_ESCAPE_SUBREGEX = '|'.join(r'\{0}(?=([\s\S]*((?<!\{0})\{0})))'.format(c) for c in ('*', '`', '_', '~', '|'))
_MARKDOWN_ESCAPE_COMMON = r'^>(?:>>)?\s|\[.+\]\(.+\)'
_MARKDOWN_ESCAPE_COMMON = r'^>(?:>>)?\s|\[.+\]\(.+\)|^#{1,3}|^\s*-'
_MARKDOWN_ESCAPE_REGEX = re.compile(fr'(?P<markdown>{_MARKDOWN_ESCAPE_SUBREGEX}|{_MARKDOWN_ESCAPE_COMMON})', re.MULTILINE)
_URL_REGEX = r'(?P<url><[^: >]+:\/[^ >]+>|(?:https?|steam):\/\/[^\s<]+[^<.,:;\"\'\]\s])'
_MARKDOWN_STOCK_REGEX = fr'(?P<markdown>[_\\~|\*`#-]|{_MARKDOWN_ESCAPE_COMMON})'
_MARKDOWN_STOCK_REGEX = fr'(?P<markdown>[_\\~|\*`]|{_MARKDOWN_ESCAPE_COMMON})'
def remove_markdown(text: str, *, ignore_links: bool = True) -> str:
@ -1054,7 +1054,7 @@ def remove_markdown(text: str, *, ignore_links: bool = True) -> str:
The text with the markdown special characters removed.
"""
def replacement(match):
def replacement(match: re.Match[str]) -> str:
groupdict = match.groupdict()
return groupdict.get('url', '')

Loading…
Cancel
Save