---
id: MRKD-WP-0005
type: workplan
domain: markitect
repo: marki-docx
status: active
state_hub_workstream_id: 2ef47f11-d828-436d-8955-c58e13c50752
created: 2026-03-16
updated: 2026-03-16
---
# MRKD-WP-0005 — Diagram Renderer Integration
Complete the deferred rendering path for FR-533/534. Currently `diagrams.py` operates
in source-only mode: diagram fenced blocks are preserved as source through the round-trip
but are never rendered to images. This workstream adds actual rendering support for
Mermaid, Graphviz, and PlantUML when the corresponding CLI tools are available, while
preserving the graceful source-only fallback when they are not.
**Scope:** FR-533 (auto-diagram support), FR-534 (diagram intent preservation),
FR-538 (processor-dependency disclosure)
**Out of scope:** new diagram syntaxes beyond mermaid/graphviz/plantuml
**Depends on:** MRKD-WP-0003 (diagrams.py source-only foundation) — complete
---
## T01 — Renderer abstraction layer and detection
```task
id: MRKD-WP-0005-T01
status: todo
priority: high
state_hub_task_id: c4911ecc-1e3c-4d22-a6fb-92d1ed319274
```
Introduce a `RendererBackend` abstraction in `diagrams.py` so that each diagram type
can be rendered by a pluggable backend. The builder calls the abstraction; concrete
backends handle tool detection and subprocess invocation.
- `DiagramRenderer` protocol: `can_render(diagram_type: str) -> bool`,
`render(source: str, diagram_type: str, output_path: Path) -> RendererResult`
- `RendererResult`: `success: bool`, `output_path: Path | None`, `warning: WarningRecord | None`
- `detect_renderers() -> dict[str, DiagramRenderer]` — probe PATH for `mmdc`, `dot`,
`plantuml`; return only those found
- Builder updated to call `detect_renderers()` at build time; if a renderer is found
for the diagram type → render to PNG and embed; if not → source-only fallback +
`WarningRecord(reason="renderer-unavailable", construct=diagram_type)` (FR-538)
- Unit tests: `test_renderer_detection` — mock PATH; `test_fallback_when_no_renderer`
Deliverable: `pytest tests/test_level3_diagrams.py` still passes; renderer abstraction
in place and tested.
---
## T02 — Mermaid CLI (mmdc) integration
```task
id: MRKD-WP-0005-T02
status: todo
priority: high
state_hub_task_id: 87caa295-f466-4e2e-ba06-4b1a801ca976
```
Implement the `MermaidRenderer` backend that shells out to `mmdc` (Mermaid CLI).
- `MermaidRenderer.can_render("mermaid") -> bool`: checks `shutil.which("mmdc")`
- `MermaidRenderer.render(source, "mermaid", output_path)`:
- Write source to a temp `.mmd` file
- Run `mmdc -i -o