feat(chat): render assistant markdown instead of raw ### and **#37
Merged
Conversation
… instead of raw text
The chat rendered `{entry.content}` as plain text, so every assistant reply showed the model's
raw markdown — literal `###`, `**bold**`, `*` bullets and code fences. Models answer in markdown
by default, so the primary surface of the product looked broken next to any other chat UI.
- New lib/markdown.ts: marked (already a dependency, previously build-time only) -> DOMPurify.
Assistant output is UNTRUSTED — a reply can quote a fetched page, an ingested PDF or an email
verbatim — so the HTML is sanitized before it ever reaches the DOM: no script, no on* handlers,
no javascript: URLs, no iframes/inline styles. Links open in a new tab with no opener.
- New lib/Markdown.svelte: renders an assistant bubble, re-rendering safely on each streaming
delta, and attaches a copy button to every code block.
- app.css: markdown block styles. .bubble sets white-space: pre-wrap for verbatim text, which had
to be reset for rendered HTML or every paragraph gained a phantom blank line. Wide tables and
long code lines scroll inside the bubble, never the page.
- User messages and error bubbles stay verbatim.
Tests: 9 new (render headings/lists/tables/code + partial markdown while streaming; strips
<script>, on* handlers, javascript: links and iframes). Web suite 63 passed, svelte-check 0/0.
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.
Why
The chat rendered the assistant's reply as plain text (
chat/+page.svelte:675→{entry.content}), so every answer displayed the model's raw markdown — literal###,**bold**,*bullets, and code fences. Models answer in markdown by default, so the product's primary surface looked broken next to any other chat UI.markedwas already in the repo, but only used at build time for the Help docs — never at runtime.What
lib/markdown.ts—marked→ DOMPurify. Assistant output is untrusted: a reply can quote a fetched web page, an ingested PDF, or an email verbatim, so a crafted document could smuggle<img onerror=…>or ajavascript:link into the answer. Injected script would run in the app origin, which holds an unlocked session — so the model's HTML is sanitized before it ever reaches the DOM (no<script>, noon*handlers, nojavascript:URLs, no iframes/inline styles). Real links open in a new tab with no opener reference.lib/Markdown.svelte— renders the assistant bubble, re-renders safely on each streaming delta, and attaches a copy button to every code block.app.css— markdown block styles..bubbleuseswhite-space: pre-wrapfor verbatim text, which had to be reset for rendered HTML or every paragraph gained a phantom blank line. Wide tables and long code lines scroll inside the bubble; the page never scrolls sideways.Verification
<script>,on*handlers,javascript:links and iframes; forcestarget=_blank+noopener.svelte-check0 errors / 0 warnings, build green, SPA bundle rebuilt.### **Key Details:**) through the real pipeline + real stylesheet in headless Chromium: headings, nested bullets, inline code, a GFM table, a blockquote, a code block and a link all render correctly.Part of Cycle 1 (W0.1) of the Knowledge/Install plan — "present answers in a consumable way."