feat(agent): render markdown and highlight code in chat replies - #28
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.ts—renderMarkdown():marked(gfm) →DOMPurifysanitize. Model output is untrusted, so it's sanitized before{@html}; links open in a new tab withnoopener. SSR (nowindow) falls back to escaped plain text.src/lib/highlight.ts—highlight.jscore + 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 inafterUpdate, guarded bydata-highlightedso 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.darkclass.Tests
markdown.test.ts— inline md, fenced code + language class, XSS stripping, linktarget/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, andvite buildclean.🤖 Generated with Claude Code