Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
12 changes: 12 additions & 0 deletions test/tm-cases/link_patterns_markdown_syntax.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,15 @@
<p>[Recipe 123]</p>

<p><a href="http://code.activestate.com/recipes/123/">Recipe 123</a></p>

<p><a href="https://example.com/recipe">See
Recipe 123</a></p>

<p><img src="recipe.png" alt="See
Recipe 123" /></p>

<p><a href="http://code.activestate.com/recipes/123/">Recipe 123</a> before <a href="https://example.com/other">See
Recipe 456</a> and <a href="http://code.activestate.com/recipes/789/">Recipe 789</a> after.</p>

<p><a href="https://example.com/nested">Recipe 123 [nested]
label</a></p>
14 changes: 13 additions & 1 deletion test/tm-cases/link_patterns_markdown_syntax.text
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,16 @@

[Recipe 123]

Recipe 123
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)