Skip to content

About

Plantuml rendering for Astro.

Resources

Stars

10 stars

Watchers

1 watching

Forks

Repository files navigation

astro-plantuml

An Astro integration for rendering PlantUML diagrams in your markdown files. This integration automatically converts PlantUML code blocks into beautiful diagrams using the PlantUML server.

Demo Sites

Features

  • 🎨 Automatic conversion of PlantUML code blocks to images
  • ⚡ Fast rendering using PlantUML's server
  • 🎯 Customizable server URL and timeout settings
  • 🎭 Optional CSS classes for styling
  • 🔧 Configurable language identifier for code blocks
  • 🌐 Support for custom PlantUML servers
  • 📁 Local diagram generation and caching
  • 🛠️ Built-in CLI tool for pre-generating diagrams
  • 🖼️ Support for both SVG and PNG formats
  • ✅ Astro 7 Sätteri markdown processor support (plus unified / legacy)

Installation

npx astro add astro-plantuml

Astro version compatibility

Astro Markdown engine How PlantUML hooks in
7+ Sätteri (@astrojs/markdown-satteri, the new default) a Sätteri mdast plugin
6.4 – 6.x unified() processor remark plugin via markdown.processor
< 6.4 / Astro 5 legacy pipeline top-level markdown.remarkPlugins

If you previously pinned markdown.processor to unified() purely to keep PlantUML working on Astro 7, you can drop that workaround and let Astro use its default Sätteri processor.

To stay on unified deliberately:

import { defineConfig } from 'astro/config';
import { unified } from '@astrojs/markdown-remark';
import plantuml from 'astro-plantuml';

export default defineConfig({
  markdown: {
    processor: unified(),
  },
  integrations: [plantuml()],
});

Quick Start

Check out our demo sites to see various PlantUML diagrams in action!

Usage

  1. Add the integration to your astro.config.mjs:
import { defineConfig } from 'astro/config';
import plantuml from 'astro-plantuml';

export default defineConfig({
  integrations: [plantuml()],
});
  1. Use PlantUML in your markdown files:
# My Documentation

Here's a sequence diagram:

