fix(render): wrap URLs in OSC 8 hyperlinks for clickable terminal links#135
Merged
Conversation
Glamour's word-wrap breaks long URLs at hyphens, inserting newlines and padding that truncate the URL from the terminal's autodetection. This adds a post-processing step that wraps http(s) URLs in OSC 8 escape sequences so terminal clicks resolve to the full URL. - injectHyperlinks reconstructs URLs broken across glamour wrap gaps and wraps them in OSC 8 hyperlinks - markCodeURLs marks URLs inside fenced/inline code regions with a zero-width marker (FS, 0x1c) so they stay literal and unlinked - urlSkipMark (0x1c) is preserved through glamour as zero-width and stripped from final output - Test assertions in chat_test.go use xansi.Strip to account for the new ANSI escape sequences in URL counts
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
Glamour's word-wrap breaks long URLs at hyphens, inserting newlines and padding that truncate the URL from the terminal's autodetection. This PR adds a post-processing step that wraps
http(s)URLs in OSC 8 escape sequences so terminal clicks resolve to the full URL.Changes
internal/tui/render/markdown.goinjectHyperlinks— post-processes glamour's ANSI output to reconstruct URLs broken across wrap gaps ([spaces]\n[spaces]) and wraps them in OSC 8 hyperlinksmarkCodeURLs— markshttp(s)://occurrences inside fenced/inline code blocks with a zero-width marker so they remain literal (no clickable link for code URLs)urlSkipMark(0x1c, FS control byte) — preserved through glamour as zero-width, stripped in final outputscanWrappedURL/shouldJoinWrappedURL— heuristic to join glamour-wrapped URL fragments across linesshouldTrimURLTail— trims trailing punctuation (.,;:!?) and unbalanced closers from click targetsinjectHyperlinkson raw inputinternal/tui/render/chat_test.goxansi.Strip(got)so ANSI escape sequences from OSC 8 wrapping don't cause false negativesinternal/tui/render/markdown_hyperlinks_test.go(new)injectHyperlinks: wrap across lines, no over-join, punctuation trimming, balanced delimiters, no-op passthrough, multiple URLsTesting
xansi.Stripadjustments