Skip to content

PlantUML

npm versionnpm monthly downloadsnpm sizenpm license

PlantUML diagram plugin, supporting PlantUML chart rendering in Markdown.

Installation

sh
pnpm add vitepress-plugin-plantuml
sh
npm install vitepress-plugin-plantuml
sh
bun add vitepress-plugin-plantuml
sh
deno add vitepress-plugin-plantuml
sh
yarn add vitepress-plugin-plantuml

Usage

.vitepress/config.ts
ts
import { defineConfig } from 'vitepress-tuck'
import plantuml from 'vitepress-plugin-plantuml'

export default defineConfig({
  plugins: [
    plantuml(),
  ],
})

Learn more about vitepress-tuck

Native Mode

.vitepress/config.ts
ts
import { defineConfig } from 'vitepress'
import { plantumlMarkdownPlugin, plantumlVitePlugin } from 'vitepress-plugin-plantuml'

export default defineConfig({
  vite: {
    plugins: [plantumlVitePlugin()],
  },
  markdown: {
    config: (md) => {
      md.use(plantumlMarkdownPlugin)
    },
    languageAlias: { plantuml: 'txt' },
  },
})
.vitepress/theme/index.ts
ts
import type { Theme } from 'vitepress'
import { enhanceAppWithPlantuml } from 'vitepress-plugin-plantuml/client'
import DefaultTheme from 'vitepress/theme'

export default {
  extends: DefaultTheme,
  enhanceApp(ctx) {
    enhanceAppWithPlantuml(ctx)
  },
} satisfies Theme

Syntax

Use code blocks with the plantuml language tag:

md
```plantuml
@startuml
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
@enduml
```

Output Format

The plugin supports svg (default) and png output formats. You can specify the format per diagram:

md
```plantuml png
@startuml
class Example {
  +attribute: string
  +method(): void
}
@enduml
```

Or set a global default:

ts
plantuml({ format: 'png' }) // default is 'svg'

Configuration

PlantumlPluginOptions

ts
interface PlantumlPluginOptions {
  /**
   * Output format, 'svg' | 'png'
   * @default 'svg'
   */
  format?: PlantumlFormat

  /**
   * PlantUML server URL
   * @default 'https://www.plantuml.com/plantuml'
   */
  serverURL?: string
}

Features

  • Dark / Light mode — Automatically generates both dark and light diagram variants, following the VitePress theme
  • Chart / Source tabs — Toggle between the rendered diagram and its PlantUML source code
  • Fullscreen mode — Click the fullscreen button to view the diagram in an overlay
  • Download — Download the current diagram as an image file
  • Multi-language — Built-in support for English, Chinese, Japanese, Korean, Spanish, French, Russian, German, and Portuguese
  • SVG optimization — SVGs are automatically optimized via SVGO, removing redundant styles and background layers
  • Build caching — Rendered diagrams are cached to disk for faster incremental builds

Built-in Languages

The plugin includes built-in support for the following languages:

  • English (en, en-US)
  • 简体中文 (zh, zh-CN)
  • 日本語 (ja)
  • 한국어 (ko)
  • Español (es)
  • Français (fr)
  • Русский (ru)
  • Deutsch (de)
  • Português (pt)

Examples

Sequence Diagram

PlantUML lightPlantUML dark
NaN%

Use Case Diagram

PlantUML lightPlantUML dark
NaN%

Class Diagram

PlantUML lightPlantUML dark
NaN%

Activity Diagram

PlantUML lightPlantUML dark
NaN%

Released under the MIT License