Implementation:7onez Cti expert Render Mermaid Render
| Knowledge Sources | |
|---|---|
| Domains | OSINT, Visualization |
| Last Updated | 2026-10-28 14:00 GMT |
Overview
Concrete tool for rendering Mermaid diagram source to SVG + PNG + PDF triple output via the pinned, sha512-verified Pele layout engine, provided by the cti-expert IntelGraph module.
Description
The render function in render_mermaid.py takes Mermaid source text and produces a triple output: SVG (vector), hi-res PNG, and optional PDF. The layout engine is Pele — a pinned, sha512-verified vendored copy, not a CDN-loaded library. The SVG is self-contained (Pele variables inlined). The PNG/PDF rasterisation uses the best available rasteriser: rsvg-convert (librsvg), chromium, or cairosvg (with a warning about missing glyph fallback on the latter).
The function detects the available rasteriser and raises a RenderError if none is found, with installation instructions. A cairosvg-specific warning fires when emoji/CJK characters are detected — cairosvg lacks per-glyph font fallback, so those characters will be missing from the PNG/PDF.
Usage
Import this when you need to:
- Render Mermaid source to SVG + PNG + PDF for report embedding.
- Produce vector figures (PDF) that stay sharp at any zoom.
- Control output scale without shrinking type (--scale raises pixel density).
Code Reference
Source Location
- Repository: cti-expert
- File: intel_engine/IntelGraph/scripts/render_mermaid.py
- Lines: L276-300 (render), L303-328 (main CLI)
Signature
def render(mmd, stem, width=0, scale=2, background="white", pdf=False):
"""Render Mermaid source to SVG + PNG (+ optional PDF) via Pele.
Returns list of output file paths. Raises RenderError if no rasteriser."""
Import
from render_mermaid import render
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| mmd | str | Yes | Mermaid source text (or .mmd file path) |
| stem | str | Yes | Output path stem (no extension) |
| width | int | No /// Layout width in px (0 = natural) | |
| scale | int | No /// PNG device scale factor (default 2) | |
| background | str | No /// Background color or "transparent" (default "white") | |
| bool | No /// Also emit <stem>.pdf (vector figure) |
Outputs
| Name | Type | Description |
|---|---|---|
| outputs | list[str] | [stem.svg, stem_hires.png, stem_thumb.png, stem.pdf?] |
Usage Examples
Render Mermaid to Triple
from render_mermaid import render
outputs = render(
mmd="graph TD\n A[Domain] --> B[Registrant]",
stem="cases/CASE-0001/report/attribution",
scale=2,
pdf=True,
)
# outputs: ["attribution.svg", "attribution_hires.png", "attribution_thumb.png", "attribution.pdf"]