```plantuml
@startuml
Alice -> Bob: Hello
Bob --> Alice: Hi there!
@enduml

And here's a class diagram:

@startuml
class Car {
  +String make
  +String model
  +int year
  +start()
  +stop()
  +accelerate()
}
@enduml

You can also use different themes:

@startuml
!theme plain
class User {
  +String name
  +String email
  +login()
  +logout()
}
@enduml

Diagram Generation Workflows

The integration supports two main workflows:

1. Server-Only Mode (Default)

Diagrams are generated on-demand from the PlantUML server during build time:

plantuml({
  serverUrl: 'https://www.plantuml.com/plantuml/svg/',
  format: 'svg'
})

2. Local File Mode with Fallback

Pre-generate diagrams during development, then use cached files during production builds:

plantuml({
  serverUrl: 'http://localhost:8080/svg/', // Local server for development
  format: 'svg',
  diagramsPath: 'diagrams' // Enable local file lookup
})

Pre-generating Diagrams

Use the built-in CLI tool to generate diagrams ahead of time. The CLI accepts explicit options, making it independent of your Astro configuration:

Command Line Usage

# Generate diagrams for all markdown files (SVG format, public server)
npx astro-plantuml generate

# Generate for specific files/patterns
npx astro-plantuml generate "src/pages/**/*.md"
npx astro-plantuml generate "docs/*.md"

# Generate PNG format with local server
npx astro-plantuml generate --format png --server http://localhost:8080/png/

# Generate with custom output directory
npx astro-plantuml generate --output diagrams --format svg

# Full options example
npx astro-plantuml generate "src/**/*.md" --format png --server http://localhost:8080/png/ --output diagrams --timeout 15000

CLI Options

  • --format FORMAT - Output format (svg, png) [default: svg]
  • --server URL - PlantUML server URL [default: https://www.plantuml.com/plantuml/svg/]
  • --output PATH - Output directory [default: diagrams]
  • --timeout MS - Request timeout in milliseconds [default: 10000]

Note: The CLI options are independent of your Astro integration configuration, giving you full control over diagram generation.

Integration with Build Tools

Package.json Scripts:

{
  "scripts": {
    "generate-diagrams": "astro-plantuml generate --format png --server http://localhost:8080/png/",
    "generate-diagrams:prod": "astro-plantuml generate --format svg",
    "prebuild": "npm run generate-diagrams:prod"
  }
}

Git Hooks (.git/hooks/pre-commit):

#!/bin/sh
echo "Generating PlantUML diagrams..."
npx astro-plantuml generate --format png --server http://localhost:8080/png/
git add diagrams/

GitHub Actions:

- name: Generate PlantUML diagrams
  run: npx astro-plantuml generate --format svg --output diagrams

Docker/CI environments:

# Use public server in environments without local PlantUML server
npx astro-plantuml generate --format svg --server https://www.plantuml.com/plantuml/svg/

Configuration

You can configure the integration with the following options:

With a PlantUML server:

plantuml({
  // URL of the PlantUML server (default: 'http://www.plantuml.com/plantuml/png/')
  serverUrl: 'https://your-custom-plantuml-server.com/plantuml/png/',
   
  // Timeout for HTTP requests in milliseconds (default: 10000)
  timeout: 10000,
  
  // Whether to add CSS classes to wrapper elements (default: true)
  addWrapperClasses: true,
  
  // Language identifier in code blocks (default: 'plantuml')
  language: 'plantuml',

  // Reuse HTTP connections (Keep-Alive) when requesting diagrams (default: true)
  // Set to false if a local PlantUML server fails on the second diagram on a page
  keepAlive: true
})

Using pre-generated diagrams for prod builds:

plantuml({
  // URL of the PlantUML server (default: 'http://www.plantuml.com/plantuml/svg/')
  serverUrl: 'https://your-custom-plantuml-server.com/plantuml/svg/',
  
  // Expected image format, either PNG or SVG
  format: 'svg', 
   
  // Path for storing/reading pre-generated diagrams (default: undefined)
  // When set, enables local file lookup with server fallback
  diagramsPath: process.env.NODE_ENV === 'production' ? 'diagrams' : undefined,
  
  // Timeout for HTTP requests in milliseconds (default: 10000)
  timeout: 10000,
  
  // Whether to add CSS classes to wrapper elements (default: true)
  addWrapperClasses: true,
  
  // Language identifier in code blocks (default: 'plantuml')
  language: 'plantuml',
  
  // Remove inline styles from SVG for better CSS control (default: false)
  // Only applies when format is 'svg'
  removeInlineStyles: true,

  // Reuse HTTP connections (Keep-Alive) when requesting diagrams (default: true)
  // Set to false if a local PlantUML server fails on the second diagram on a page
  keepAlive: true
})

Using a Local PlantUML Server (picoweb)

Some local PlantUML servers, such as plantuml.jar --picoweb, handle persistent (Keep-Alive) HTTP connections poorly. On a page with multiple diagrams, the second and later requests reused on the same connection can fail with a reset connection or hang. If you run into this with a local server, set keepAlive to false so each request opens a new connection:

plantuml({
  serverUrl: 'http://localhost:8080/plantuml/svg/',
  format: 'svg',
  keepAlive: false
})

Using a Custom PlantUML Server

By default, the integration uses the public PlantUML server. However, you can use your own PlantUML server by setting the serverUrl option. This is useful when you:

  • Need better performance or reliability
  • Want to avoid rate limits
  • Need to use custom themes or styles
  • Want to keep your diagrams private

Example using a custom server:

plantuml({
  serverUrl: 'https://your-custom-plantuml-server.com/plantuml/png/',
  // ... other options
})

You can set up your own PlantUML server using:

  • Docker: docker run -d -p 8080:8080 plantuml/plantuml-server:jetty
  • Java: Run the PlantUML server JAR file
  • Other deployment options as per PlantUML's documentation

CSS Styling

When addWrapperClasses is enabled (default), the integration adds the following CSS classes:

  • plantuml-diagram: Wrapper around the diagram
  • plantuml-img: The actual image element (PNG format)
  • plantuml-svg: The SVG element (SVG format)
  • plantuml-error: Error message container

You can style these in your CSS:

.plantuml-diagram {
  margin: 2rem 0;
  text-align: center;
}

.plantuml-img {
  max-width: 100%;
  height: auto;
  border: 1px solid #eee;
  border-radius: 4px;
}

.plantuml-svg {
  max-width: 100%;
  height: auto;
  border: 1px solid #eee;
  border-radius: 4px;
}

.plantuml-error {
  background: #fee;
  border: 1px solid #f99;
  padding: 1rem;
  border-radius: 4px;
  margin: 1rem 0;
}

Examples

Sequence Diagram

@startuml
participant User
participant Frontend
participant Backend
participant Database

User -> Frontend: Login Request
Frontend -> Backend: POST /api/login
Backend -> Database: Validate Credentials
Database --> Backend: User Data
Backend --> Frontend: JWT Token
Frontend --> User: Welcome Message
@enduml

Class Diagram

@startuml
class Animal {
  +String name
  +int age
  +makeSound()
  +move()
  +eat()
}

class Dog {
  +String breed
  +bark()
  +fetch()
}

class Cat {
  +String color
  +meow()
  +climb()
}

Animal <|-- Dog
Animal <|-- Cat
@enduml

Activity Diagram

@startuml
start
:User visits website;
if (Logged in?) then (yes)
  :Show dashboard;
else (no)
  :Show login form;
endif
:User interacts with site;
stop
@enduml

Error Handling

If there's an error generating a diagram, the integration will:

  1. Display an error message
  2. Keep the original code block for reference
  3. Add the plantuml-error class to the error container

Changelog

[0.2.0] - 2026-08-21

Added

  • ✅ Astro 7 Sätteri markdown processor support via a native mdast plugin
  • 🔌 Processor-aware registration: Sätteri → mdastPlugins, unified → remarkPlugins, legacy → top-level arrays
  • 📦 Expanded peerDependencies.astro to >=5.5.6

Changed

  • Shared PlantUML render helpers used by remark, Sätteri, and CLI paths

[0.1.2] - 2024-01-26

Fixed

  • 🐛 Fixed PlantUML rendering by switching from rehype to remark plugin
  • 🚀 Plugin now processes code blocks before syntax highlighting
  • 🔧 Fixed encoding issue with PlantUML server (using deflateRawSync instead of deflateSync)
  • 🧹 Removed deprecated rehype plugin

Changed

  • Remark plugin runs before Shiki to prevent language warnings

[0.1.1] - 2024-01-25

Added

  • 🎉 Initial release
  • ✨ Basic PlantUML rendering functionality
  • 🎨 Configurable options (serverUrl, timeout, addWrapperClasses, language)
  • 📚 Support for all PlantUML diagram types
  • 🔧 Error handling with fallback to original code block

[0.1.0] - 2024-01-24

Added

  • 🚀 Initial development version
  • ⚡ Core integration with Astro
  • 🎯 Basic PlantUML to image conversion

Publishing

Releases are automated with semantic-release on pushes to main (see .github/workflows/release.yml).

How it works

  1. Merge a PR to main whose commits follow Conventional Commits
  2. The release workflow builds the package and runs semantic-release
  3. If there are releasable commits (feat, fix, or breaking changes), it:
    • bumps the version in package.json
    • updates CHANGELOG.md
    • publishes to npm
    • creates a GitHub release and git tag
Commit type Release
fix: patch
feat: minor
feat!: / BREAKING CHANGE: major
chore:, docs:, ci:, test:, … none

Do not manually edit version in package.json — semantic-release owns it.

npm authentication

Publishing uses the npm_token GitHub Actions secret. Create an npm automation token at https://www.npmjs.com/settings/~/tokens and set it with:

gh secret set npm_token --repo joesaby/astro-plantuml

Workflows pass it as NODE_AUTH_TOKEN (see release.yml and npm-publish-manual.yml).

First-time setup

Before the first automated release, tag the current published version so semantic-release continues from it:

git tag v0.2.0
git push origin v0.2.0

To retry a failed npm publish without bumping the version, use Publish to npm (manual) in the Actions tab.

Demo

Visit our demo sites to see:

  • Sequence diagrams
  • Class diagrams
  • Activity diagrams
  • State diagrams
  • Component diagrams
  • Mind maps
  • Gantt charts

License

MIT

About

Plantuml rendering for Astro.

Resources

Stars

10 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages