Skip to content

Conversation

@rscarvalho
Copy link
Contributor

@rscarvalho rscarvalho commented Feb 1, 2026

Summary

  • Add markdownToHtml() converter with inline styles for cross-editor compatibility
  • Add copyRich() clipboard function supporting Linux (Wayland/X11), macOS, with graceful fallback
  • Add selection-to-markdown matching to find original markdown from rendered terminal text
  • Add copy_as_rich_text config option (defaults to false) and runtime toggle in command palette

Resolves #10693

Technical Details

Markdown to HTML Conversion

Uses the marked library with a custom renderer that applies inline styles to all elements. This ensures formatting is preserved when pasting into editors that strip external CSS (Google Docs, Notion).

Clipboard Platform Support

  • Linux Wayland: wl-copy --type text/html
  • Linux X11: xclip -selection clipboard -t text/html
  • macOS: AppleScript with hex-encoded HTML data
  • Windows/SSH/tmux: Plain text fallback (rich text not supported)

Selection Matching

When copying selected text, the system attempts to find the original markdown source using:

  1. Exact substring match
  2. Normalized whitespace/case comparison
  3. Stripped markdown syntax matching
  4. Partial match for selections covering >30% of content

Caveats

  • Rich text copy requires wl-copy (Wayland) or xclip (X11) to be installed on Linux
  • Remote sessions (SSH, tmux, screen) always fall back to plain text
  • Windows does not support rich text copy (falls back to plain text)
  • Selection matching may not find the source markdown for heavily transformed or partial selections

Test Plan

  • Unit tests for markdown-to-HTML conversion (31 tests)
  • Unit tests for clipboard operations (16 tests)
  • Manual test: Copy message with Ctrl+Y, paste into Google Docs
  • Manual test: Select text, Ctrl+C, paste into rich text editor
  • Manual test: Toggle setting via command palette (Ctrl+P)
  • Manual test: Verify plain text fallback in SSH session

Add markdownToHtml() function that converts markdown to HTML with inline styles for compatibility with rich text editors like Google Docs, Notion, and LibreOffice.

- Add marked dependency (^17.0.1) for markdown parsing
- Implement custom renderer with inline styles for all elements
- Support headers, lists, links, code blocks, tables, blockquotes
- Proper HTML escaping to prevent XSS
- Add copy_as_rich_text config setting (defaults to false)
- Add comprehensive test coverage (31 tests, all passing)
Add copyRich() function to copy both plain text and HTML to the system clipboard with graceful fallback when rich text is not supported.

Platform support:
- Linux Wayland: wl-copy --type text/html
- Linux X11: xclip -selection clipboard -t text/html
- macOS: AppleScript with hex-encoded HTML data
- Windows/Other: Plain text fallback
- SSH/Remote: Plain text fallback (OSC 52 doesn't support HTML)

Features:
- Add CopyRichResult discriminated union type
- Add isRemoteSession() helper for SSH/tmux detection
- Add commandExists() helper for tool availability checking
- Never throws - always returns a result with descriptive reasons
- Comprehensive test suite (16 tests covering all platforms and edge cases)
Add smart text selection matching to enable rich text copying when users select and copy text from assistant messages in the TUI.

Features:
- Add selection-to-markdown.ts with fuzzy matching to find original markdown from rendered text
- Update all text selection handlers (app.tsx, dialog.tsx) to support rich text
- Add runtime toggle command in command palette (Ctrl+P)
- Add copyAsRichText signal to local context
- Update copy handlers in session views to use markdown source

Matching strategies:
1. Exact substring match
2. Normalized whitespace/case comparison
3. Stripped markdown syntax matching
4. Partial match for selections covering >30% of content

When copy_as_rich_text is enabled and text is selected:
- Attempts to find original markdown source
- Converts to HTML and copies as rich text
- Falls back to plain text if no match found
- Shows appropriate toast messages (success/warning/error)

This completes the rich text clipboard feature, allowing users to copy both via commands and text selection with formatting preserved in rich text editors.
@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2026

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2026

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

@rscarvalho rscarvalho marked this pull request as draft February 1, 2026 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Copy assistant messages as rich text for pasting into Google Docs, Notion, etc.

1 participant