dsh-mermaid-fence: Rendering Mermaid Fences as SVG in DSH Web Chat

Introduction

In the DeepSeek Harness (DSH) Web GUI, models frequently output Markdown code fences in their replies. If the language tag is mermaid, developers typically expect to see SVG diagrams such as flowcharts or sequence diagrams, rather than a long block of source code. While community plugins already exist to handle capabilities like lazy loading, zooming, and fullscreen viewing; if you are more concerned about minimizing network-accessible elements in the rendered result for scenarios involving “untrusted model output,” and prefer parsing only after streaming output concludes while retaining the source code upon failure, you may want to explore the client plugin introduced in this article.

What is this

dsh-mermaid-fence is released by maintainer XiaoBinGan, categorized as a Client plugin, and targets the DSH Web GUI chat interface. It renders settled (turn ended, message root node no longer has data-streaming) ```mermaid fences into SVG; fences currently streaming remain as standard code blocks without speculative parsing.

The plugin README explicitly states: this is a community package that works by rewriting the rendered conversation DOM, not an upstream built-in capability; DeepSeek Harness does not accept external PRs, and the distribution path is via GitHub repositories tagged with dsh-plugin and community directories.

Positioning compared to similar plugins (all from READMEs):

Plugin Capabilities Highlighted in README
AKS1st/dsh-mermaid Lazy loading, viewport-driven rendering, fullscreen zoom, error feedback loops, etc.
timedomain1/dsh-mermaid-renderer Diagram/source toggle, zooming, standalone viewer
dsh-mermaid-fence (This Article) Post-render SVG hardening after mermaid rendering is complete, combined with behaviors like “render only after settling” and “retain code block on failure”

If you require the interaction and viewer capabilities of the former two, the README suggests installing them preferentially; this package focuses on hardening and security boundary documentation.

Core Features

Render Only Settled Fences

The host AssistantMarkdown adds data-streaming to the message root while tokens are still arriving and removes it when the turn ends. The plugin only scans for fences that do not have a [data-streaming] ancestor. Fences currently streaming remain byte-level identical to the host’s rendering result, avoiding flickering of half-written diagrams, per-chunk reparsing, or parse errors popping up before the model has finished writing.

Four Fence States (README Behavior Table)

Fence State UI Behavior
Settled and Source is Valid SVG Diagram; toggleable to show raw source; host copy button remains functional
Settled but Source is Invalid Retain original code block and append a readable mermaid parse error (role="status")
Still Streaming Original code block, unmodified
Declared as mermaid but Not Diagram Syntax Original code block (mermaid rejects, error visible)

Source code is not lost upon parse failure, and exceptions do not propagate to the host console; failed fences are marked so subsequent scans do not repeatedly retry them.

Security: securityLevel: 'strict' and SVG Hardening

The renderer hardcodes securityLevel: 'strict' in src/render.js, and the README states this is non-configurable — fence content is model output and treated as untrusted input. The public interface exposes no securityLevel, htmlLabels toggle, or independent palette; theme colors are derived from host CSS variables (--dsw-*), and exported methods are limited to render and refreshTheme.

When strict is insufficient, the SVG returned by mermaid is further processed by src/harden.js: removing script, iframe, object, embed, img, image, audio, video, source, track; stripping all on* attributes; and discarding non-same-document fragments (#id) as well as href/xlink:href/src/srcset/data/poster/action/formaction that do not start with data:image/.

The README includes empirical tests on Chromium with mermaid 11.17.2: for example, a label <img src=x onerror=alert(1)> might leave <img src="x"> under strict, but after hardening, no img/image elements remain in the diagram; external click links lose their xlink:href after hardening, rendering anchors inert.

Boundaries you must understand: Hardening occurs after mermaid.render() completes, whereas mermaid inserts markup into the live document during output construction. README tests indicate that labels containing off-origin img might initiate a request during the render call; hardening cannot prevent this single transient fetch by mermaid during the rendering phase. What it can do is ensure that the final SVG remaining in the page DOM retains no such network-accessible elements, and prevents duplicate fetches if the same markup is inserted again.

Theme and Source Toggling

Colors are bound to the host <body>’s --dsw-* and the dark mode attribute data-ds-dark-theme; theme switches trigger a re-read of tokens and re-rendering of mounted diagrams. Each diagram retains the host code block banner (copy button accessible) and adds a toggle to view the raw fence text.

Uninstallation and Cleanup

The plugin registers resources (such as MutationObserver, debounce timers, etc.) via ctx.effect within apply, each with its own cleanup, facilitating release when the profile is removed.

Installation and Activation

The package is not published to the public npm registry (README notes a 404 for dsh-mermaid-fence), so it must be installed from Git; installation requires no build step as the repository contains the pre-built client.js.

To verify package contents in any environment, you can use:

npm install github:XiaoBinGan/dsh-mermaid-fence

In a DSH profile, the host installer adds the same specifier to the profile’s layer list:

dsh plugin --profile web add github:XiaoBinGan/dsh-mermaid-fence

The installed file tree (verified in README) is:

LICENSE  README.md  client.js  cordis.patch.yml  index.js  package.json

package.json declares dsh.bundle.patch: ./cordis.patch.yml, inserting the entry dsh-mermaid-fence into the bundle; the client injection target is @deepseek-ai/dsh-client-ui-chat on the web platform. The current package version is 0.1.0, licensed under MIT.

The plugin runs with the permissions of the current DSH process and its Web client; please review the repository source code and LICENSE yourself before installation to ensure compliance with your security and compliance requirements.

Typical Usage

In a Web GUI conversation, have the model (or you, in a message) output a standard mermaid fence. Once the turn ends and the syntax is valid, the interface will display the SVG. README Example:

graph TD
  A[Start] --> B{Choice}
  B -->|yes| C[Done]
  B -->|no| D[Stop]

During streaming generation, you will continuously see the source code block above; it transforms into a diagram only after settling. To copy the source code, use the copy button on the host banner or view the raw text via the plugin’s source toggle.

Use Cases and Caveats

Better suited for: Users already utilizing DSH Web GUI who need to view mermaid diagrams in chat and accept a client plugin with a “narrower feature set but detailed README regarding security hardening and limitations”; compared to the more feature-rich community mermaid plugins, you primarily need post-render SVG hardening and parse-after-settling semantics.

Things to note:

  1. It does not hook into the host’s internal rendering seams; it relies on DOM structure, and major host version changes may lead to fragility (README “Known limitations” direction).
  2. The security level cannot be relaxed via configuration; if a label triggers network behavior during the mermaid rendering phase, hardening cannot retroactively prevent that specific request.
  3. The community plugin directory entry on SkillHub and the GitHub repository are maintained independently and have no official affiliation with DeepSeek / High-Flyer; the DSH ecosystem emphasizes “everything is a plugin,” so installation sources should be based on trusted registries or git specifiers.

Conclusion

dsh-mermaid-fence renders settled mermaid fences in DSH Web chat into SVG, retains code blocks during the streaming phase, preserves source code and displays errors upon failure; its differentiation lies in SVG hardening on mermaid output and the empirical security boundary documentation in the README. If you require a complete experience with lazy loading and fullscreen viewers, please evaluate the two other community plugins mentioned in the README first.

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

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

Xiaoye