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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## Unreleased

- 🐛 FIX: `gfm_autolink` hang on autolink-like text in link labels (#160)

## 0.7.0 - 2026-07-19

- ✨ NEW: Add section reference plugin (`section_ref`) (#144)
Expand Down
9 changes: 6 additions & 3 deletions mdit_py_plugins/gfm_autolink/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ def _www_inline_rule(state: StateInline, silent: bool) -> bool:
label = src[pos : pos + length]

if silent:
return True
# Autolinks are only recognised when emitting tokens. When skipping
# silently (e.g. scanning a link label), report no match so the parser
# steps over this text as plain characters (#160).
return False

full_url = state.md.normalizeLink(url)
if not state.md.validateLink(full_url):
Expand Down Expand Up @@ -223,7 +226,7 @@ def _protocol_rule(state: StateInline, silent: bool) -> bool:
label = combined[:total_len]

if silent:
return True
return False # see _www_inline_rule
return _create_autolink(state, bscan_len, total_len, full_url, label)


Expand Down Expand Up @@ -291,5 +294,5 @@ def _email_rule(state: StateInline, silent: bool) -> bool:
url = "mailto:" + email_text

if silent:
return True
return False # see _www_inline_rule
return _create_autolink(state, local_len, total_len, url, email_text)
51 changes: 51 additions & 0 deletions tests/fixtures/gfm_autolink.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,54 @@ xmpp:foo@bar.baz/txt/bin
.
<p><a href="xmpp:foo@bar.baz/txt">xmpp:foo@bar.baz/txt</a>/bin</p>
.

GFM autolink: www in link text after leading text (#160)
.
see [www.example.com](https://example.com)
.
<p>see <a href="https://example.com">www.example.com</a></p>
.

GFM autolink: www in emphasized link text (#160)
.
[link *www.example.com*](https://example.org)
.
<p><a href="https://example.org">link <em>www.example.com</em></a></p>
.

GFM autolink: www in image alt text (#160)
.
see ![www.example.com](i.png)
.
<p>see <img src="i.png" alt="www.example.com"></p>
.

GFM autolink: www in reference link label (#160)
.
see [www.example.com]

[www.example.com]: https://example.com
.
<p>see <a href="https://example.com">www.example.com</a></p>
.

GFM autolink: protocol in link text with preceding text (#160)
.
https[x https://example.com](u)
.
<p>https<a href="u">x https://example.com</a></p>
.

GFM autolink: email in link text with preceding text (#160)
.
a[x b@example.com](u)
.
<p>a<a href="u">x b@example.com</a></p>
.

GFM autolink: mailto in link text with preceding text (#160)
.
mailto[x mailto:a@example.com](u)
.
<p>mailto<a href="u">x mailto:a@example.com</a></p>
.