Skip to content

Commit dd7f449

Browse files
committed
fix: correct PNG resolution regression and inaccurate skill docs
Fixes found in a critical review of the previous commit: - embed.ts: fix PNG resolution degradation on large diagrams. Export mode was reusing the interactive fitToContainer() scaling, which silently shrinks diagrams to fit an arbitrary viewport — a 21-node flowchart at default settings rendered at 444x1736px instead of its natural 2024x7936px. Export mode now always renders at true 1:1 scale. - render.mjs: grow the PNG viewport to the diagram's natural size as a defensive fallback; drop the fragile global-puppeteer createRequire hack in favor of one consistent local-install story. - SKILL.md/README: fix contradictory puppeteer install instructions (SKILL.md said -g, README said local — only local works with this script's ESM resolution). Remove the false "auto-installed via npx" compatibility claim. Remove allowed-tools (Claude-specific syntax, risky to pre-authorize Bash access across untested agents). Document that --width/--height only bound PNG output and never affect SVG. Also split the single diagram-guide.md into two verified reference docs, researched via web search and fact-checked against MermZen's actual renderer (not just recalled from training data): - references/style-guide.md: diagram types, node-count thresholds, direction/subgraph/shape conventions, hand-drawn-specific complexity limits, gantt/ER/sequence-diagram tips - references/syntax-guide.md: LLM-common Mermaid syntax mistakes (reserved words, keyword collisions, quoting rules, classDef support by diagram type). Several claims from initial research were verified or corrected by actually rendering test cases: confirmed `end` as a bare node ID and sequence participants named `Loop` break rendering; confirmed classDef is a hard parse error in sequenceDiagram but a silent no-op in classDiagram/erDiagram; disproved and removed an unverified claim about underscores triggering markdown italics (doesn't reproduce on this Mermaid version/config).
1 parent 553dfcd commit dd7f449

8 files changed

Lines changed: 501 additions & 166 deletions

File tree

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,12 @@ node skills/mermzen-render/scripts/render.mjs \
259259
| `--font` | `kalam` | `kalam` or `caveat` (CJK auto-uses Xiaolai SC) |
260260
| `--bg` | `transparent` | CSS color, `transparent`, or `grid` |
261261
| `--scale` | `2` | Device scale factor for PNG |
262-
| `--width` | `1400` | Viewport width (px) |
263-
| `--height` | `900` | Viewport height (px) |
264-
265-
Run `node skills/mermzen-render/scripts/render.mjs --help` for more details.
262+
| `--width` | `1400` | Minimum PNG canvas width (px); grows to fit large diagrams |
263+
| `--height` | `900` | Minimum PNG canvas height (px); grows to fit large diagrams |
264+
265+
Diagrams always render at their true 1:1 size (never shrunk to fit), so PNG
266+
resolution reflects the diagram's real size regardless of `--width`/`--height`.
267+
SVG output is always the natural vector size — `--width`/`--height`/`--scale`
268+
don't apply to it. Run `node skills/mermzen-render/scripts/render.mjs --help`
269+
for more details. For diagram styling tips and common syntax pitfalls, see
270+
[skills/mermzen-render/references/](skills/mermzen-render/references/).

README.zh.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ node skills/mermzen-render/scripts/render.mjs \
252252
| `--font` | `kalam` | `kalam``caveat`(中文自动使用小赖字体) |
253253
| `--bg` | `transparent` | CSS 颜色、`transparent``grid` |
254254
| `--scale` | `2` | PNG 设备缩放系数 |
255-
| `--width` | `1400` | 视口宽度(px) |
256-
| `--height` | `900` | 视口高度(px) |
255+
| `--width` | `1400` | PNG 画布最小宽度(px);大图会自动撑大 |
256+
| `--height` | `900` | PNG 画布最小高度(px);大图会自动撑大 |
257257
258-
运行 `node skills/mermzen-render/scripts/render.mjs --help` 查看完整用法。
258+
图表始终按真实 1:1 尺寸渲染(不会为适配小画布而被压缩),所以 PNG 分辨率取决于图表本身大小,与 `--width`/`--height` 无关;这两个参数只是设置最小画布尺寸。SVG 输出始终是矢量自然尺寸,不受 `--width`/`--height`/`--scale` 影响。运行 `node skills/mermzen-render/scripts/render.mjs --help` 查看完整用法。图表美化技巧和常见语法陷阱见 [skills/mermzen-render/references/](skills/mermzen-render/references/)
259259

