Color mode

PlantUML

PlantUML diagram rendering for ```plantuml code blocks. Diagrams are turned into a PlantUML server image URL at build time; the build itself never talks to the network and no client JavaScript is shipped.

日本語

Usage

ts
import { defineConfig } from "@riebeckite/core";
import { plantuml } from "@riebeckite/plugin-plantuml";
 
export default defineConfig({
  // ...
  plugins: [plantuml()],
});

plantuml is also exported under the alias plantumlPlugin.

Behavior

Each ```plantuml code block is replaced with a figure.rb-plantuml whose diagram is an <img> pointing at the PlantUML server.

html
<figure class="rb-plantuml" data-plantuml data-plantuml-marker="..." data-plantuml-source="...">
  <div class="rb-plantuml__frame">
    <img class="rb-plantuml__image" src="https://www.plantuml.com/plantuml/svg/..." alt="..." loading="lazy" />
  </div>
  <details class="rb-plantuml__fallback">
    <summary>Diagram source</summary>
    <pre><code>...</code></pre>
  </details>
  <figcaption class="rb-plantuml__caption">...</figcaption>
</figure>

The caption comes from the code block title or from a %% caption: ... line in the source. Because %% is not PlantUML comment syntax, the %% caption: line is removed from the diagram source before it is encoded. When there is no caption, the <img> alternative text is PlantUML diagram. With fallback enabled the original PlantUML source is kept in a collapsible <details> element.

URL encoding

The image URL is built at build time with PlantUML's text encoding:

  1. Encode the source as UTF-8 bytes.
  2. Compress them with raw DEFLATE (RFC 1951 — no zlib header or Adler-32).
  3. Re-encode the bytes with PlantUML's custom base64 variant (alphabet 0-9A-Za-z-_, packing 3 bytes into four 6-bit characters).

The algorithm lives in src/plantuml-encoder.ts. It loads node:zlib through a dynamic import so a client bundle never pulls in a Node builtin. Encoding is fully build-time; no request is made to the PlantUML server.

Options

Option Type Default Description
server string "https://www.plantuml.com/plantuml" Base URL of the PlantUML server. http(s) only
format "svg" | "png" "svg" Requested image format
caption boolean true Show title / %% caption: as figcaption
fallback boolean true Keep the diagram source in <details>

Output HTML / CSS

The plugin ships style.css and emits stable class names: rb-plantuml, rb-plantuml__frame, rb-plantuml__image, rb-plantuml__caption, and rb-plantuml__fallback. Styling follows the --rb-color-* custom properties when present and switches to dark colors under html[data-theme="dark"], or under the prefers-color-scheme: dark system query while data-theme is absent.

Diagnostics

Encoding failures are reported with file.message(...). Diagnostics use source: "@riebeckite/plugin-plantuml" and ruleId either encoder-error (encoding failed) or empty-source (no diagram source).

Limitations

  • The configured PlantUML server must be reachable when a reader views the page. Offline readers see no diagram.
  • To self-host, point server at your own PlantUML base URL.
  • Because the build never contacts the server, diagram syntax is not validated at build time.

Exports

  • plantuml(options?) — plugin factory
  • plantumlPlugin — alias of plantuml
  • Types: PlantumlOptions, PlantumlFormat

See also

History

