Repository navigation
Support Mermaid diagram rendering in fenced code blocks #1065
onestone1879
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Background
The Web GUI renders assistant markdown through
MarkdownTextin@deepseek-ai/dsh-client-ui-primitives(markdown renderer underlib/types/markdown/). The pipeline is:renderCodespecial-cases exactly one fence language —math— routing it to the KaTeX renderer once streaming has settled (!context.streaming && lang === "math"). Every other language goes toCodeBlock, which only knows the shiki grammar map (TypeScript, shell, …); an unknown language such asmermaidrenders as a plain<pre>with the diagram source text and a copy button.Result:
mermaidfences written by the model (e.g. flowcharts in architecture explanations) are shown to users as raw source code instead of diagrams.Requirements
mermaidfenced code block in a rendered markdown message displays as an actual SVG diagram, not as source text.mathfence: the diagram renders only after streaming of the message has settled. While a message is still streaming, the block must go through the plainCodeBlockpath exactly as it does today.CodeBlockoutput so the user still sees the source text and keeps the copy button — the same error-chain philosophy as the KaTeX renderer (strict→strict: 'ignore'→ error span).scripttags andjavascript:-style hrefs must be stripped, consistent with the trust model applied to shiki output.Recommended implementation approach
Make the seam generic instead of hard-coding mermaid:
1. Extension point in the core renderer
In
dsh-client-ui-primitives, introduce a fence-renderer registry besiderenderCode, e.g.:renderCodeconsults the registry only when!context.streaming— the same gate as thematharm, so streaming messages keep today's plainCodeBlock. A renderer returningnull(or throwing) falls back toCodeBlock. Whethermathis migrated onto the same seam or left as-is is secondary; the point is that mermaid (and future diagram languages) no longer require touching the core renderer.2. New client plugin
dsh-client-ui-mermaidRegisters
mermaid(plus themmdalias if desired) on the seam:CodeBlocksource (or a placeholder sized to avoid layout shift);CodeBlockchrome (banner, infostring, copy button) by reusing/exportingCodeBlockfrom primitives, so requirements 3 and 4 fall out naturally;themeservice) to mermaidtheme/themeVariablesand re-renders on theme change;nullso the core falls back toCodeBlock(requirement 3);3. Composition
One new row in the web profile bundle patch (
dsh-web-appcordis.patch.yml, or a dedicated bundle layer):4. Tests / verification
CodeBlockfallback; theme switch re-render; copy copies the source;Non-goals (for this issue)
All reactions