genius-alray/dsh-mermaid-render
Web UI 对话 mermaid 渲染插件:将消息中的 mermaid 代码块渲染为可交互图表卡片(缩放 / 适应宽度 / 全屏查看 / 预览代码切换),复用官方组件原语,渲染失败时保留原代码块并内联展示错误。
已收录
1
Docs
Bundle 已验证
预览
功能介绍
Web UI 对话 mermaid 渲染插件:将消息中的 mermaid 代码块渲染为可交互图表卡片(缩放 / 适应宽度 / 全屏查看 / 预览代码切换),复用官方组件原语,渲染失败时保留原代码块并内联展示错误。
适合
- 经常包含 Mermaid 流程图、时序图或其他 Mermaid 代码块的 DSH Web 对话。
- 需要缩放、适应宽度、全屏查看或在图表与源码间切换的用户。
- 希望 Mermaid 无法渲染时仍保留源码并内联显示解析错误的团队。
不适合
- 非 Web 的 DSH 客户端,或在对话界面之外查看的文档。
- 很少包含 Mermaid 代码块的对话。
- 首次使用时无法从 jsDelivr 加载固定版本 Mermaid 运行库的环境。
README
dsh-mermaid-render
Interactive Mermaid diagram rendering for agent messages in the DSH Web UI: mermaid code blocks in the conversation are rendered into interactive diagram cards — zoom, fit-width, fullscreen viewer, and a preview/code toggle — built entirely on official UI primitives and DSW design tokens. When rendering fails, the original code block is preserved and an inline error banner is shown right below it.
Features
-
Auto-render mermaid code blocks — fences with
mermaid/mmdinfo strings in conversation messages become diagram cards automatically (both assistant and user messages). - Zoom / fit-width — viewport-only zoom: the card shell keeps its size, only the diagram inside scales and scrolls. Ctrl/⌘+wheel zooms, the fit button resets to width fit.
- Fullscreen viewer — a fixed overlay (product-style mask layer, portal to body): zoom, fit, and close via Esc / mask click / button.
- Preview / code toggle — a segmented selector in the card’s top-right switches between the rendered diagram and the original mermaid source.
- Graceful failure — on a render or loader error the original code block stays visible and a compact inline error banner appears under it; no stray elements are left in the page.
-
Theme-aware — diagrams re-render with the mermaid
dark/defaulttheme when the app theme changes. - Bilingual UI — zh / en labels follow the app locale.
-
Native look — primitives
Pill/Tooltipcomponents, composer-style icon buttons, lucide-style SVG icons,--dsw-*tokens only.
Install
Installed via the official dsh plugin command; it links the package into the profile and automatically appends the dsh.bundle package to dsh.profile.bundles (no manual profile edits).
dsh plugin --profile web add genius-alray/dsh-mermaid-render
Then restart dsh web — the bundle layer is composed at boot.
Git-source installs may hit pnpm’s build-script approval on first run; follow the printed hint to add the key to the profile’s
pnpm-workspace.yamlallowBuildsand re-run. The repo commits prebuiltlib/, so no local build is required.
Usage
Send a message containing a mermaid code block:
```mermaid
flowchart TD
A[Start] --> B{Has a mermaid block?}
B -- yes --> C[Load mermaid renderer]
B -- no --> D[Keep plain code block]
C --> E[Render interactive diagram]
E --> F[Toolbar: zoom / fit / fullscreen]
```
The block renders into a card with a bottom-right toolbar (zoom in / zoom out / fit width / fullscreen) and a top-right Preview / Code selector. On a syntax error the card is not rendered: the original code block remains and an inline “Mermaid render failed” banner with the parser message appears below it.
Technical notes
-
Bundle plugin (official form):
package.jsondeclaresdsh.bundle.patch: ./cordis.patch.yml; the patch mounts the package itself. Pure client (dsh.client.platform: web);lib/client.jsis served at/plugins/dsh-mermaid-render/client.js. -
mermaid is not bundled — the ~3.3 MB library is loaded lazily at first use via a runtime dynamic
import()of the pinnedmermaid@10.9.3+esmbuild from jsDelivr, so the plugin bundle stays ~34 kB and the page boot cost is zero. -
Rendering pipeline — a
MutationObserverwatches the conversation scrollport for.md-code-blockelements whose fence infostring is mermaid/mmd; each block is rendered into a private hidden container (mermaid’s error path leaves a huge “Syntax error” SVG in the DOM otherwise — the private container keeps the page clean), then the resulting SVG is mounted into a React root as an interactive card. -
Text fidelity — the SVG is scaled through its own width/height (native vector re-render) rather than CSS transforms, and the card isolates inherited typography (
font: 13px/1.5+ CJK font stack) so Chinese node labels never overflow or clip insideforeignObjectlabels. -
Stable layout — the stage height is fixed at fit-time and
scrollbar-gutter: stablereserves the scrollbar slot, soclientWidthcannot oscillate and the page never jitters. -
UI primitives —
Pill(preview/code toggle),Tooltip, composer-style icon buttons, and hand-drawn lucide-style icons; only--dsw-*tokens, no hard-coded colors.
License
MIT
常见问题常见问题
在启用了 DSH 的终端中执行已验证命令 dsh plugin --profile default add github:genius-alray/dsh-mermaid-render。命令会解析公开 package 元数据,并保持插件与本页展示的目录身份一致。
兼容性以页面上展示的 bundle 与 profile 状态为准。如果某个 profile 尚未检测到,请先保持禁用,并在生产启用前阅读仓库文档。
GitHub 链接和 activity 元数据是 release 与维护状态的来源。新版本发布后重新查看本页,确认目录已经观察到最新版本。