Render Mermaid code fences in DSH Web chat messages as lazy-loaded SVG diagrams with strict sanitization and light/dark theme follow.
Install
# from GitHub (first run asks for allowBuilds approval — follow the hint, retry)
dsh plugin --profile web add github:AKS1st/dsh-mermaid
Any plugin you install runs third-party code with your own permissions — it can read your files, use your credentials, and reach the network, and tool approvals don’t sandbox it. GitHub-sourced plugins also run build scripts at install time. Only install sources you trust, and pin a commit (github:owner/repo#sha).
README
在 DSH Web 会话消息中把 ```mermaid 代码围栏渲染为 SVG 图表的独立插件,通过 dsh plugin 安装进 web profile。
工作方式
- Host 半部(
src/index.ts):注册webServer前缀路由/mermaid-dist,从插件自己的node_modules/mermaid惰性提供 UMD 构建,并提供固定的config.json端点。 - Client 半部(
src/client/):监听会话 DOM,把 infostring 为mermaid的围栏渲染为 SVG:- 只处理已定格的围栏(流式输出期间不渲染);
- 首次遇到围栏才惰性加载 mermaid(浏览器缓存一次);
mermaid.render()产出 SVG,替换围栏的<pre>主体,语言横幅与复制按钮保留(复制仍复制源码);securityLevel恒为strict,标签经 mermaid 内置 DOMPurify 消毒,且从不绑定点击处理;- 主题跟随 GUI:
theme: auto读取body[data-ds-dark-theme],属性翻转时自动重渲染既有图表。
client 包体积约 10 KB(gzip ~4 KB);mermaid(~700 KB)只在真正出现 mermaid 围栏时才按需加载,不进入 boot 图。
安装
从 GitHub 仓库安装(构建在 prepare 脚本里自动执行):
dsh plugin --profile web add github:AKS1st/dsh-mermaid
dsh web # 重启 web 服务使 profile 生效
若 pnpm 提示 git 依赖需要执行构建脚本(
ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED), 按提示把包加入 profile 的pnpm-workspace.yaml的allowBuilds后重试即可。
本地开发(先构建再安装):
npm install
npm run build
dsh plugin --profile web add .
dsh web
卸载:
dsh plugin --profile web remove @dsh-external/dsh-mermaid
配置
组合包默认生效以下配置:
- insert:
- id: mermaid
name: '@dsh-external/dsh-mermaid'
config:
theme: auto
maxTextSize: 50000
maxEdges: 2000
securityLevel: strict
| 配置项 | 默认值 | 说明 |
|---|---|---|
theme |
auto |
图表主题:auto(跟随亮/暗)、default、dark、neutral、forest、base |
maxTextSize |
50000 | 单图文本上限(防超大图拖垮渲染) |
maxEdges |
2000 | 边数守卫 |
securityLevel |
strict |
固定为 strict,不接受 loose |
在 profile 的 cordis.patch.yml 里以 - set: 或 - update: 覆盖即可。
安全模型
- 助手输出不可信:
securityLevel锁定strict,标签中的 HTML 由 mermaid 内部 DOMPurify 消毒;不调用bindFunctions,点击处理保持惰性。 - 渲染失败时保留原纯文本代码块(绝不渲染错误 HTML),控制台可见错误。
已知限制
- 依赖主前端
CodeBlock的稳定钩子(字面量类md-code-block与 infostring 文本);上游渲染器重构时需要同步更新选择器。 - 流式输出期间不渲染,定格后才渲染。
securityLevel: strict下 mermaid 的点击交互不可用。
Links
More in this category
zhu1090093659/dsh-web-ui#packages/dsh-web-ui-all★ 2263
Plugin and skin collection for the DSH Web UI: task board, Git graph, right-side panel, remote mobile UI, pet, live token stats, and a skin center.
ccch1mneyyy/dsh-TUI★ 1051
Claude Code-style full-screen terminal UI: pixel-whale header, live status line, and streaming thought expansion.
omdsh-dev/DSH-better-sidebar★ 920
Full sidebar workbench with file rendering and editing, terminal, Git, and subagents; third-party plugins can register new tabs.
omdsh-dev/dsh-at-file★ 171
Codex-style `@file` mentions: search workspace files in the composer and attach their contents to prompts.
huiliyi37/dsh-tianshu-tui★ 143
A terminal UI (TUI) for DeepSeek Harness.
Nagi-ovo/dsh-visualize★ 90
In-conversation generative UI: the model renders interactive HTML cards into the chat stream, with streaming preview and sandboxed rendering.