dsh-mermaid-plugin: Rendering Mermaid Code Blocks into Diagrams in DSH Chats

Introduction

When chatting with models in DSH, mermaid code blocks often appear in the replies: flowcharts, sequence diagrams, class diagrams, etc. By default, these blocks contain only source code; you need to copy them to an external editor or online tool to view the diagram, which disrupts the reading flow.

Below is an introduction to the client plugin shinelon/dsh-mermaid-plugin published by the maintainer shinelon. It automatically identifies Mermaid blocks within the chat transcript in the DSH Web conversation interface, renders them in-place as SVG, and retains a “Graph / Source” toggle, theme following, and source code fallback on errors. The plugin currently has 0 stars on GitHub and is categorized as a client-side plugin. regarding the ecosystem, DSH emphasizes “everything is a plugin.” The SkillHub directory page has no official affiliation with DeepSeek or High-Flyer (Huanfang). Please verify the source code and the MIT license yourself before installation.

What is this

dsh-mermaid-plugin (package name @local/mermaid-chat, manifest version 1.0.0) is a Web client plugin for DeepSeek Harness (DSH): it renders ```mermaid code blocks into graphics within chat messages. On the server side, the apply() function in index.js is empty, and all rendering logic is completed within the pre-built client.js. No local build is required, nor does it rely on npm to install dependencies—client.js has mermaid 11.17.2 and the plugin’s glue code embedded.

Core Features

Auto-recognition

The plugin scans for Mermaid code blocks within the conversation DOM: it checks both the code block banner and uses “first valid line” matching (skipping leading empty lines, %% comments, and YAML frontmatter).

Supported Diagram Types

The types listed in the README include: flowchart, graph TB/TD/BT/RL/LR, sequenceDiagram, classDiagram, stateDiagram(-v2), erDiagram, journey, gantt, pie, mindmap, timeline, gitGraph, quadrantChart, requirementDiagram, c4Context, sankey-beta, xychart-beta, block-beta, packet-beta, architecture-beta (20 types in total).

Graph and Source Toggle

After rendering, you can still switch back to the original code block; the host source code is hidden via CSS :has() when a rendered graph exists, rather than deleting it from the DOM.

Theme Following

It listens for changes to the DSH dark-theme attribute and reinitializes mermaid and redraws the diagrams based on dark / default.

Error Fallback

In case of syntax or rendering failures, the source code remains visible, and mermaid error messages are displayed to avoid content being silently swallowed.

Security and Incremental Rendering

Mermaid runs with securityLevel: "strict" and a transparent background. A debounced MutationObserver listens for changes in the transcript: unchanged code will not be rendered repeatedly; when a code block disappears, the corresponding rendering surface is cleaned up. When uninstalling the plugin, observers are disconnected, injected styles and all surface elements are removed.

Installation and Activation

The plugin is only applicable to DSH Web. The official README provides two methods:

  1. One-click installation via the dsh-market plugin market: Settings → Plugin Market.
  2. Or use the DSH CLI: The README specifies that this repository can be added via dsh plugin add this repository from GitHub; please refer to your local dsh plugin add --help and DSH documentation for complete parameters (the provided materials do not contain a fixed one-liner example with github:owner/repo, so we will not fabricate one here).

After installation, you must use the Web client; the dsh.client section in the manifest configures platform: web, immediately: true, and injects scripts and locale into @deepseek-ai/dsh-client-ui-conversation.

Typical Usage

In DSH chat, simply have the model (or yourself) output standard Mermaid fenced blocks; no additional configuration is needed—the package.json in the materials does not declare user-configurable plugin fields. For example, a flowchart:

```mermaid
flowchart LR
  A[Start] --> B{Decision}
  B -->|Yes| C[Process]
  B -->|No| D[End]
```

After sending or receiving a message containing the above block, the plugin will lazy-load mermaid and render the SVG within the conversation interface; you can use the graph/source toggle on the interface to view the original text. Interface text is parsed via the injected locale service, with built-in Chinese/English fallbacks (locale/zh.json, locale/en.json).

How it Works (Brief)

On the bundle side, dsh.bundle.patch in package.json points to cordis.patch.yml, inserting the module mermaid-chat into the host bundle. The client client.js is registered via window.__ModuleLoader__.load. Inside apply(ctx), it establishes a MutationObserver → detects blocks → lazy-loads mermaid → outputs SVG.

Use Cases and Notes

Suitable for: Developers or agents users who frequently read architecture descriptions, process designs, or sequence interactions containing Mermaid in DSH Web and wish to view diagrams within the same window.

Notes:

  • The plugin runs on the browser side with the permissions of the current DSH process; please read the GitHub repository source code before installation (especially the pre-built client.js, which is about 3.4 MB; do not manually reformat it).
  • Only Web platform; client.js injection logic will not load in non-Web environments.
  • The repository description advises against manually modifying client.js (build artifact); static checking can be performed with: node --check index.js && node --check client.js (the repository has no test/lint scripts).

Conclusion

dsh-mermaid-plugin transforms Mermaid in DSH chat from “source code only” to “in-place viewing, switchable to source, predictable theme and error behavior,” providing a targeted enhancement to the client conversation experience. Directory and source code:

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

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

Xiaoye