The article owns the declaration; the build owns rendering; the reader gets the image.

One image section describes both the output and its recipe

The blog models a diagram as an ordinary deep-dive image section with extra build metadata. The top-level lightSrc and darkSrc fields are the static site paths that the rendered article will reference. The diagram object names the renderer and supplies the source for each variant; Mermaid can also receive a different theme JSON file for each pass. Width, height, alt text, and caption are still ordinary image-section data.

This keeps the publishing contract visible in articles.yaml. The article has one section in the reading flow, even though the build creates two SVG files. It is not a code section, and its PlantUML or Mermaid source is not emitted to the browser. The source files remain beside the article's other assets so they can be reviewed and rebuilt.

- type: image
  lightSrc: articles/2026/10/diagrams/example/example-light.svg
  darkSrc: articles/2026/10/diagrams/example/example-dark.svg
  diagram:
    format: mermaid
    light:
      source: articles/2026/10/diagrams/example/example.mmd
      theme: articles/2026/10/diagrams/example/theme-light.json
    dark:
      source: articles/2026/10/diagrams/example/example.mmd
      theme: articles/2026/10/diagrams/example/theme-dark.json
  width: 1100
  height: 520
  alt:
    en: A flow diagram of the example build
    es: Un diagrama de flujo de la compilación de ejemplo
  caption:
    en: Rendered before the page is published.
    es: Renderizado antes de publicar la página.

The builder asks for each picture separately

Blog.Build loads the article source and calls blog.article.Diagrams.try-prepare-diagrams before it renders the article HTML. That module walks the deep-dive sections and acts only on image sections with diagram metadata. For each such section it resolves the light source and output, then the dark source and output, into local article paths and issues one renderer request for each variant.

The renderer is selected by diagram.format. The framework's os.shell.tools.plantuml wrapper calls the PlantUML shim to make SVG output. The os.shell.tools.mermaid wrapper calls mmdc with an explicit input, output, theme file, transparent background, and Puppeteer configuration. Both wrappers use the framework process component and retain the command, stdout, stderr, and error context when the tool fails. The blog coordinates the diagram declaration; the framework owns the reusable command wrappers.

One detail matters for PlantUML: the wrapper gives PlantUML an output directory and a source path, so PlantUML derives the SVG filename from the source basename. Keep the source and declared output basenames aligned. Mermaid accepts its output path explicitly. The article paths for both tools still share the same validation rule: local site paths begin with articles/ and cannot escape with parent segments or switch to an absolute or drive path.

The diagram build sequence shows Blog.Build preparing each light and dark variant, recording renderer errors, copying assets, and rendering a theme-aware image component.The diagram build sequence shows Blog.Build preparing each light and dark variant, recording renderer errors, copying assets, and rendering a theme-aware image component.
A failure in one render request is recorded on the section while the build continues.

Failures belong to the diagram section

The diagram preparer catches errors independently around the light and dark render requests. It records each full error string on the prepared section and still attempts the other variant. A missing tool, invalid source, or renderer error therefore does not turn the entire article build into an HTTP-style failure. The rest of the article and site can still be generated.

The image component checks that render-error field. If either variant failed, it emits an escaped preformatted diagnostic with role status and preserves the caption. It does not show a misleading half-pair by displaying the successful color while silently missing the other. This gives the author the complete cause chain in the preview and makes a broken diagram visible in place.

Once diagram preparation finishes, Blog.Build renders article pages, writes the rest of the preview, and recursively copies the article asset tree into the preview's articles directory. Source files, theme JSON, and generated SVGs stay together as project assets; only the image paths appear in the article HTML. A published reader requests static files and never starts PlantUML, Node, Puppeteer, or a diagram renderer.

Keep syntax highlighting out of the rendering path

The blog also has PEG grammars for PlantUML and Mermaid source. Those grammars classify source tokens when a code section asks for syntax highlighting. They are independent of diagram rendering: a grammar cannot create an SVG, and a diagram image section does not need a syntax highlighter. That separation lets an article include a true picture without publishing its source as an editable code sample.