1 changesCollapseExpand
1 + <!-- Generated from packages/plugins/plantuml/README.md. Do not edit this page directly; edit the package README and run `pnpm docs:sync`. -->
2 +
3 + # PlantUML
4 +
5 + PlantUML diagram rendering for ` ```plantuml ` code blocks. Diagrams are turned into
6 + a PlantUML server image URL at build time; the build itself never talks to the
7 + network and no client JavaScript is shipped.
8 +
9 + [日本語](./plantuml.md)
10 +
11 + ## Usage
12 +
13 + ```ts
14 + import { defineConfig } from "@riebeckite/core";
15 + import { plantuml } from "@riebeckite/plugin-plantuml";
16 +
17 + export default defineConfig({
18 + // ...
19 + plugins: [plantuml()],
20 + });
21 + ```
22 +
23 + `plantuml` is also exported under the alias `plantumlPlugin`.
24 +
25 + ## Behavior
26 +
27 + Each ` ```plantuml ` code block is replaced with a `figure.rb-plantuml` whose
28 + diagram is an `<img>` pointing at the PlantUML server.
29 +
30 + ```html
31 + <figure class="rb-plantuml" data-plantuml data-plantuml-marker="..." data-plantuml-source="...">
32 + <div class="rb-plantuml__frame">
33 + <img class="rb-plantuml__image" src="https://www.plantuml.com/plantuml/svg/..." alt="..." loading="lazy" />
34 + </div>
35 + <details class="rb-plantuml__fallback">
36 + <summary>Diagram source</summary>
37 + <pre><code>...</code></pre>
38 + </details>
39 + <figcaption class="rb-plantuml__caption">...</figcaption>
40 + </figure>
41 + ```
42 +
43 + The caption comes from the code block `title` or from a `%% caption: ...` line in
44 + the source. Because `%%` is not PlantUML comment syntax, the `%% caption:` line is
45 + removed from the diagram source before it is encoded. When there is no caption,
46 + the `<img>` alternative text is `PlantUML diagram`. With `fallback` enabled the
47 + original PlantUML source is kept in a collapsible `<details>` element.
48 +
49 + ## URL encoding
50 +
51 + The image URL is built at build time with PlantUML's *text encoding*:
52 +
53 + 1. Encode the source as UTF-8 bytes.
54 + 2. Compress them with raw DEFLATE (RFC 1951 — no zlib header or Adler-32).
55 + 3. Re-encode the bytes with PlantUML's custom base64 variant (alphabet
56 + `0-9A-Za-z-_`, packing 3 bytes into four 6-bit characters).
57 +
58 + The algorithm lives in `src/plantuml-encoder.ts`. It loads `node:zlib` through a
59 + dynamic `import` so a client bundle never pulls in a Node builtin. Encoding is
60 + fully build-time; no request is made to the PlantUML server.
61 +
62 + ## Options
63 +
64 + | Option | Type | Default | Description |
65 + | ------ | ---- | ------- | ----------- |
66 + | `server` | `string` | `"https://www.plantuml.com/plantuml"` | Base URL of the PlantUML server. `http(s)` only |
67 + | `format` | `"svg" \| "png"` | `"svg"` | Requested image format |
68 + | `caption` | `boolean` | `true` | Show `title` / `%% caption:` as `figcaption` |
69 + | `fallback` | `boolean` | `true` | Keep the diagram source in `<details>` |
70 +
71 + ## Output HTML / CSS
72 +
73 + The plugin ships `style.css` and emits stable class names: `rb-plantuml`,
74 + `rb-plantuml__frame`, `rb-plantuml__image`, `rb-plantuml__caption`, and
75 + `rb-plantuml__fallback`. Styling follows the `--rb-color-*` custom properties
76 + when present and switches to dark colors under `html[data-theme="dark"]`, or
77 + under the `prefers-color-scheme: dark` system query while `data-theme` is
78 + absent.
79 +
80 + ## Diagnostics
81 +
82 + Encoding failures are reported with `file.message(...)`. Diagnostics use
83 + `source: "@riebeckite/plugin-plantuml"` and `ruleId` either `encoder-error`
84 + (encoding failed) or `empty-source` (no diagram source).
85 +
86 + ## Limitations
87 +
88 + - The configured PlantUML server must be reachable when a reader views the
89 + page. Offline readers see no diagram.
90 + - To self-host, point `server` at your own PlantUML base URL.
91 + - Because the build never contacts the server, diagram syntax is not validated
92 + at build time.
93 +
94 + ## Exports
95 +
96 + - `plantuml(options?)` — plugin factory
97 + - `plantumlPlugin` — alias of `plantuml`
98 + - Types: `PlantumlOptions`, `PlantumlFormat`
99 +
100 + ## See also
101 +
102 + - [Plugin guide](../reference/plugin-api.en.md)
103 +