Markdown link labels are underlined but not clickable (missing OSC 8)
Summary
Labeled Markdown links are styled as links in the TUI, but the label is not clickable because Jcode does not emit an OSC 8 hyperlink. In iTerm2, Command-clicking the underlined label does nothing, while Command-clicking the same destination when printed as a raw URL works.
This is the focused OSC 8 issue suggested in #622, whose triage comment recommended splitting terminal hyperlinks into a smaller issue.
Reproduction
- Run Jcode in iTerm2.
- Render a response containing:
[Jcode issue #898](https://github.com/1jehuang/jcode/issues/898)- Command-click the underlined
Jcode issue #898label. - Print
https://github.com/1jehuang/jcode/issues/898as a raw URL and Command-click it.
Actual behavior
- The labeled Markdown text is underlined but does not open anything.
- The raw URL opens correctly through iTerm2's URL detection.
Expected behavior
The labeled text should carry its Markdown destination as an OSC 8 hyperlink, so supporting terminals can open it. Non-supporting terminals should retain the visible raw-URL fallback.
Environment
- Jcode v0.86.20-dev (
cc200cd28) - macOS, arm64
- iTerm2
TERM=xterm-256color- No tmux or screen
Source-level cause
At current public master (ef4c2bd):
crates/jcode-tui-markdown/src/markdown_render_full.rscrates/jcode-tui-markdown/src/markdown_render_lazy.rs
Both renderers keep dest_url only in a temporary link_targets stack. While a link is open, apply_inline_decorations underlines the label. On TagEnd::Link, the target is appended as dim text. The destination is not retained as metadata on the rendered label.
The backend-neutral path has the same limitation. crates/jcode-render-core/src/markdown.rs identifies StyleRole::Link, but StyledSpan in crates/jcode-render-core/src/model.rs has no destination field. Ratatui 0.30 Span and Cell also have no hyperlink field, so the crossterm backend cannot emit OSC 8 from the current buffer alone.
Proposed fix
- Preserve the destination on link-label spans, for example as
link_target: Option<String>on the backend-neutralStyledSpanand equivalent sidecar metadata for the TUI renderer. - Preserve that metadata through wrapping, clipping, caching, lazy rendering, and line splitting.
- At the terminal output boundary, coalesce adjacent cells with the same destination and emit:
ESC ] 8 ; ; URL ESC \
label text
ESC ] 8 ; ; ESC \- Close any active hyperlink before cursor movement outside the run, at the end of every frame, and during terminal cleanup.
- Validate and escape destinations. Allow only intentional schemes such as
https,http, andmailto. Do not insert OSC bytes intoSpan::content, because invisible bytes would corrupt width measurement and wrapping. - Keep the visible
(url)fallback unless terminal capability handling can guarantee another safe, discoverable fallback.
A sidecar link-range map plus OSC 8-aware emission at the crossterm boundary avoids requiring hyperlink support in ratatui's Span or Cell types.
Tests
- Markdown parsing attaches the destination to every label span, including labels split across pulldown-cmark events.
- Wrapping and clipping preserve link metadata across lines.
- Terminal byte-output test contains balanced OSC 8 open/close sequences around only the label text.
- Redrawing linked text as plain text clears the terminal hyperlink state.
- Unsupported or malformed schemes remain non-clickable.
- Existing visible-width and copy-selection behavior is unchanged.
Filed by Wren (Jcode) on behalf of @tallakahath; scope approved, wording not reviewed.
Source: 1jehuang/jcode