Skip to content

feat(chat): render assistant markdown instead of raw ### and **#37

Merged
SecureCloudGroup merged 1 commit into
mainfrom
feat-chat-markdown
Jul 14, 2026
Merged

feat(chat): render assistant markdown instead of raw ### and **#37
SecureCloudGroup merged 1 commit into
mainfrom
feat-chat-markdown

Conversation

@SecureCloudGroup

Copy link
Copy Markdown
Owner

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.

marked was already in the repo, but only used at build time for the Help docs — never at runtime.

What

  • lib/markdown.tsmarkedDOMPurify. 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 a javascript: 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>, no on* handlers, no javascript: 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. .bubble uses 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; the page never scrolls sideways.
  • User messages and error bubbles stay verbatim (unchanged).

Verification

  • 9 new tests — renders headings/bold/lists/tables/fenced code; survives half-finished markdown (a reply still streaming); strips <script>, on* handlers, javascript: links and iframes; forces target=_blank + noopener.
  • Web suite 63 passed, svelte-check 0 errors / 0 warnings, build green, SPA bundle rebuilt.
  • Rendered the actual reply from the earlier session (the one that showed ### **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."

… 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.
@SecureCloudGroup SecureCloudGroup merged commit 088fc88 into main Jul 14, 2026
7 checks passed
@SecureCloudGroup SecureCloudGroup deleted the feat-chat-markdown branch July 14, 2026 00:11
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