prettier-plugin-mmd 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.ja.md +278 -0
- package/README.md +236 -0
- package/lib/index.d.mts +172 -0
- package/lib/index.mjs +12648 -0
- package/package.json +29 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yosuke Ota
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.ja.md
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
# prettier-plugin-mmd
|
|
2
|
+
|
|
3
|
+
英語版: [README.md](./README.md)
|
|
4
|
+
|
|
5
|
+
Mermaid の図を整形する [Prettier](https://prettier.io/) プラグインです。
|
|
6
|
+
`.mmd` と `.mermaid` のファイルと、
|
|
7
|
+
Markdown の中の `mermaid` のコードブロックを整形します。
|
|
8
|
+
|
|
9
|
+
mermaid-js とは関係のない第三者のプロジェクトです。
|
|
10
|
+
ここでいう `mmd` は Mermaid の図の記法のことで、
|
|
11
|
+
MultiMarkdown や MikuMikuDance ではありません。
|
|
12
|
+
|
|
13
|
+
## Playground
|
|
14
|
+
|
|
15
|
+
ブラウザーで、このプラグインによる整形結果を確認できます。
|
|
16
|
+
**Formatted**タブは編集に合わせて更新され、
|
|
17
|
+
**Indent**と**Use tabs**で字下げを設定できます。
|
|
18
|
+
**Apply to source**で、入力を整形結果に置き換えられます。
|
|
19
|
+
|
|
20
|
+
公開URL: [Playground](https://mmd-toolkit.github.io/mmd-toolkit/playground/)。
|
|
21
|
+
|
|
22
|
+
操作方法は[Playgroundの使い方](../playground/README.ja.md)を参照してください。
|
|
23
|
+
|
|
24
|
+
## 導入
|
|
25
|
+
|
|
26
|
+
Prettier 3 と一緒に入れます。
|
|
27
|
+
Node.js `^20.19.0 || ^22.13.0 || >=24` が必要です。
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
npm install --save-dev prettier prettier-plugin-mmd
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
そのうえで、Prettier の設定に加えます。
|
|
34
|
+
Prettier 3 はプラグインを自分では見つけないので、この指定が必要です。
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"plugins": ["prettier-plugin-mmd"]
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
あとは、
|
|
43
|
+
いつもどおり Prettier で Mermaid のファイルと Markdown のファイルを整形します。
|
|
44
|
+
たとえば:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
npx prettier --write "**/*.{mmd,mermaid,md}"
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## 例
|
|
51
|
+
|
|
52
|
+
入力
|
|
53
|
+
([statements-one-per-line/separated-by-semicolons-input.mmd](./tests/fixtures/flowchart/statements-one-per-line/separated-by-semicolons-input.mmd)):
|
|
54
|
+
|
|
55
|
+
```mmd
|
|
56
|
+
flowchart LR
|
|
57
|
+
A --> B; B --> C; C --> D
|
|
58
|
+
subgraph S; E; F; end
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
出力
|
|
62
|
+
([statements-one-per-line/separated-by-semicolons-output.mmd](./tests/fixtures/flowchart/statements-one-per-line/separated-by-semicolons-output.mmd)):
|
|
63
|
+
|
|
64
|
+
```mmd
|
|
65
|
+
flowchart LR
|
|
66
|
+
A --> B
|
|
67
|
+
B --> C
|
|
68
|
+
C --> D
|
|
69
|
+
subgraph S
|
|
70
|
+
E
|
|
71
|
+
F
|
|
72
|
+
end
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## 整形するもの
|
|
76
|
+
|
|
77
|
+
- 名前が `.mmd` か `.mermaid` で終わるファイル。
|
|
78
|
+
- Markdown の、情報文字列の最初の語が `mermaid` か `mmd` のコードブロック。
|
|
79
|
+
大文字と小文字を区別するので、`Mermaid` は整形しません。
|
|
80
|
+
`mermaidx` も整形しません。
|
|
81
|
+
- flowchart。
|
|
82
|
+
`flowchart`、`graph`、`flowchart-elk`、`swimlane-beta` で始まる図です。
|
|
83
|
+
整形の規則は、
|
|
84
|
+
例とともに [docs/flowchart.ja.md](./docs/flowchart.ja.md) にあります。
|
|
85
|
+
- agentflow。
|
|
86
|
+
`agentflow-beta`で始まる図です。
|
|
87
|
+
整形規則と例は[docs/agentflow.ja.md](./docs/agentflow.ja.md)にあります。
|
|
88
|
+
- sequence 図。
|
|
89
|
+
`sequenceDiagram` で始まる図です。
|
|
90
|
+
整形の規則は、
|
|
91
|
+
例とともに [docs/sequence.ja.md](./docs/sequence.ja.md) にあります。
|
|
92
|
+
- class 図。
|
|
93
|
+
`classDiagram` か `classDiagram-v2` で始まる図です。
|
|
94
|
+
整形の規則は、例とともに [docs/class.ja.md](./docs/class.ja.md) にあります。
|
|
95
|
+
- state 図。
|
|
96
|
+
`stateDiagram` か `stateDiagram-v2` で始まる図です。
|
|
97
|
+
整形の規則は、例とともに [docs/state.ja.md](./docs/state.ja.md) にあります。
|
|
98
|
+
- ER 図。
|
|
99
|
+
`erDiagram` で始まる図です。
|
|
100
|
+
整形の規則は、例とともに [docs/er.ja.md](./docs/er.ja.md) にあります。
|
|
101
|
+
- Gantt 図。
|
|
102
|
+
`gantt` で始まる図です。
|
|
103
|
+
整形の規則は、例とともに [docs/gantt.ja.md](./docs/gantt.ja.md) にあります。
|
|
104
|
+
- journey 図。
|
|
105
|
+
`journey` で始まる図です。
|
|
106
|
+
整形の規則は、
|
|
107
|
+
例とともに [docs/journey.ja.md](./docs/journey.ja.md) にあります。
|
|
108
|
+
- requirement 図。
|
|
109
|
+
`requirementDiagram` で始まる図です。
|
|
110
|
+
整形の規則は、
|
|
111
|
+
例とともに [docs/requirement.ja.md](./docs/requirement.ja.md) にあります。
|
|
112
|
+
- mindmap。
|
|
113
|
+
`mindmap` で始まる図です。
|
|
114
|
+
整形の規則は、
|
|
115
|
+
例とともに [docs/mindmap.ja.md](./docs/mindmap.ja.md) にあります。
|
|
116
|
+
- timeline。
|
|
117
|
+
`timeline` で始まる図です。
|
|
118
|
+
整形の規則は、
|
|
119
|
+
例とともに [docs/timeline.ja.md](./docs/timeline.ja.md) にあります。
|
|
120
|
+
- sankey 図。
|
|
121
|
+
`sankey` か `sankey-beta` で始まる図です。
|
|
122
|
+
整形の規則は、例とともに [docs/sankey.ja.md](./docs/sankey.ja.md) にあります。
|
|
123
|
+
- XY チャート。
|
|
124
|
+
`xychart` か `xychart-beta` で始まる図です。
|
|
125
|
+
整形の規則は、
|
|
126
|
+
例とともに [docs/xychart.ja.md](./docs/xychart.ja.md) にあります。
|
|
127
|
+
- 象限チャート。
|
|
128
|
+
`quadrantChart` で始まる図です。
|
|
129
|
+
整形の規則は、
|
|
130
|
+
例とともに [docs/quadrant.ja.md](./docs/quadrant.ja.md) にあります。
|
|
131
|
+
- kanban。
|
|
132
|
+
`kanban` で始まる図です。
|
|
133
|
+
整形の規則は、例とともに [docs/kanban.ja.md](./docs/kanban.ja.md) にあります。
|
|
134
|
+
- C4 図。
|
|
135
|
+
`C4Context`、`C4Container`、`C4Component`、`C4Dynamic`、
|
|
136
|
+
`C4Deployment` で始まる図です。
|
|
137
|
+
整形の規則は、例とともに [docs/c4.ja.md](./docs/c4.ja.md) にあります。
|
|
138
|
+
- Venn 図。
|
|
139
|
+
`venn-beta` で始まる図です。
|
|
140
|
+
整形の規則は、例とともに [docs/venn.ja.md](./docs/venn.ja.md) にあります。
|
|
141
|
+
- Ishikawa 図。
|
|
142
|
+
`ishikawa` と `ishikawa-beta` で始まる図で、
|
|
143
|
+
受理する大文字小文字の表記も扱います。
|
|
144
|
+
整形の規則は [docs/ishikawa.ja.md](./docs/ishikawa.ja.md) にあります。
|
|
145
|
+
- Usecase 図。
|
|
146
|
+
`usecase-beta` で始まる図です。
|
|
147
|
+
整形の規則は [docs/usecase.ja.md](./docs/usecase.ja.md) にあります。
|
|
148
|
+
- Pie 図。
|
|
149
|
+
`pie` で始まる図で、`showData` も扱います。
|
|
150
|
+
整形の規則は [docs/pie.ja.md](./docs/pie.ja.md) にあります。
|
|
151
|
+
- Info 図。
|
|
152
|
+
`info` で始まる図で、`showInfo` も扱います。
|
|
153
|
+
整形の規則は [docs/info.ja.md](./docs/info.ja.md) にあります。
|
|
154
|
+
- Git graph。
|
|
155
|
+
`gitGraph` で始まる図です。
|
|
156
|
+
整形の規則は [docs/gitgraph.ja.md](./docs/gitgraph.ja.md) にあります。
|
|
157
|
+
- architecture 図: `architecture-beta` で始まる図です。
|
|
158
|
+
整形の規則は [docs/architecture.ja.md](./docs/architecture.ja.md) にあります。
|
|
159
|
+
- treemap 図: `treemap` と `treemap-beta` で始まる図です。
|
|
160
|
+
整形の規則は [docs/treemap.ja.md](./docs/treemap.ja.md) にあります。
|
|
161
|
+
- treeview 図: `treeView-beta` で始まる図です。
|
|
162
|
+
整形の規則は [docs/treeview.ja.md](./docs/treeview.ja.md) にあります。
|
|
163
|
+
- radar 図: `radar-beta` で始まる図です。
|
|
164
|
+
整形の規則は [docs/radar.ja.md](./docs/radar.ja.md) にあります。
|
|
165
|
+
- Wardley 図: `wardley-beta` で始まる図です。
|
|
166
|
+
整形の規則は [docs/wardley.ja.md](./docs/wardley.ja.md) にあります。
|
|
167
|
+
- railroad 図: `railroad-beta`、`railroad-ebnf-beta`、 `railroad-abnf-beta`、
|
|
168
|
+
`railroad-peg-beta` で始まる図です。
|
|
169
|
+
整形の規則は [docs/railroad.ja.md](./docs/railroad.ja.md) にあります。
|
|
170
|
+
- cynefin 図: `cynefin-beta` と `cynefin-beta:` で始まる図です。
|
|
171
|
+
整形の規則は [docs/cynefin.ja.md](./docs/cynefin.ja.md) にあります。
|
|
172
|
+
- eventmodeling 図: `eventmodeling` で始まる図です。
|
|
173
|
+
規則は [docs/eventmodeling.ja.md](./docs/eventmodeling.ja.md) にあります。
|
|
174
|
+
- packet 図: `packet` と `packet-beta` で始まる図です。
|
|
175
|
+
整形の規則は [docs/packet.ja.md](./docs/packet.ja.md) にあります。
|
|
176
|
+
- ブロック図。
|
|
177
|
+
`block-beta` か `block` で始まる図です。
|
|
178
|
+
整形の規則は、例とともに [docs/block.ja.md](./docs/block.ja.md) にあります。
|
|
179
|
+
- これらの図の YAML のフロントマター。
|
|
180
|
+
Prettier の YAML 整形で整形します。
|
|
181
|
+
|
|
182
|
+
## オプション
|
|
183
|
+
|
|
184
|
+
- `useTabs` と `tabWidth` で字下げを決めます。
|
|
185
|
+
既定は空白 2 つです。
|
|
186
|
+
- `endOfLine` で改行コードを決めます。
|
|
187
|
+
- `printWidth` は効きません。
|
|
188
|
+
行を折り返すことはありません。
|
|
189
|
+
|
|
190
|
+
## 整形しない場合
|
|
191
|
+
|
|
192
|
+
- mermaid.js が拒否するテキストは変えません。
|
|
193
|
+
ファイルでは、Prettier が構文エラーを報告し、ファイルはそのまま残ります。
|
|
194
|
+
Markdown では、コードブロックを Prettier に任せ、
|
|
195
|
+
Prettier は整形しないコードとして印字します。
|
|
196
|
+
- mermaid.js が受理する入力の一部も、構文エラーとして報告します。
|
|
197
|
+
たとえば、`sub%%{init: {}}%%graph S` のように、
|
|
198
|
+
キーワードの中にディレクティブがある場合です。
|
|
199
|
+
また、`subgraph Handle click events` のように、
|
|
200
|
+
click 文を始めない `click` がある場合です。
|
|
201
|
+
flowchart では、`click` は予約語です。
|
|
202
|
+
`A-->|x""|B` のように、トークンの間に空の文字列がある場合もそうです。
|
|
203
|
+
一覧は [docs/compatibility.ja.md](./docs/compatibility.ja.md) にあります。
|
|
204
|
+
- mermaid.js の `error` 擬似図は変えません。
|
|
205
|
+
`error` という語と、
|
|
206
|
+
その周りのコメント・ディレクティブ・改行だけでできたテキストです。
|
|
207
|
+
ただし、改行コードは `endOfLine` に従います。
|
|
208
|
+
Markdown では、Prettier に任せます。
|
|
209
|
+
|
|
210
|
+
## 保証と制限
|
|
211
|
+
|
|
212
|
+
- 整形で図は変わりません。
|
|
213
|
+
mermaid.js は、整形の前と後で同じ図を読みます。
|
|
214
|
+
- 例外が 1 つあります。
|
|
215
|
+
`style`、`classDef`、`linkStyle` の行の末尾の空白を取り除きます。
|
|
216
|
+
mermaid.js は、その空白を最後のスタイルの末尾に残します。
|
|
217
|
+
- 整形した図をもう一度整形しても、何も変わりません。
|
|
218
|
+
- ディレクティブ、不透明な `@{ ... }` のデータブロック、
|
|
219
|
+
フロントマターの中身は検査しません。
|
|
220
|
+
その中身のために mermaid.js が拒否する図も整形します。
|
|
221
|
+
ディレクティブとデータブロックは書かれたまま残し、
|
|
222
|
+
フロントマターは Prettier が YAML として読めるときだけ整形します。
|
|
223
|
+
usecase の native metadata は構文として解析し、プロパティを検証します。
|
|
224
|
+
- mermaid.js が許すより多くの辺を持つ flowchart は、mermaid.js は拒否しますが、
|
|
225
|
+
ここでは整形します。
|
|
226
|
+
許す数は、サイト設定の `maxEdges` で、既定で 500 本です。
|
|
227
|
+
プラグインはサイト設定を知らないからです。
|
|
228
|
+
- フロントマターの前のバイト順マークを、mermaid.js と同じようには扱いません。
|
|
229
|
+
mermaid.js が受理する図を構文エラーとして報告することと、
|
|
230
|
+
拒否する図を整形することがあります。
|
|
231
|
+
- Markdown では、
|
|
232
|
+
Prettier がすべてのコードブロックの最後の行の末尾の空白を取り除きます。
|
|
233
|
+
`style A fill:#f00, ` のように mermaid.js がその空白を読む箇所では、
|
|
234
|
+
図が変わります。
|
|
235
|
+
|
|
236
|
+
理由と詳細は [docs/compatibility.ja.md](./docs/compatibility.ja.md) にあります。
|
|
237
|
+
|
|
238
|
+
## 文書
|
|
239
|
+
|
|
240
|
+
- [docs/flowchart.ja.md](./docs/flowchart.ja.md): flowchart の整形の規則。
|
|
241
|
+
- [docs/agentflow.ja.md](./docs/agentflow.ja.md): agentflow の整形の規則。
|
|
242
|
+
- [docs/sequence.ja.md](./docs/sequence.ja.md): sequence 図の整形の規則。
|
|
243
|
+
- [docs/class.ja.md](./docs/class.ja.md): class 図の整形の規則。
|
|
244
|
+
- [docs/state.ja.md](./docs/state.ja.md): state 図の整形の規則。
|
|
245
|
+
- [docs/er.ja.md](./docs/er.ja.md): ER 図の整形の規則。
|
|
246
|
+
- [docs/gantt.ja.md](./docs/gantt.ja.md): Gantt 図の整形の規則。
|
|
247
|
+
- [docs/journey.ja.md](./docs/journey.ja.md): journey 図の整形の規則。
|
|
248
|
+
- [docs/requirement.ja.md](./docs/requirement.ja.md): requirement
|
|
249
|
+
図の整形の規則。
|
|
250
|
+
- [docs/mindmap.ja.md](./docs/mindmap.ja.md): mindmap の整形の規則。
|
|
251
|
+
- [docs/timeline.ja.md](./docs/timeline.ja.md): timeline の整形の規則。
|
|
252
|
+
- [docs/sankey.ja.md](./docs/sankey.ja.md): sankey 図の整形の規則。
|
|
253
|
+
- [docs/xychart.ja.md](./docs/xychart.ja.md): XY チャートの整形の規則。
|
|
254
|
+
- [docs/quadrant.ja.md](./docs/quadrant.ja.md): 象限チャートの整形の規則。
|
|
255
|
+
- [docs/kanban.ja.md](./docs/kanban.ja.md): kanban の整形の規則。
|
|
256
|
+
- [docs/c4.ja.md](./docs/c4.ja.md): C4 図の整形の規則。
|
|
257
|
+
- [docs/venn.ja.md](./docs/venn.ja.md): Venn 図の整形の規則。
|
|
258
|
+
- [docs/ishikawa.ja.md](./docs/ishikawa.ja.md): Ishikawa 図の整形の規則。
|
|
259
|
+
- [docs/usecase.ja.md](./docs/usecase.ja.md): usecase 図の整形の規則。
|
|
260
|
+
- [docs/pie.ja.md](./docs/pie.ja.md): pie 図の整形の規則。
|
|
261
|
+
- [docs/info.ja.md](./docs/info.ja.md): info の整形の規則。
|
|
262
|
+
- [docs/gitgraph.ja.md](./docs/gitgraph.ja.md): gitgraph の整形の規則。
|
|
263
|
+
- [docs/architecture.ja.md](./docs/architecture.ja.md): architecture
|
|
264
|
+
図の整形の規則。
|
|
265
|
+
- [docs/treemap.ja.md](./docs/treemap.ja.md): treemap 図の整形の規則。
|
|
266
|
+
- [docs/treeview.ja.md](./docs/treeview.ja.md): treeview 図の整形の規則。
|
|
267
|
+
- [docs/radar.ja.md](./docs/radar.ja.md): radar 図の整形の規則。
|
|
268
|
+
- [docs/wardley.ja.md](./docs/wardley.ja.md): Wardley 図の整形の規則。
|
|
269
|
+
- [docs/railroad.ja.md](./docs/railroad.ja.md): railroad 図の整形の規則。
|
|
270
|
+
- [docs/cynefin.ja.md](./docs/cynefin.ja.md): cynefin 図の整形規則。
|
|
271
|
+
- [docs/eventmodeling.ja.md](./docs/eventmodeling.ja.md): eventmodeling
|
|
272
|
+
図の整形規則。
|
|
273
|
+
- [docs/packet.ja.md](./docs/packet.ja.md): packet 図の整形の規則。
|
|
274
|
+
- [docs/block.ja.md](./docs/block.ja.md): ブロック図の整形の規則。
|
|
275
|
+
- [docs/compatibility.ja.md](./docs/compatibility.ja.md): mermaid.js
|
|
276
|
+
と違う箇所と、その理由。
|
|
277
|
+
- [docs/development.ja.md](./docs/development.ja.md): テストと fixture。
|
|
278
|
+
プラグインを開発する人向けです。
|
package/README.md
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# prettier-plugin-mmd
|
|
2
|
+
|
|
3
|
+
Japanese version: [README.ja.md](./README.ja.md)
|
|
4
|
+
|
|
5
|
+
A [Prettier](https://prettier.io/) plugin that formats Mermaid diagrams: `.mmd`
|
|
6
|
+
and `.mermaid` files, and `mermaid` code blocks in Markdown.
|
|
7
|
+
|
|
8
|
+
This is a third-party project, not affiliated with mermaid-js. `mmd` here means
|
|
9
|
+
the Mermaid diagram syntax, not MultiMarkdown or MikuMikuDance.
|
|
10
|
+
|
|
11
|
+
## Playground
|
|
12
|
+
|
|
13
|
+
Preview this plugin's formatting in the browser. The **Formatted** tab updates
|
|
14
|
+
as you edit, with **Indent** and **Use tabs** controls. Use **Apply to source**
|
|
15
|
+
to replace the input with the result.
|
|
16
|
+
|
|
17
|
+
Public URL: [Playground](https://mmd-toolkit.github.io/mmd-toolkit/playground/).
|
|
18
|
+
|
|
19
|
+
For usage, see the [Playground guide](../playground/README.md).
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
Install it next to Prettier 3. It needs Node.js `^20.19.0 || ^22.13.0 || >=24`.
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
npm install --save-dev prettier prettier-plugin-mmd
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Then add it to your Prettier configuration. Prettier 3 does not find plugins by
|
|
30
|
+
itself, so this entry is required:
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"plugins": ["prettier-plugin-mmd"]
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Prettier then formats Mermaid files and Markdown files as usual, for example:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
npx prettier --write "**/*.{mmd,mermaid,md}"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Example
|
|
45
|
+
|
|
46
|
+
Input
|
|
47
|
+
([statements-one-per-line/separated-by-semicolons-input.mmd](./tests/fixtures/flowchart/statements-one-per-line/separated-by-semicolons-input.mmd)):
|
|
48
|
+
|
|
49
|
+
```mmd
|
|
50
|
+
flowchart LR
|
|
51
|
+
A --> B; B --> C; C --> D
|
|
52
|
+
subgraph S; E; F; end
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Output
|
|
56
|
+
([statements-one-per-line/separated-by-semicolons-output.mmd](./tests/fixtures/flowchart/statements-one-per-line/separated-by-semicolons-output.mmd)):
|
|
57
|
+
|
|
58
|
+
```mmd
|
|
59
|
+
flowchart LR
|
|
60
|
+
A --> B
|
|
61
|
+
B --> C
|
|
62
|
+
C --> D
|
|
63
|
+
subgraph S
|
|
64
|
+
E
|
|
65
|
+
F
|
|
66
|
+
end
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## What is formatted
|
|
70
|
+
|
|
71
|
+
- Files ending in `.mmd` or `.mermaid`.
|
|
72
|
+
- Markdown code blocks whose info string has `mermaid` or `mmd` as its first
|
|
73
|
+
word. The match is case-sensitive: `Mermaid` and `mermaidx` are not formatted.
|
|
74
|
+
- Flowcharts: diagrams that start with `flowchart`, `graph`, `flowchart-elk`, or
|
|
75
|
+
`swimlane-beta`. The formatting rules, with examples, are in
|
|
76
|
+
[docs/flowchart.md](./docs/flowchart.md).
|
|
77
|
+
- Agentflow: diagrams that start with `agentflow-beta`. The formatting rules,
|
|
78
|
+
with examples, are in [docs/agentflow.md](./docs/agentflow.md).
|
|
79
|
+
- Sequence diagrams: diagrams that start with `sequenceDiagram`. The formatting
|
|
80
|
+
rules, with examples, are in [docs/sequence.md](./docs/sequence.md).
|
|
81
|
+
- Class diagrams: diagrams that start with `classDiagram` or `classDiagram-v2`.
|
|
82
|
+
The formatting rules, with examples, are in [docs/class.md](./docs/class.md).
|
|
83
|
+
- State diagrams: diagrams that start with `stateDiagram` or `stateDiagram-v2`.
|
|
84
|
+
The formatting rules, with examples, are in [docs/state.md](./docs/state.md).
|
|
85
|
+
- ER diagrams: diagrams that start with `erDiagram`. The formatting rules, with
|
|
86
|
+
examples, are in [docs/er.md](./docs/er.md).
|
|
87
|
+
- Gantt charts: diagrams that start with `gantt`. The formatting rules, with
|
|
88
|
+
examples, are in [docs/gantt.md](./docs/gantt.md).
|
|
89
|
+
- User journeys: diagrams that start with `journey`. The formatting rules, with
|
|
90
|
+
examples, are in [docs/journey.md](./docs/journey.md).
|
|
91
|
+
- Requirement diagrams: diagrams that start with `requirementDiagram`. The
|
|
92
|
+
formatting rules, with examples, are in
|
|
93
|
+
[docs/requirement.md](./docs/requirement.md).
|
|
94
|
+
- Mindmaps: diagrams that start with `mindmap`. The formatting rules, with
|
|
95
|
+
examples, are in [docs/mindmap.md](./docs/mindmap.md).
|
|
96
|
+
- Timelines: diagrams that start with `timeline`. The formatting rules, with
|
|
97
|
+
examples, are in [docs/timeline.md](./docs/timeline.md).
|
|
98
|
+
- Sankey diagrams: diagrams that start with `sankey` or `sankey-beta`. The
|
|
99
|
+
formatting rules, with examples, are in [docs/sankey.md](./docs/sankey.md).
|
|
100
|
+
- XY charts: diagrams that start with `xychart` or `xychart-beta`. The
|
|
101
|
+
formatting rules, with examples, are in [docs/xychart.md](./docs/xychart.md).
|
|
102
|
+
- Quadrant charts: diagrams that start with `quadrantChart`. The formatting
|
|
103
|
+
rules, with examples, are in [docs/quadrant.md](./docs/quadrant.md).
|
|
104
|
+
- Kanban boards: diagrams that start with `kanban`. The formatting rules, with
|
|
105
|
+
examples, are in [docs/kanban.md](./docs/kanban.md).
|
|
106
|
+
- C4 diagrams: `C4Context`, `C4Container`, `C4Component`, `C4Dynamic`, and
|
|
107
|
+
`C4Deployment`. The formatting rules, with examples, are in
|
|
108
|
+
[docs/c4.md](./docs/c4.md).
|
|
109
|
+
- Venn diagrams: diagrams that start with `venn-beta`. The formatting rules,
|
|
110
|
+
with examples, are in [docs/venn.md](./docs/venn.md).
|
|
111
|
+
- Ishikawa diagrams: `ishikawa` and `ishikawa-beta`, including accepted case
|
|
112
|
+
variants. The formatting rules are in [docs/ishikawa.md](./docs/ishikawa.md).
|
|
113
|
+
- Usecase diagrams: diagrams that start with `usecase-beta`. The formatting
|
|
114
|
+
rules are in [docs/usecase.md](./docs/usecase.md).
|
|
115
|
+
- Pie charts: diagrams that start with `pie`, including `showData`. The
|
|
116
|
+
formatting rules are in [docs/pie.md](./docs/pie.md).
|
|
117
|
+
- Info diagrams: diagrams that start with `info`, including `showInfo`. The
|
|
118
|
+
formatting rules are in [docs/info.md](./docs/info.md).
|
|
119
|
+
- Git graphs: diagrams that start with `gitGraph`. The formatting rules are in
|
|
120
|
+
[docs/gitgraph.md](./docs/gitgraph.md).
|
|
121
|
+
- Architecture diagrams: `architecture-beta`. The formatting rules are in
|
|
122
|
+
[docs/architecture.md](./docs/architecture.md).
|
|
123
|
+
- Treemap diagrams: `treemap` and `treemap-beta`. The formatting rules are in
|
|
124
|
+
[docs/treemap.md](./docs/treemap.md).
|
|
125
|
+
- Treeview diagrams: `treeView-beta`. The formatting rules are in
|
|
126
|
+
[docs/treeview.md](./docs/treeview.md).
|
|
127
|
+
- Radar diagrams: `radar-beta`. The formatting rules are in
|
|
128
|
+
[docs/radar.md](./docs/radar.md).
|
|
129
|
+
- Wardley maps: `wardley-beta`. The formatting rules are in
|
|
130
|
+
[docs/wardley.md](./docs/wardley.md).
|
|
131
|
+
- Railroad diagrams: `railroad-beta`, `railroad-ebnf-beta`, `railroad-abnf-beta`
|
|
132
|
+
and `railroad-peg-beta`. The formatting rules are in
|
|
133
|
+
[docs/railroad.md](./docs/railroad.md).
|
|
134
|
+
- Cynefin diagrams: `cynefin-beta` and `cynefin-beta:`. The formatting rules are
|
|
135
|
+
in [docs/cynefin.md](./docs/cynefin.md).
|
|
136
|
+
- Eventmodeling diagrams: `eventmodeling`. The formatting rules are in
|
|
137
|
+
[docs/eventmodeling.md](./docs/eventmodeling.md).
|
|
138
|
+
- Packet diagrams: `packet` and `packet-beta`. The formatting rules are in
|
|
139
|
+
[docs/packet.md](./docs/packet.md).
|
|
140
|
+
- Block diagrams: diagrams that start with `block-beta` or `block`. The
|
|
141
|
+
formatting rules, with examples, are in [docs/block.md](./docs/block.md).
|
|
142
|
+
- The YAML frontmatter of these diagrams, with Prettier's YAML formatter.
|
|
143
|
+
|
|
144
|
+
## Options
|
|
145
|
+
|
|
146
|
+
- `useTabs` and `tabWidth` set the indentation. The default is two spaces.
|
|
147
|
+
- `endOfLine` sets the line endings.
|
|
148
|
+
- `printWidth` has no effect: lines are never wrapped.
|
|
149
|
+
|
|
150
|
+
## When a diagram is not formatted
|
|
151
|
+
|
|
152
|
+
- Text that mermaid.js rejects is not changed. In a file, Prettier reports a
|
|
153
|
+
syntax error and leaves the file as it is. In Markdown, the code block is left
|
|
154
|
+
to Prettier, which prints it as code it does not format.
|
|
155
|
+
- A few inputs that mermaid.js accepts are reported as syntax errors too. For
|
|
156
|
+
example, a directive inside a keyword, as in `sub%%{init: {}}%%graph S`, and a
|
|
157
|
+
`click` that does not start a click statement, as in
|
|
158
|
+
`subgraph Handle click events`: in flowchart, `click` is a reserved word. An
|
|
159
|
+
empty string between tokens, as in `A-->|x""|B`, is reported too. The full
|
|
160
|
+
list is in [docs/compatibility.md](./docs/compatibility.md).
|
|
161
|
+
- The `error` pseudo-diagram of mermaid.js, a text of the word `error` with only
|
|
162
|
+
comments, directives, and line breaks around it, is not changed, except that
|
|
163
|
+
line endings follow `endOfLine`. In Markdown, it is left to Prettier.
|
|
164
|
+
|
|
165
|
+
## Guarantees and limitations
|
|
166
|
+
|
|
167
|
+
- Formatting does not change the diagram: mermaid.js reads the same diagram
|
|
168
|
+
before and after.
|
|
169
|
+
- One exception: whitespace at the end of a `style`, `classDef`, or `linkStyle`
|
|
170
|
+
line is removed. mermaid.js keeps it at the end of the last style.
|
|
171
|
+
- Formatting a formatted diagram again changes nothing.
|
|
172
|
+
- The content of directives, of opaque `@{ ... }` data blocks, and of the
|
|
173
|
+
frontmatter is not checked. A diagram that mermaid.js rejects because of that
|
|
174
|
+
content is still formatted. Directives and data blocks are kept as written;
|
|
175
|
+
the frontmatter is formatted only when Prettier can read it as YAML. Native
|
|
176
|
+
usecase metadata properties are parsed and validated as syntax.
|
|
177
|
+
- A flowchart with more edges than mermaid.js allows, 500 by default (its
|
|
178
|
+
`maxEdges` site setting), is rejected by mermaid.js but still formatted: the
|
|
179
|
+
plugin does not know the site settings.
|
|
180
|
+
- A byte order mark before the frontmatter is not handled as mermaid.js handles
|
|
181
|
+
it. A diagram that mermaid.js accepts may be reported as a syntax error, and
|
|
182
|
+
one that it rejects may be formatted.
|
|
183
|
+
- In Markdown, Prettier removes whitespace at the end of the last line of every
|
|
184
|
+
code block. Where mermaid.js reads that whitespace, as in
|
|
185
|
+
`style A fill:#f00, `, the diagram changes.
|
|
186
|
+
|
|
187
|
+
The reasons and the details are in
|
|
188
|
+
[docs/compatibility.md](./docs/compatibility.md).
|
|
189
|
+
|
|
190
|
+
## Documentation
|
|
191
|
+
|
|
192
|
+
- [docs/flowchart.md](./docs/flowchart.md): the formatting rules for flowcharts.
|
|
193
|
+
- [docs/agentflow.md](./docs/agentflow.md): the formatting rules for Agentflow.
|
|
194
|
+
- [docs/sequence.md](./docs/sequence.md): the formatting rules for sequence
|
|
195
|
+
diagrams.
|
|
196
|
+
- [docs/class.md](./docs/class.md): the formatting rules for class diagrams.
|
|
197
|
+
- [docs/state.md](./docs/state.md): the formatting rules for state diagrams.
|
|
198
|
+
- [docs/er.md](./docs/er.md): the formatting rules for ER diagrams.
|
|
199
|
+
- [docs/gantt.md](./docs/gantt.md): the formatting rules for Gantt charts.
|
|
200
|
+
- [docs/journey.md](./docs/journey.md): the formatting rules for user journeys.
|
|
201
|
+
- [docs/requirement.md](./docs/requirement.md): the formatting rules for
|
|
202
|
+
requirement diagrams.
|
|
203
|
+
- [docs/mindmap.md](./docs/mindmap.md): the formatting rules for mindmaps.
|
|
204
|
+
- [docs/timeline.md](./docs/timeline.md): the formatting rules for timelines.
|
|
205
|
+
- [docs/sankey.md](./docs/sankey.md): the formatting rules for sankey diagrams.
|
|
206
|
+
- [docs/xychart.md](./docs/xychart.md): the formatting rules for XY charts.
|
|
207
|
+
- [docs/quadrant.md](./docs/quadrant.md): the formatting rules for quadrant
|
|
208
|
+
charts.
|
|
209
|
+
- [docs/kanban.md](./docs/kanban.md): the formatting rules for kanban boards.
|
|
210
|
+
- [docs/c4.md](./docs/c4.md): the formatting rules for C4 diagrams.
|
|
211
|
+
- [docs/venn.md](./docs/venn.md): the formatting rules for Venn diagrams.
|
|
212
|
+
- [docs/ishikawa.md](./docs/ishikawa.md): the formatting rules for Ishikawa
|
|
213
|
+
diagrams.
|
|
214
|
+
- [docs/usecase.md](./docs/usecase.md): the formatting rules for usecase
|
|
215
|
+
diagrams.
|
|
216
|
+
- [docs/pie.md](./docs/pie.md): the formatting rules for pie charts.
|
|
217
|
+
- [docs/info.md](./docs/info.md): the formatting rules for info diagrams.
|
|
218
|
+
- [docs/gitgraph.md](./docs/gitgraph.md): the formatting rules for git graphs.
|
|
219
|
+
- [docs/architecture.md](./docs/architecture.md): the formatting rules for
|
|
220
|
+
architecture diagrams.
|
|
221
|
+
- [docs/treemap.md](./docs/treemap.md): the formatting rules for treemaps.
|
|
222
|
+
- [docs/treeview.md](./docs/treeview.md): the formatting rules for treeviews.
|
|
223
|
+
- [docs/radar.md](./docs/radar.md): the formatting rules for radar diagrams.
|
|
224
|
+
- [docs/wardley.md](./docs/wardley.md): the formatting rules for Wardley maps.
|
|
225
|
+
- [docs/railroad.md](./docs/railroad.md): the formatting rules for railroad
|
|
226
|
+
diagrams.
|
|
227
|
+
- [docs/cynefin.md](./docs/cynefin.md): the formatting rules for cynefin
|
|
228
|
+
diagrams.
|
|
229
|
+
- [docs/eventmodeling.md](./docs/eventmodeling.md): Eventmodeling formatting
|
|
230
|
+
rules.
|
|
231
|
+
- [docs/packet.md](./docs/packet.md): the formatting rules for packet diagrams.
|
|
232
|
+
- [docs/block.md](./docs/block.md): the formatting rules for block diagrams.
|
|
233
|
+
- [docs/compatibility.md](./docs/compatibility.md): where the plugin differs
|
|
234
|
+
from mermaid.js, and why.
|
|
235
|
+
- [docs/development.md](./docs/development.md): the tests and the fixtures, for
|
|
236
|
+
people who work on the plugin.
|