Skip to content

Commit

Permalink
fix: prevent autolink parsing in images and links
Browse files Browse the repository at this point in the history
  • Loading branch information
hukkin committed Dec 13, 2024
1 parent 5297ef6 commit 1236fcb
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/mdformat_gfm/_mdit_gfm_autolink_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def gfm_autolink(state: StateInline, silent: bool) -> bool: # noqa: C901
Returns:
bool: True if GFM autolink found.
"""
# Prevents autolink parsing in link and image labels
if state.level > 0:
return False

pos = state.pos
src = state.src

Expand Down
51 changes: 51 additions & 0 deletions tests/data/gfm_autolink.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,37 @@ don't touch text in html <a> tags
<p><a href="https://example.com">https://example.com</a></p>
.


space separated autolink in html <a> tags
.
<a href="https://example.fi"> https://example.com </a>
.
<p><a href="https://example.fi"> <a href="https://example.com">https://example.com</a> </a></p>
.

space separated autolink after html </a> tag
.
</a> https://example.com
.
<p></a> <a href="https://example.com">https://example.com</a></p>
.

autolink in link after </a> tag
.
</a> [t https://example.fi](https://example.com)
.
<p></a> <a href="https://example.com">t https://example.fi</a></p>
.


autolink in link after <a> tag
.
<a> [t https://example.fi](https://example.com)
.
<p><a> <a href="https://example.com">t https://example.fi</a></p>
.


entities inside raw links
.
https://example.com/foo&amp;bar
Expand Down Expand Up @@ -262,3 +293,23 @@ This doesnt http://example.org/foo.*bar*-*baz
.
<p>This doesnt <a href="http://example.org/foo.*bar*-*baz">http://example.org/foo.*bar*-*baz</a></p>
.

autolink inside link
.
[t https://blaa.org](https://www.gaah.fi)

[https://blaa.org](https://www.gaah.fi)
.
<p><a href="https://www.gaah.fi">t https://blaa.org</a></p>
<p><a href="https://www.gaah.fi">https://blaa.org</a></p>
.

autolink inside image
.
![t https://blaa.org](https://www.gaah.fi)

![https://blaa.org](https://www.gaah.fi)
.
<p><img src="https://www.gaah.fi" alt="t https://blaa.org" /></p>
<p><img src="https://www.gaah.fi" alt="https://blaa.org" /></p>
.

0 comments on commit 1236fcb

Please sign in to comment.