Skip to content

Don't autolink URLs used as markdown link text#3319

Open
shainaraskas wants to merge 2 commits into
mainfrom
double-external-icons
Open

Don't autolink URLs used as markdown link text#3319
shainaraskas wants to merge 2 commits into
mainfrom
double-external-icons

Conversation

@shainaraskas
Copy link
Copy Markdown
Member

@shainaraskas shainaraskas commented May 13, 2026

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.

bad good
image image

Made with Cursor

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR fixes a bug where URLs appearing inside Markdown link text were being separately autolinked, creating nested <a> elements and duplicate external link indicators. The fix adds early-return suppression logic to AutoLinkInlineParser.Match when the parser is inside an open [ link delimiter, supported by a helper method that detects this state by walking backwards through inline siblings. Two regression test cases verify the fix for URLs as complete link text and URLs with surrounding text.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: preventing autolinks on URLs used as markdown link text.
Linked Issues check ✅ Passed The changes directly address issue #3317 by detecting when a URL is inside an open link delimiter and suppressing autolinking, preventing the double external-link icon issue.
Out of Scope Changes check ✅ Passed All changes are scoped to the autolink parsing issue. The modifications to AutoLinkInlineParser and the corresponding tests are directly related to fixing the nested anchor problem.
Description check ✅ Passed The PR description clearly explains the issue (duplicate external-link icons from nested anchors), the root cause (autolinker runs before link parser), and the solution (suppress autolinking inside open link delimiters).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch double-external-icons

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using a URL as text on a markdown link (external) results in two "external" icons

1 participant