Repository navigation
feat: report the document's links through onLinksChange - #1088
Open
juliusmarminge wants to merge 1 commit into
Open
juliusmarminge wants to merge 1 commit into
juliusmarminge wants to merge 1 commit into
Conversation
linkPillContent, markdownStyle.linkVariants and linkContextMenuItems are keyed by link URL, but an app had no way to learn which links a document contains, so it could only configure links it predicted. The collector behind renderers and resolveImageSource now also records every Link node (URL, label, title) in document order, and onLinksChange reports them from a layout effect when they change, so a state update made in it lands before the frame is drawn. The web collector reports the same links. Links that linkRecognition adds are not reported: recognition runs in the native converters as the text is drawn, not in the shared parse.
This branch has not been deployed
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.
What/Why?
linkPillContent,markdownStyle.linkVariantsandlinkContextMenuItemsare all keyed by link URL, but an app has no way to learn which links a document contains. It can only configure links it predicts, or parse the Markdown a second time with its own rules, which disagree with md4c on bare URLs,www.andmailto:rewrites, escapes and code spans.In our app, T3 Code, every file reference in an agent message is shown as a pill with the file's name and icon, and every link gets its own long-press menu. That needs the document's real link URLs.
This adds
onLinksChange. It reports the links from the parse that #1026 already shares withrenderersandresolveImageSource:collectinBlockSlots.cppalso records every Link node, with URL, label and title, in document order. That covers paragraphs, headings, lists, tables, quotes and link blocks. It is the same walk, so there's no second parse.NativeEnrichedMarkdownParser.collectreturnslinks.onLinksChange(links)fires from a layout effect once on mount, then whenever the links change by value. A state update made in it lands before the frame is drawn. A streaming tick that adds no link reports nothing, and a new handler function doesn't report again, the same asresolveImageSource.web/blockSlots.tscollects the same links.Links that
linkRecognitionadds are not reported. Recognition runs in the native converters as the text is drawn, not in the shared parse. Apps that uselinkRecognition.textknow their own patterns, so we match those ourselves. Including recognized links would mean running the recognizers insidecollect, which seemed better as a separate discussion.A side note:
MarkdownLinkBlock.labelis documented as""for a bare URL or autolink, but both collectors return the URL as written, for examplewww.example.com. I documentedMarkdownLinkOccurrence.labelto match that behavior. I left the existing block doc alone.Testing
scripts/test-core-parser.sh: the newblock_slots_test.cppchecks cover links in headings, text, lists, tables and quotes, autolinks and bare URLs, labels, titles, code spans and fences (no links), and repeated links.onLinksChangereporting once and then only on change, also across a handler change (1791 tests pass).tscandyarn lintpass, andnode scripts/test-web-bundle.mjspasses.apps/react-native-example/scripts/test-ios.sh(27 tests) builds the regenerated parser spec.onLinksChangefor its link pills and iOS link menus. In its build I verified file pills in text, a list and a table, a host icon on a heading link, and the iOS long-press menu keyed by the reported URL. The same message usesrenderers.imagefor root and quoted images andresolveImageSourcefor list and inline images. iOS 27 and Android 17:Building that app on top of #1027 also needed #1086 (iOS with video off) and #1087 (Android include collision), opened separately.
PR Checklist
onLinksChangein the API referenceModel: Claude Opus 5.5. Harness: Claude Code in T3 Code.