Skip to content

diagram

goworm edited this page Jul 3, 2026 · 1 revision

Diagram (mermaid) — pptx & docx

add --type diagram (alias flowchart) turns mermaid source into a diagram on a slide (pptx) or in the body (docx). Input mirrors equation: inline mermaid (aliases text / dsl) or a src / path .mmd file.

Like equation, diagram is an Add-only synthesizer — after add it lives as ordinary shapes / picture with no persistent diagram node (no Set/Get/Query/Remove on diagram itself). Native diagrams are wrapped in one group so they stay resizable as a unit: get /body/group[N] (docx) or the slide's group node (pptx) reads it back; set on the group x/y repositions the whole diagram.

Properties

Property Description
mermaid / text / dsl Inline mermaid source.
src / path Path to a .mmd source file. Mutually exclusive with mermaid=.
render auto (default), native, image. See below.
x / y, width / height Position and size (EMU or unit-qualified).

Render paths

Path Backend Coverage Notes
native Built-in synthesizer (Core/Diagram) flowchart + sequenceDiagram (limited subset) Zero dependencies. Emits editable native shapes + connectors. Unsupported types are rejected with a clear message.
image Real mermaid.js in a headless browser Every mermaid type (flowchart, gantt, pie, class, state, ER, …) PNG (not SVG — Office cannot draw mermaid's foreignObject HTML labels). Source is stamped into the picture's alt-text as Format["mermaid"] so the diagram travels with the file and stays regenerable. Chinese/CJK text stays intact.
auto (default) Image when a backend is available, else native Best-tool-first cascade: mmdc (mermaid-cli) → Chrome-family browser → native fallback.

Backend fetches mermaid.min.js (~3.5 MB) once to ~/.officecli/cache (own mirror, CDN fallback). The daily UpdateChecker pass revalidates with a conditional request. Mermaid syntax errors surface directly instead of failing silently.

Examples

# PPT — auto render (image if a browser or mmdc is on PATH, else native)
officecli add deck.pptx /slide[1] --type diagram \
  --prop mermaid="flowchart LR; A[Start] --> B{Ready?} --> C[Ship]; B -->|no| D[Fix]" \
  --prop x=2cm --prop y=3cm --prop width=20cm --prop height=10cm

# Word — from a .mmd file, force native so shapes stay editable
officecli add report.docx /body --type diagram --prop path=architecture.mmd --prop render=native

# Word — full-fidelity image (gantt is not in native coverage)
officecli add report.docx /body --type diagram --prop render=image \
  --prop mermaid="gantt; title Schedule; Task1: 2026-01-01, 30d; Task2: after Task1, 20d"

# Reposition a docx native diagram as one unit
officecli set report.docx /body/group[1] --prop x=3cm --prop y=6cm

See Also


Based on OfficeCLI v1.0.128

Clone this wiki locally