skills/mermzen-render/SKILL.md

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ description: >
55
and multiple themes. Use when asked to generate, render, or export a Mermaid diagram as
66
an image file. Triggers: "render diagram", "mermaid to svg", "mermaid to png",
77
"generate diagram", "draw flowchart", "draw sequence diagram", "export diagram".
8-
compatibility: Requires Node.js 18+ and Puppeteer (auto-installed on first run via npx)
9-
allowed-tools: Bash(node *) Bash(npx *)
8+
compatibility: Requires Node.js 18+ and a local Puppeteer install (npm install puppeteer)
109
---
1110

1211
# MermZen Render
@@ -17,13 +16,19 @@ No need to clone any repository — the script uses the deployed MermZen instanc
1716

1817
## Prerequisites
1918

20-
The render script requires **Node.js 18+** and **Puppeteer**. Install Puppeteer if not
21-
already available:
19+
The render script requires **Node.js 18+** and **Puppeteer**, installed locally
20+
(not globally — a global install won't be found by this script's module
21+
resolution):
2222

2323
```bash
24-
npm install -g puppeteer
24+
npm install puppeteer
2525
```
2626

27+
Run this from your project directory (or anywhere that's an ancestor
28+
directory of wherever this skill is installed) — Node resolves `puppeteer`
29+
by walking up from the script's location, so a local install anywhere above
30+
it in the directory tree works.
31+
2732
## Usage
2833

2934
```bash
@@ -36,6 +41,15 @@ node scripts/render.mjs --code "graph TD; A-->B-->C" --output diagram.svg
3641
node scripts/render.mjs --file diagram.mmd --output output.png --format png
3742
```
3843

44+
### Workflow: render, then look at the result
45+
46+
Syntax-valid Mermaid can still render into something visually broken —
47+
clipped labels, a cramped layout, or the wrong orientation. After rendering,
48+
view the output image before reporting success. If rendering fails outright,
49+
check [references/syntax-guide.md](references/syntax-guide.md) for the likely
50+
cause, apply one targeted fix, and retry once before reporting the error to
51+
the user.
52+
3953
### Parameters
4054

4155
| Parameter | Default | Description |
@@ -50,10 +64,16 @@ node scripts/render.mjs --file diagram.mmd --output output.png --format png
5064
| `--font-size`| `16` | Font size in pixels |
5165
| `--bg` | `transparent` | CSS color, `transparent`, or `grid` |
5266
| `--scale` | `2` | Device scale factor for PNG (higher = sharper) |
53-
| `--width` | `1400` | Viewport width (px) |
54-
| `--height` | `900` | Viewport height (px) |
67+
| `--width` | `1400` | Minimum PNG canvas width (px); grows to fit large diagrams |
68+
| `--height` | `900` | Minimum PNG canvas height (px); grows to fit large diagrams |
5569
| `--base-url` | `https://eric.run.place/MermZen` | Override the MermZen instance URL |
5670

71+
`--width`/`--height`/`--scale` only affect PNG output — SVG always exports at
72+
its natural vector size. Diagrams always render at their true 1:1 size (never
73+
shrunk to fit a small canvas), so PNG resolution reflects the diagram's real
74+
size regardless of `--width`/`--height`; they only set a *minimum* canvas,
75+
useful for adding extra padding around a small diagram.
76+
5777
Run `node scripts/render.mjs --help` for the full usage info.
5878

5979
### Themes, fonts, and styles
@@ -109,15 +129,20 @@ node scripts/render.mjs \
109129
4. Extracts the SVG from the DOM or takes a PNG screenshot
110130
5. Writes the result to the output file
111131

112-
## Diagram guide
132+
## References
113133

114-
For supported diagram types, styling tips, and best practices for creating
115-
beautiful diagrams, see [references/diagram-guide.md](references/diagram-guide.md).
134+
- [references/style-guide.md](references/style-guide.md) — supported diagram
135+
types, node-count thresholds, direction/layout choices, and styling tips
136+
for making diagrams look good
137+
- [references/syntax-guide.md](references/syntax-guide.md) — reserved words,
138+
quoting rules, and other syntax pitfalls that break rendering; read this
139+
first if a render fails
116140

117141
## Troubleshooting
118142

119143
| Symptom | Fix |
120144
|---------|-----|
121-
| `Cannot find module 'puppeteer'` | Run `npm install -g puppeteer` |
145+
| `Cannot find module 'puppeteer'` | Run `npm install puppeteer` (local, not global — see Prerequisites) |
146+
| Render hangs / times out with no error | Usually a Mermaid syntax error (e.g. a reserved word, unquoted special character) — check [references/syntax-guide.md](references/syntax-guide.md) |
122147
| Timeout / blank output | Check network connectivity (the script fetches from eric.run.place) |
123148
| CJK text clipped | Re-run — font CDN may have been slow on first load |

skills/mermzen-render/references/diagram-guide.md

Lines changed: 0 additions & 134 deletions
This file was deleted.

0 commit comments

Comments
 (0)