@boneskull/typedoc-plugin-mermaid

中文文档
0.2.1发布于 2026/02/01BlueOak-1.0.0TypeScriptES Module零依赖构建来源已验证近 30 天下载 9657

TypeDoc plugin for rendering Mermaid diagrams

原始使用文档
文档目录11 节
  1. Features
  2. Install
  3. Usage
  4. Supported Diagram Types
  5. Configuration
  6. mermaidSource
  7. mermaidCdnUrl
  8. How It Works
  9. Acknowledgments
  10. Differences from the Original
  11. License

@boneskull/typedoc-plugin-mermaid

TypeDoc plugin for rendering Mermaid diagrams

This plugin transforms Mermaid code blocks in your TypeDoc documentation into rendered diagrams. It automatically adapts to TypeDoc's light and dark themes.

Features

  • Renders Mermaid diagrams from fenced code blocks
  • Automatic dark/light theme switching based on TypeDoc theme
  • Graceful fallback to plain code when JavaScript is disabled
  • Loads Mermaid from CDN or locally from your node_modules
  • Responsive diagram sizing

Install

npm install @boneskull/typedoc-plugin-mermaid -D

Usage

Add the plugin to your typedoc.json:

{
  "ignoredHighlightLanguages": ["mermaid"],
  "plugin": ["@boneskull/typedoc-plugin-mermaid"]
}

The ignoredHighlightLanguages option silences TypeDoc warnings about mermaid not being a recognized highlight language (this plugin handles it separately).

Or via command line:

typedoc --plugin @boneskull/typedoc-plugin-mermaid

Then use Mermaid code blocks in your documentation comments:

/**
 * Represents a workflow state machine.
 *
 * ```mermaid
 * stateDiagram-v2
 *   [*] --> Idle
 *   Idle --> Processing: start()
 *   Processing --> Complete: finish()
 *   Processing --> Error: fail()
 *   Complete --> [*]
 *   Error --> Idle: retry()
 * ```
 */
export class Workflow {
  // ...
}

Supported Diagram Types

Any diagram type supported by Mermaid works:

  • Flowcharts
  • Sequence diagrams
  • Class diagrams
  • State diagrams
  • Entity Relationship diagrams
  • Gantt charts
  • Pie charts
  • And more...

See the Mermaid documentation for all diagram types and syntax.

Configuration

mermaidSource

Where to load the Mermaid library from. Defaults to "cdn".

ValueDescription
"cdn"Load from a CDN URL (configured via mermaidCdnUrl)
"local"Copy mermaid's ESM bundle from node_modules to the docs output

typedoc.json:

{
  "mermaidSource": "local"
}

When using "local", you must install mermaid in your project:

npm install mermaid -D

The plugin copies mermaid's ESM entry point and chunks directory to assets/mermaid/ in your docs output. Diagram-specific code is lazy-loaded on demand, so only the diagram types you actually use are downloaded by browsers.

Use "local" when you need:

  • Offline documentation
  • Air-gapped or restricted network environments
  • Pinned mermaid versions bundled with your docs
  • Full control over the mermaid distribution

mermaidCdnUrl

URL to load the Mermaid library from. Defaults to https://unpkg.com/mermaid@latest/dist/mermaid.esm.min.mjs.

Only used when mermaidSource is "cdn" (the default).

This is useful for using alternative CDNs or self-hosting the library.

typedoc.json:

{
  "mermaidCdnUrl": "https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs"
}

Command line:

typedoc --mermaidCdnUrl "https://your-cdn.example.com/mermaid.esm.min.mjs"

How It Works

The plugin hooks into TypeDoc's HTML rendering pipeline and:

  1. Finds <pre><code class="mermaid"> blocks in the output
  2. Wraps them in a container with both dark and light themed versions
  3. Injects CSS and JavaScript to render diagrams and switch themes
  4. Preserves the original code as a fallback for non-JS environments

Diagrams are rendered client-side using the Mermaid library, loaded either from a CDN or from a local copy in your docs output (depending on mermaidSource).

Acknowledgments

This plugin is adapted from typedoc-plugin-mermaid by kamiazya.

Differences from the Original

FeatureThis Pluginkamiazya/typedoc-plugin-mermaid
TypeDoc version0.27+0.22–0.26
Rendering strategyDual dark/light diagrams with CSS switchingSingle diagram per block
Theme supportAutomatic dark/light based on TypeDoc themeManual theme configuration
@mermaid JSDoc tagNot supportedSupported
Mermaid loadingCDN or local ESM bundle with lazy chunksBundled UMD or CDN
Offline supportYes (with mermaidSource: "local")Yes (when bundled)
Configuration optionsmermaidSource, mermaidCdnUrlmermaidVersion, mermaidCdn

Why a new plugin?

The original plugin stopped working with TypeDoc 0.27+ due to breaking API changes and appears unmaintained.

License

Copyright © 2026 Christopher "boneskull" Hiller. Licensed BlueOak-1.0.0.

版本与发布记录

@boneskull/typedoc-plugin-mermaid 共发布 3 个版本,首次发布于 2026/01/10;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.1latest2026/02/019 个月前
0.2.02026/01/199 个月前
0.1.02026/01/109 个月前

关于 @boneskull/typedoc-plugin-mermaid 的常见问题

@boneskull/typedoc-plugin-mermaid 是什么?

TypeDoc plugin for rendering Mermaid diagrams

如何安装 @boneskull/typedoc-plugin-mermaid?

在项目目录运行 npm install @boneskull/typedoc-plugin-mermaid,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:typedoc(>=0.27.0 || ^0.28.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@boneskull/typedoc-plugin-mermaid 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@boneskull/typedoc-plugin-mermaid 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@boneskull/typedoc-plugin-mermaid 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@boneskull/typedoc-plugin-mermaid 可以商用吗?

@boneskull/typedoc-plugin-mermaid 使用 BlueOak-1.0.0 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@boneskull/typedoc-plugin-mermaid 的下载量有多少?

根据 npm 官方下载统计,@boneskull/typedoc-plugin-mermaid 在 2026/10/09 – 2026/11/07 这 30 天内被下载 9,657 次,日均约 322 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@boneskull/typedoc-plugin-mermaid 还在维护吗?

最新版本 0.2.1 发布于 2026/02/01(9 个月前);至今共发布 3 个版本,其中过去 12 个月发布了 3 个;首次发布于 2026/01/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。