mirror of
				https://github.com/Rapptz/discord.py.git
				synced 2025-10-25 02:23:04 +00:00 
			
		
		
		
	Escape masked URLs; Support quotes for as_needed
This commit is contained in:
		| @@ -440,7 +440,9 @@ def resolve_invite(invite): | |||||||
| _MARKDOWN_ESCAPE_SUBREGEX = '|'.join(r'\{0}(?=([\s\S]*((?<!\{0})\{0})))'.format(c) | _MARKDOWN_ESCAPE_SUBREGEX = '|'.join(r'\{0}(?=([\s\S]*((?<!\{0})\{0})))'.format(c) | ||||||
|                                      for c in ('*', '`', '_', '~', '|')) |                                      for c in ('*', '`', '_', '~', '|')) | ||||||
|  |  | ||||||
| _MARKDOWN_ESCAPE_REGEX = re.compile(r'(?P<markdown>%s)' % _MARKDOWN_ESCAPE_SUBREGEX) | _MARKDOWN_ESCAPE_COMMON = r'^>(?:>>)?\s|\[.+\]\(.+\)' | ||||||
|  |  | ||||||
|  | _MARKDOWN_ESCAPE_REGEX = re.compile(r'(?P<markdown>%s|%s)' % (_MARKDOWN_ESCAPE_SUBREGEX, _MARKDOWN_ESCAPE_COMMON)) | ||||||
|  |  | ||||||
| def escape_markdown(text, *, as_needed=False, ignore_links=True): | def escape_markdown(text, *, as_needed=False, ignore_links=True): | ||||||
|     r"""A helper function that escapes Discord's markdown. |     r"""A helper function that escapes Discord's markdown. | ||||||
| @@ -476,7 +478,7 @@ def escape_markdown(text, *, as_needed=False, ignore_links=True): | |||||||
|                 return is_url |                 return is_url | ||||||
|             return '\\' + groupdict['markdown'] |             return '\\' + groupdict['markdown'] | ||||||
|  |  | ||||||
|         regex = r'(?P<markdown>[_\\~|\*`]|>(?:>>)?\s)' |         regex = r'(?P<markdown>[_\\~|\*`]|%s)' % _MARKDOWN_ESCAPE_COMMON | ||||||
|         if ignore_links: |         if ignore_links: | ||||||
|             regex = '(?:%s|%s)' % (url_regex, regex) |             regex = '(?:%s|%s)' % (url_regex, regex) | ||||||
|         return re.sub(regex, replacement, text) |         return re.sub(regex, replacement, text) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user