diff --git a/CHANGELOG.md b/CHANGELOG.md index a1b78b3..ca180d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/mdit_py_plugins/gfm_autolink/index.py b/mdit_py_plugins/gfm_autolink/index.py index 48de4b7..360ba67 100644 --- a/mdit_py_plugins/gfm_autolink/index.py +++ b/mdit_py_plugins/gfm_autolink/index.py @@ -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): @@ -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) @@ -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) diff --git a/tests/fixtures/gfm_autolink.md b/tests/fixtures/gfm_autolink.md index 6a715f3..03e369f 100644 --- a/tests/fixtures/gfm_autolink.md +++ b/tests/fixtures/gfm_autolink.md @@ -223,3 +223,54 @@ xmpp:foo@bar.baz/txt/bin .
. + +GFM autolink: www in link text after leading text (#160) +. +see [www.example.com](https://example.com) +. +see www.example.com
+. + +GFM autolink: www in emphasized link text (#160) +. +[link *www.example.com*](https://example.org) +. + +. + +GFM autolink: www in image alt text (#160) +. +see  +. +see 
see www.example.com
+. + +GFM autolink: protocol in link text with preceding text (#160) +. +https[x https://example.com](u) +. + +. + +GFM autolink: email in link text with preceding text (#160) +. +a[x b@example.com](u) +. + +. + +GFM autolink: mailto in link text with preceding text (#160) +. +mailto[x mailto:a@example.com](u) +. +mailtox mailto:a@example.com
+.