Don't autolink URLs used as markdown link text#3319
Conversation
📝 WalkthroughWalkthroughThis PR fixes a bug where URLs appearing inside Markdown link text were being separately autolinked, creating nested 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The parser-level check only caught the case where the autolink URL appeared immediately after `[`. Once any literal text intervened, the LinkDelimiterInline walk-back missed it. Detecting nested links in the renderer instead works for every parse shape. Co-authored-by: Cursor <cursoragent@cursor.com>
Why
When a URL is used as both the visible text and the target of a markdown link — e.g. https://gist.github.com — the page renders two external-link icons. The custom bare-URL autolinker runs before the standard link parser, so it matches the URL inside the [...] text and produces a nested . The CSS rule that paints the external icon then fires on both anchors. Closes #3317.
Chose to do this through a code fix rather than fixing instances because sometimes the URL link text is the most accurate + making it a bare link is busywork + the problem is likely to recur. the most expedient fix is in the code
What
HtmxLinkInlineRenderer now walks the parent chain of each LinkInline it's about to write; if any ancestor is also a LinkInline, it skips the wrapping and just renders the children. The outer link keeps its target="_blank" + external icon; the inner autolinked URL becomes plain text inside it. One anchor, one icon, valid HTML.
Adds two regression tests covering the exact issue case and a URL embedded mid-text inside link text.
Made with Cursor