feat(tree-sitter): detect URL scopes and set link property on text chunks#737
Closed
mugnimaestra wants to merge 1 commit intoanomalyco:mainfrom
Closed
feat(tree-sitter): detect URL scopes and set link property on text chunks#737mugnimaestra wants to merge 1 commit intoanomalyco:mainfrom
mugnimaestra wants to merge 1 commit intoanomalyco:mainfrom
Conversation
…unks When tree-sitter highlights contain URL-bearing scopes (markup.link.url, string.special.url), extract the URL text and set the link property on the corresponding TextChunk. Also propagates the URL to associated markup.link.label chunks so link text is clickable too. This enables OSC 8 hyperlink emission for the tree-sitter code rendering path, fixing URL click behavior when long URLs wrap across terminal lines.
Author
|
Combining this with #736 — both fixes are needed together to solve the same issue (URLs breaking at line wrap). |
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.
Summary
When tree-sitter highlights markdown content via the
<code filetype="markdown">rendering path, URL-bearing text chunks never receive alinkproperty, so OSC 8 hyperlink sequences are never emitted. This causes terminals to fall back on visual URL auto-detection, which breaks when URLs wrap across lines.Changes
packages/core/src/lib/tree-sitter-styled-text.tsAdded URL detection to
treeSitterToTextChunks():Pre-scan phase (lines 51-68): Builds a
Map<number, string>mapping highlight indices to URLs. Scans formarkup.link.urlandstring.special.urlscopes, extracts the URL text, and also maps associatedmarkup.link.labelhighlights (found by walking backwards pastmarkup.linkbracket highlights) to the same URL.Chunk creation (lines 204-227): After merging styles, checks if any active highlight has a URL mapping. If so, sets
link: { url }on the chunk.This enables:
https://example.com) → clickable OSC 8 hyperlinkClick herein[Click here](url)) → also clickable, linking to the same URLstring.special.url→ also clickablepackages/core/src/lib/tree-sitter-styled-text.test.tsAdded 5 new tests in a
"Link detection"describe block:markup.link.urlchunks getlinkproperty ✅markup.link.labelchunks get associated URL ✅string.special.urlchunks getlinkproperty ✅link✅Test Results
All 49 tests pass (44 existing + 5 new).
Related