dsh-plugin-mermaid: Render Mermaid Code Blocks to Images in DSH Replies

Introduction

When conversing with models in DeepSeek Harness (DSH), fenced code blocks with ```mermaid syntax frequently appear in responses. By default, you see the source code; to inspect the structure, you often have to copy it into another tool to render it, or wait for the entire turn to finish before finding a way to preview it.

The community plugin dsh-plugin-mermaid (maintained by kjx-talesofai) takes a different approach: it doesn’t modify the Markdown rendering pipeline, but instead attaches a layer of client-side decoration on top of the existing code block DOM. It renders recognized Mermaid blocks as diagrams and — importantly — produces the diagram during streaming output as soon as the block content stabilizes, without waiting for the turn to end.

The following sections explain “what it does, how to install it, how to use it, and what to watch out for.” All facts come from the GitHub repository README and package.json.

What This Is

dsh-plugin-mermaid is a client-side (web) plugin for DSH: when a fenced code block with the language tag mermaid appears in an assistant reply, it renders it as a Mermaid diagram on the page; if parsing fails, it leaves the original code block as-is without inserting placeholder UI.

In terms of classification, it belongs to “client-side” capabilities: it doesn’t occupy a Cordis slot, doesn’t add tools to the model, and doesn’t replace the entire Markdown renderer.

Core Features

Diagram View and Toolbar

When the model produces a block like the following, you see a diagram rather than the full source taking over the screen:

```mermaid
flowchart LR
    A["工作区"] --> B["暂存区"] --> C["仓库"]

```

A thin bar sits above the diagram, labeled Mermaid, providing Copy and a Source / Diagram toggle. When the plugin displays the diagram, it hides the code block’s built-in banner (the language label line); the source <pre> is still rendered by DSH, but is hidden while viewing the diagram via CSS (:has()); the plugin adds a div.dsh-mermaid node under data-code-block-content.

Rendering Strategy During Streaming Responses

DSH performs incremental Markdown parsing on streaming replies: completed blocks are parsed only once and React elements are cached, while each token mainly rebuilds the trailing block. The plugin therefore adopts the convention: rendering is triggered only after the source text has been unchanged for 220 ms. While tokens are still arriving, the timer is reset, avoiding repeated rendering of half-drawn diagrams for the “tail”; once the fence closes and subsequent body text begins arriving, the block freezes and the diagram can appear mid-turn, during the same response. If you pause inside an unclosed fence for more than 220 ms, it draws once with the current content; if the source continues to grow afterwards, the panel discards and redraws. Blocks that Mermaid cannot parse remain unchanged in full.

Rendered results for the same source and theme are cached, so re-rendering messages or switching themes does not re-run Mermaid.

Copy Behavior

The copied content matches the current view: in Diagram mode, it copies a PNG (roughly 2–3 times the display size, with the code block background filled in, for easy pasting into documents); in Source mode, it copies the Mermaid text. The browser clipboard is unreliable for SVG, so the diagram is rasterized via canvas; Mermaid uses htmlLabels: false to avoid <foreignObject> being lost during rasterization.

Mermaid Script Source and Security

The browser fetches /api/mermaid.asset.js through a same-origin, authenticated Host route. The Host resolves and serves mermaid.min.js (approximately 3.4 MB, loaded on first diagram render, with ETag revalidation) from the plugin’s dependency tree. Rendering happens entirely within the browser using Mermaid’s strict security level: HTML tags are sanitized, and click-to-activate links are not provided.

Dependencies and Environment

  • DSH: >=0.2.0-rc.1 (consistent between the README badge and package.json’s engines.dsh / peerDependencies, with an upper bound of <0.3.0-0).
  • Node (dev/test): >=22.
  • Runtime dependency: mermaid ^11.17.2.
  • License: MIT.

Installation and Activation

Install via Add plugin in DSH’s Plugin Manager; no npm publishing account is required. Do not use npm install as the installation path.

Method What to fill in
GitHub github:kjx-talesofai/dsh-plugin-mermaid#v0.2.1
Local directory The absolute path to the plugin repository, e.g. /path/to/dsh-plugin-mermaid

After installation, restart the desktop app: the Host side is responsible for asset routing and loads it only at startup. On the browser side, refresh the page (⌘R on macOS) to load the client script.

The plugin is listed on the directory site at the SkillHub plugin page; the community directory is an independent site with no official affiliation with DeepSeek / High-Flyer.

Typical Usage

  1. Install and restart DSH as described in the previous section, then refresh the conversation page.
  2. In a conversation, ask the model to output a reply containing ```mermaid fenced blocks (flowcharts, sequence diagrams, and other Mermaid-supported syntax).
  3. After the block content stabilizes, view the automatically rendered diagram; switch to Source via the toolbar when you need to edit the code, or use Copy to grab a PNG or text when pasting into documents.

The streaming example given by the maintainer in the README is the flowchart LR three-node chain shown above, and can be reproduced directly.

Use Cases and Caveats

Who it’s for: developers who frequently read or write Mermaid-containing assistant replies in DSH, want to see diagrams while streaming, but don’t want to take over the entire Markdown rendering pipeline.

Capability boundaries (README Limits):

  • DSH clients without the plugin (e.g. mobile devices with old tabs, the --no-client toolchain) still show only the code block.
  • On parse failure, there will be [mermaid] … logs in the console, but no error row is added to the UI (to avoid flickering of incomplete syntax during streaming).
  • No per-block history is provided; the panel is just the current Markdown view.
  • What it doesn’t do: doesn’t modify the Markdown renderer, doesn’t occupy assistant slots, doesn’t add model tools.

Security and trust: the plugin runs within the current DSH process and client environment and will fetch and execute the Mermaid script from the Host. Before installing, please review the repository source code and the MIT license yourself to confirm it meets your usage policy.

Summary

dsh-plugin-mermaid uses minimal DOM coupling to turn mermaid code blocks in DSH replies into switchable, copyable diagrams, and adopts a 220 ms quiescence-then-render strategy tailored to the streaming cache semantics. When you need to install it, remember the GitHub reference github:kjx-talesofai/dsh-plugin-mermaid#v0.2.1 and the step of restarting the app.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye