You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(cli): add --export-diagrams flag to render mermaid diagrams via local browser (finos#2634)
* feat(cli): add --export-diagrams flag to render mermaid diagrams via local browser
Adds --export-diagrams <svg|png> to docify, which post-processes generated
markdown to render mermaid code blocks into SVG/PNG images using a local
Chromium-based browser (playwright-core), with chrome/msedge auto-detection
and a --browser-path escape hatch. Rendering is opt-in and recoverable on
failure -- diagrams remain as mermaid blocks if no browser is found or a
diagram fails to render. playwright-core, mermaid, and @mermaid-js/layout-elk
are marked external in tsup configs and only loaded lazily when the flag is
used.
* docs(cli): document --export-diagrams, --browser-path, --diagram-render-timeout
Adds the new docify diagram-export options to the CLI README docify help
output and usage section, and to the working-with-calm CLI reference docs.
* fix(shared): resolve strict TS error in Docifier.renderDiagrams
this.exportDiagrams is DiagramExportFormat | undefined, and TS cannot
narrow it across the docify -> renderDiagrams call. renderDiagrams is
only invoked when exportDiagrams is set, so assert non-null.
* fix(shared): center exported diagrams and match export font to IDE rendering
Rewrite exported mermaid diagrams as centered <p align="center"><img/></p> blocks instead of plain markdown image references, and ensure the standalone SVG/PNG output uses the same font stack and sizing that calm-widgets/VS Code use for live rendering, fixing visual mismatches and oversized/clipped exports.
* fix(shared): address Copilot review feedback on diagram export
Use an explicit .md/.mdx regex (MARKDOWN_FILE_REGEX, now shared with
processDiagramsInDirectory) to decide whether --output is a file or a
directory, instead of path.extname which misclassified directories
with a dot in their name (e.g. docs/v1.2) as files.
Make MERMAID_BLOCK_REGEX tolerate CRLF line endings around mermaid
code fences, and switch the per-diagram mkdirp call to its async form
so it no longer blocks the event loop inside the render loop.
Also clarifies the MermaidBrowserRendererOptions.browser doc comment:
dispose() does close the passed-in browser.
* fix(shared): respect --verbose for diagram export logger
Docifier.renderDiagrams hardcoded initLogger(false, ...), so its debug-level logs (e.g. MermaidBrowserRenderer cleanup diagnostics) were always suppressed even when --verbose was passed. Align it with the process.env.DEBUG === 'true' pattern used by every other initLogger call in shared/src.
* test(shared): extract createMockLogger test helper
Dedupe the repeated mock Logger object literal across the docify and template-strategy specs into a shared createMockLogger() helper, and fix the loading-helpers.spec.ts mock from any to the proper Logger type. Also rename PNG_MAGIC_BYTES to PNG_SIGNATURE with a clarifying comment in the diagram-export e2e spec.
---------
Co-authored-by: Matthew Bain <66839492+rocketstack-matt@users.noreply.github.com>
Co-authored-by: LeighF <167173740+LeighFinegold@users.noreply.github.com>
Copy file name to clipboardExpand all lines: cli/README.md
+29Lines changed: 29 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -452,6 +452,9 @@ Options:
452
452
-t, --template <path> Path to a single .hbs or .md template file
453
453
-d, --template-dir <path> Path to a directory of .hbs/.md templates
454
454
-u, --url-to-local-file-mapping <path> Path to mapping file which maps URLs to local paths.
455
+
--export-diagrams <svg|png> Render mermaid diagrams to image files using a local Chromium-based browser (adds roughly 10-40s depending on diagram count).
456
+
--browser-path <path> Path to a Chromium-based browser executable, only needed if automatic detection fails.
457
+
--diagram-render-timeout <ms> Per-diagram render timeout in milliseconds, only used with --export-diagrams (default: 30000).
0 commit comments