Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

Enhances markdown code block rendering with line numbers, syntax highlighting, and a reusable copy-to-clipboard button.

Changes

Code Block Display

  • Line numbers in left gutter using CSS grid layout
  • Syntax highlighting with Shiki (lazy-loads languages on-demand)
  • Line wrapping enabled (no horizontal scroll)
  • Increased line-height to 1.6 for better readability

Copy Functionality

  • Reusable CopyButton component (src/components/ui/CopyButton.tsx)
    • Hover-to-reveal button positioned bottom-right
    • Shows "Copied!" feedback for 2 seconds
    • Fully documented with TypeScript interfaces
  • CopyIcon component (src/components/icons/CopyIcon.tsx)
    • SVG icon with clean clipboard metaphor
    • Accepts className for styling flexibility
  • Clipboard utility (src/utils/clipboard.ts)
    • Modern navigator.clipboard API with fallback
    • Supports Storybook, HTTP contexts, older browsers

Storybook Examples

  • CodeBlock.stories.tsx - Various code block examples
  • CopyButton.stories.tsx - Reusable copy button demos

Additional Fixes

  • Fixed fmt.mk to check ~/.local/bin/uvx for uvx availability

Visual Design

Code blocks now have:

  • Subtle gutter background with vertical border
  • Rounded corners (4px)
  • Hover-reveals copy button with smooth opacity transition
  • Dark semi-transparent button background

Testing

All components visible in Storybook:

  • Components/Messages/CodeBlock - Code block examples
  • UI/CopyButton - Copy button standalone examples

Generated with cmux

- Add line numbers in left gutter using CSS grid layout
- Implement reusable CopyButton component with clipboard fallback
- Add CopyIcon SVG component
- Extract clipboard logic to src/utils/clipboard.ts
- Support syntax highlighting with Shiki
- Enable line wrapping without horizontal scroll
- Add subtle hover-to-reveal copy button
- Include Storybook examples for both components
- Fix fmt.mk to check ~/.local/bin/uvx
- Increase line-height to 1.6 for better readability
- Update useCopyToClipboard hook to use copyToClipboard utility as default
- Replace navigator.clipboard.writeText with copyToClipboard in UserMessage
- Replace navigator.clipboard.writeText with copyToClipboard in AssistantMessage
- Remove redundant defaultClipboardWriteText function from UserMessage
- All clipboard operations now use the centralized utility with fallback support
@ammario ammario merged commit 145685d into main Oct 29, 2025
15 checks passed
@ammario ammario deleted the md-code branch October 29, 2025 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants