fix(markdown): dedupe [url](url) chunks when label equals href#966
Open
mocksoul wants to merge 4 commits into
Open
fix(markdown): dedupe [url](url) chunks when label equals href#966mocksoul wants to merge 4 commits into
mocksoul wants to merge 4 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes
[url](url)markdown links rendering asurl (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):
In tables:
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:
renderInlineToken(marked renderer)CodeRenderablewith tree-sitter markdown grammar +_linkifyMarkdownChunkspost-processorThis PR fixes both paths.
Changes
1.
renderInlineToken(covers table cells)Skip appending
(href)suffix when the label text already equalstoken.href.2.
_linkifyMarkdownChunks(covers inline text)Tree-sitter markdown conceal produces this 5-chunk sequence for
[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 deduplink with label different from href shows both— regression guard (unchanged behavior)table with links where label equals href is deduped— table cells dedupAll pass. Existing
table with linksandincomplete link (no closing paren)tests continue to pass unchanged.Verification in consumer
Tested in opencode TUI with
OPENCODE_EXPERIMENTAL_MARKDOWN=true. Applied viapatchedDependencies. Confirmed visually for both inline text and table cells.Related