Repository navigation
Open
Description
Proposal
Render fenced ```mermaid blocks as diagrams in chat and other Markdown surfaces, using Pele (repository).
Why
- Agents already write Mermaid. Plans, architecture explanations, and flows come back as Mermaid. Today
CodeBlockinapps/web/src/components/chat/markdown.tsxshows them as syntax-highlighted text, so the reader has to paste them somewhere else to see the diagram. - Pele is a better fit than Mermaid.js, according to its own comparison: about 230 kB gzip against 1.6 MB, render times under 1 ms against tens of ms, zero dependencies, MIT license, and support for every diagram type built into Mermaid 12.1.0.
- Theming uses CSS variables (
--pele-bg,--pele-fg,--pele-line,--pele-surface). They can map to our design tokens, so light and dark mode work without re-rendering. - Rendering is synchronous and cheap. That fits streamed messages: re-render on each update and keep the last good SVG while the fence is still incomplete.
Sketch
- In
MemoizedMarkdown, sendblock.lang === "mermaid"to a lazy-loadedMermaidBlock, using the same split-chunk pattern asLazyHighlighter. MermaidBlockcalls Pele'srender()ormount()and inserts the SVG. If parsing fails, it falls back to the currentCodeBlock.- Keep the copy button, and add a toggle between the diagram and its source.
- Apply the same renderer to the shared
packages/uiMarkdown component, so documents and other surfaces get it too.
Security: required
Diagram source comes from model output, which can repeat untrusted content (issues, web pages, files). Pele's security page says what it already filters and what the app must handle:
- Sanitize every SVG before it is inserted. Pass
mount()our SVG sanitizer, or sanitizerender()output ourselves. Either way, nothing goes into the page through rawinnerHTML. No sanitizer is installed in this repository yet; DOMPurify's SVG profile is the obvious candidate. - Disable
linksandimages. Images make network requests when the diagram is displayed, which would let a diagram send data out of the page. - Do not pass
icons. Pele inserts icon markup without filtering it. - Show errors with
textContent. Error messages can contain text from the diagram. - Never let diagram source set render
optionsoroptions.config. - Keep Pele's default size limits (50k characters of source, 5k edges) or lower them.
Acceptance
- Mermaid fences render as diagrams in chat, in light and dark mode.
- Invalid or partial source falls back to the code block, with no console errors.
- A test feeds a hostile diagram (script in a label, a
javascript:link, an image URL, aclickcallback) and asserts the inserted DOM has no scripts, no event handlers, and no external URLs. - The new chunk loads only when a message contains a Mermaid block.
🤖 Generated with Claude Code
Metadata
Metadata
Assignees
Labels
No labels
Activity