Skip to content

feat(chat): add syntax highlighting for markdown code blocks#63

Open
kathifis wants to merge 7 commits into
mainfrom
feat/chat-syntax-highlighting
Open

feat(chat): add syntax highlighting for markdown code blocks#63
kathifis wants to merge 7 commits into
mainfrom
feat/chat-syntax-highlighting

Conversation

@kathifis

Copy link
Copy Markdown

Summary (Sub-issue #62)

Follow-up to Markdown rendering in chat. Fenced code blocks with a language tag (e.g. ```js) are now syntax-highlighted in chat messages.

  • Add highlight.js (core + selected languages) for lightweight highlighting
  • New markdownHighlight.ts utility: custom marked code renderer, highlight, then DOMPurify sanitize
  • Highlighted blocks use a fixed dark code theme so colors remain readable in both user (blue) and assistant (gray) bubbles
  • Blocks without a language tag stay plain monospace (unchanged behavior)
  • Inline code (`like this`) is not highlighted
  • Copy button continues to work on fenced blocks

This branch builds on the Markdown rendering work (MarkdownRenderer, copy button, env.d.ts). If the parent Markdown PR is not merged yet, merge that first or review this PR as the combined chat-markdown stack.

Library choice

highlight.js with lib/core and explicit language imports (js/ts, python, json, xml, css, bash, sql) — smaller bundle than importing the full package.

Acceptance criteria

  • Lightweight highlighting library (highlight.js)
  • Fenced blocks with language tag are highlighted
  • Fenced blocks without language tag render as before
  • Readable in light/dark chat bubbles (dark .hljs theme)
  • Output sanitized after highlighting (DOMPurify, ADD_ATTR: ['class'])
  • No regression for lists, bold, links, copy button
  • Tests for highlighting logic and component integration

Changed files

File Change
package.json highlight.js dependency
src/utils/markdownHighlight.ts Parse, highlight, sanitize
src/components/chat/MarkdownRenderer.vue Use utility + highlight styles
src/__tests__/markdownHighlight.test.ts Unit tests
src/__tests__/markdownRenderer.component.test.ts Component tests extended

@opencode-agent

Copy link
Copy Markdown

APIError: Quota exceeded. Check your plan and billing details.

opencode session  |  github run

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.

1 participant