Skip to content

fix(markdown): dedupe [url](url) chunks when label equals href#966

Open
mocksoul wants to merge 4 commits into
anomalyco:mainfrom
mocksoul:fix/markdown-link-dedup
Open

fix(markdown): dedupe [url](url) chunks when label equals href#966
mocksoul wants to merge 4 commits into
anomalyco:mainfrom
mocksoul:fix/markdown-link-dedup

Conversation

@mocksoul

@mocksoul mocksoul commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Fixes [url](url) markdown links rendering as url (url) in conceal mode when the visible label text equals the href — a common pattern for auto-links written in full form.

Issue

Before (conceal mode on):

[https://example.com](https://example.com)
→ https://example.com (https://example.com)   ← duplicate

In tables:

| Service | URL |
|---|---|
| Example | [https://example.com](https://example.com) |

Renders with https://example.com (https://example.com) inside the cell.

After: just https://example.com.

Context

This supersedes #707, which was closed with "we already updated the test". The referenced test covers incomplete links (no closing paren) — a different case. The original duplicate-href issue is still reproducible in v0.1.101+.

The markdown rendering pipeline has been refactored significantly since then. Markdown now takes two code paths:

  1. Table cellsrenderInlineToken (marked renderer)
  2. Normal paragraph textCodeRenderable with tree-sitter markdown grammar + _linkifyMarkdownChunks post-processor

This PR fixes both paths.

Changes

1. renderInlineToken (covers table cells)

Skip appending (href) suffix when the label text already equals token.href.

2. _linkifyMarkdownChunks (covers inline text)

Tree-sitter markdown conceal produces this 5-chunk sequence for [url](url):

[url][" "]["("][url][")"]

When the first and fourth chunks have identical text, collapse to a single chunk retaining link metadata.

Tests

3 new inline snapshot tests:

  • link with label equal to href is deduped — inline text dedup
  • link with label different from href shows both — regression guard (unchanged behavior)
  • table with links where label equals href is deduped — table cells dedup

All pass. Existing table with links and incomplete link (no closing paren) tests continue to pass unchanged.

Verification in consumer

Tested in opencode TUI with OPENCODE_EXPERIMENTAL_MARKDOWN=true. Applied via patchedDependencies. Confirmed visually for both inline text and table cells.

Related

In markdown rendering with conceal mode on, tree-sitter markdown grammar
highlights link syntax like `[url](url)` as five chunks:
  [url][" "]["("][url][")"]
where the label and href texts are identical. Visually this shows up as
"url (url)" — awkward duplication for auto-links written in full \[\]\(\) form.

This fix post-processes chunks in _linkifyMarkdownChunks (after detectLinks
annotates link metadata) to collapse the duplicate pattern into a single
chunk retaining the link metadata.

The alternative (fixing it upstream in renderInlineToken of the marked
renderer) only works for non-conceal code paths like tables, not the
tree-sitter highlighted inline markdown path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant