Skip to content

feat(agent): render markdown and highlight code in chat replies - #28

Merged
shimoncohen merged 2 commits into
mainfrom
feat/render-markdown-chat
Jul 30, 2026
Merged

feat(agent): render markdown and highlight code in chat replies#28
shimoncohen merged 2 commits into
mainfrom
feat/render-markdown-chat

Conversation

@shimoncohen

Copy link
Copy Markdown
Contributor

Closes #26.

What

Model responses in the agent chat were shown as raw text. Now they render as sanitized markdown with syntax-highlighted code blocks.

How

  • src/lib/markdown.tsrenderMarkdown(): marked (gfm) → DOMPurify sanitize. Model output is untrusted, so it's sanitized before {@html}; links open in a new tab with noopener. SSR (no window) falls back to escaped plain text.
  • src/lib/highlight.tshighlight.js core + a lean language set (js/ts/json/xml/css/bash/python/markdown) instead of the full ~200-language registry. Code blocks are highlighted on the live DOM in afterUpdate, guarded by data-highlighted so re-renders skip finished blocks.
  • agentChat.svelte — assistant messages render markdown; user messages stay literal (plain text).
  • app.postcss — variable-based hljs palette (github light / github-dark) + prose styles, adapts to the app's .dark class.

Tests

  • markdown.test.ts — inline md, fenced code + language class, XSS stripping, link target/rel.
  • agentChat.test.ts — assistant markdown becomes real DOM (<strong>, <pre><code>), fenced block gets .hljs-* spans, user asterisks stay literal.

All 94 tests pass; svelte-check, eslint, and vite build clean.

🤖 Generated with Claude Code

shimoncohen and others added 2 commits July 30, 2026 15:51
Assistant responses were shown as raw text. Render them as sanitized
markdown (marked + DOMPurify) with syntax-highlighted code blocks
(highlight.js core + a lean language set). User messages stay literal.

- markdown.ts: parse + sanitize; SSR falls back to escaped text
- highlight.ts: post-render highlightElement, guarded against re-runs
- app.postcss: variable-based hljs theme + prose styles, light/dark aware

Closes #26

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@shimoncohen
shimoncohen merged commit 5fe858f into main Jul 30, 2026
6 checks passed
@shimoncohen
shimoncohen deleted the feat/render-markdown-chat branch July 30, 2026 14:16
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.

Render markdown and code in model responses

1 participant