diff --git a/CHANGES.md b/CHANGES.md index 90f815ec..f4b326a9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -23,6 +23,7 @@ - [pull #734] Fix empty list items being parsed as nested lists (#167) - [pull #735] Fix `smarty-pants` extra converting quotes inside inline HTML tags and comments (#150) - [pull #737] Fix XSS from code spans that the span gamut doesn't treat as code spans in safe mode (#726) +- [pull #747] Fix `link-patterns` extra linking text inside Markdown links and images whose label wraps onto another line ## python-markdown2 2.5.5 diff --git a/lib/markdown2.py b/lib/markdown2.py index a55f7098..01984e47 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -3841,7 +3841,8 @@ class LinkPatterns(Extra): order = (Stage.LINKS,), () options: _link_patterns - _basic_link_re = re.compile(r'!?\[.*?\]\(.*?\)') + # LinkProcessor's 3000-character sentinel includes both label brackets. + _basic_link_re = re.compile(r'!?\[(?s:.{0,2998}?)\]\(.*?\)') def run(self, text: str): link_from_hash = {} diff --git a/test/tm-cases/link_patterns_markdown_syntax.html b/test/tm-cases/link_patterns_markdown_syntax.html index 968b9b48..7debe621 100644 --- a/test/tm-cases/link_patterns_markdown_syntax.html +++ b/test/tm-cases/link_patterns_markdown_syntax.html @@ -5,3 +5,15 @@

[Recipe 123]

Recipe 123

+ +

See +Recipe 123

+ +

See
+Recipe 123

+ +

Recipe 123 before See +Recipe 456 and Recipe 789 after.

+ +

Recipe 123 [nested] +label

diff --git a/test/tm-cases/link_patterns_markdown_syntax.text b/test/tm-cases/link_patterns_markdown_syntax.text index 4c0bff19..f19cf010 100644 --- a/test/tm-cases/link_patterns_markdown_syntax.text +++ b/test/tm-cases/link_patterns_markdown_syntax.text @@ -4,4 +4,16 @@ [Recipe 123] -Recipe 123 \ No newline at end of file +Recipe 123 + +[See +Recipe 123](https://example.com/recipe) + +![See +Recipe 123](recipe.png) + +Recipe 123 before [See +Recipe 456](https://example.com/other) and Recipe 789 after. + +[Recipe 123 [nested] +label](https://example.com/nested)