mirror of
https://github.com/block/goose.git
synced 2026-07-17 12:56:20 +02:00
02b38f3ac8
- Detect code blocks with triple backtick syntax () - Render using react-syntax-highlighter with VS Code dark theme - Display language badge in top-right corner - Support all common programming languages - Maintain cursor positioning and height synchronization - Code blocks excluded from spell checking
1.8 KiB
1.8 KiB
IDE-Style Code Block Rendering Implementation Plan
Goal
Add IDE-style syntax highlighting for code blocks pasted into the chat input.
Approach
1. Detection Pattern
- Match triple backtick code fences:
```language\ncode\n``` - Regex:
/```(\w+)?\n([\s\S]*?)```/g - Extract language (optional) and code content
2. Integration Points
- Add to
allMatchesarray inrenderContent()alongside actions, mentions, misspelled words - Type:
'codeblock' - Store:
{ language, code, index, length }
3. Rendering
- Use
react-syntax-highlighter(already installed) - Theme:
vscDarkPlus(VS Code dark theme) - Wrapper: Styled
<div>with IDE-like appearance- Dark background
- Rounded corners
- Padding
- Optional language label
- Monospace font
4. Styling Considerations
- Disable spell check within code blocks
- Maintain cursor positioning
- Handle height synchronization
- Ensure code blocks don't break layout
5. Features
- Syntax highlighting based on language
- Language badge in top-right corner
- Copy button (future enhancement)
- Line numbers (optional, future enhancement)
Implementation Steps
- ✅ Import
SyntaxHighlighterand theme - ⏳ Add code block regex to
renderContent() - ⏳ Extract code blocks and add to
allMatches - ⏳ Create code block rendering component
- ⏳ Handle cursor positioning around code blocks
- ⏳ Test with various languages (js, py, tsx, etc.)
- ⏳ Ensure height sync works with code blocks
Example Input
```typescript function hello(name: string) { console.log(`Hello, ${name}!`); } ```
Expected Output
A beautifully syntax-highlighted code block with:
- VS Code dark theme colors
- Proper indentation
- Language-specific highlighting
- Clean, IDE-like appearance