Fix discord.utils.escape_markdown only escaping first link on line
#711
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #695. On current
master, callingescape_markdownwith default parameters on something like the following stringresults in this escaping:
This is because the
_MARKDOWN_ESCAPE_COMMONregular expression consumes greedily, and considers the third line a single link with textlink 3](https://example.org), [link 4and destinationhttps://example.org. We fix this by disallowing[,]characters in link text and(,)characters in link destinations.Under this PR, the above string escapes to:
Worth noting is that the GitHub Flavored Markdown standard actually allows for brackets in link text, as well as parentheses in link destination/titles. This blog post provides a good reference on solving this intelligently, but unfortunately some of the regular expression features used (namely, recursive patterns) aren't included in Python's native
relibrary. (As an aside, the language of finite strings with balanced parentheses is provably non-regular, so we shouldn't hope for an easy cheat here.)Checklist
type: ignorecomments were used, a comment is also left explaining why