mmdfmt 0.1.0 → 0.2.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/README.md CHANGED
@@ -10,8 +10,8 @@ blocks of `.md` and `.markdown` files. The rest of a Markdown file stays byte
10
10
  for byte as it is. The diagrams are formatted by
11
11
  [Prettier](https://prettier.io/) with
12
12
  [`prettier-plugin-mmd`](../prettier-plugin-mmd), the Mermaid plugin for
13
- Prettier, so they come out as that plugin prints them, apart from the two cases
14
- in [If you know Prettier](#if-you-know-prettier).
13
+ Prettier, so they come out as that plugin prints them, apart from the cases in
14
+ [If you know Prettier](#if-you-know-prettier).
15
15
 
16
16
  This is a third-party project, not affiliated with
17
17
  [mermaid-js](https://mermaid.js.org/). The
@@ -108,28 +108,42 @@ diagram differently.
108
108
  ## Usage
109
109
 
110
110
  ```sh
111
- mmdfmt --write <pattern>...
111
+ mmdfmt --write [--check | --list-different] <pattern>...
112
112
  mmdfmt --check <pattern>...
113
+ mmdfmt --list-different <pattern>...
113
114
  mmdfmt --stdin-filepath <path>
114
115
  ```
115
116
 
116
- | Option | What it does |
117
- | ------------------------- | -------------------------------------------------------------------------------------------- |
118
- | `--write` | Formats the files in place, and lists on standard output the ones that changed. |
119
- | `--check` | Changes nothing. Lists on standard output the files that `--write` would change. |
120
- | `--stdin-filepath <path>` | Formats standard input as if it were the file at `<path>`, and writes it to standard output. |
121
- | `-h`, `--help` | Prints the usage on standard output. |
122
- | `-v`, `--version` | Prints the version on standard output. |
123
-
124
- Give patterns with either `--write` or `--check`, or give `--stdin-filepath`
125
- alone. `--help` and `--version` only print, whatever else of this table is given
126
- with them. Any other combination is an error. With no argument at all, `mmdfmt`
127
- prints the usage on standard error and exits with `2`.
117
+ | Option | What it does |
118
+ | ------------------------- | --------------------------------------------------------------------------------------------- |
119
+ | `-w`, `--write` | Formats the files in place, and lists each file it formats on standard output, with its time. |
120
+ | `-c`, `--check` | Checks whether the files are formatted, and prints a summary and the files that are not. |
121
+ | `-l`, `--list-different` | Changes nothing. Lists on standard output the files that `--write` would change. |
122
+ | `--stdin-filepath <path>` | Formats standard input as if it were the file at `<path>`, and writes it to standard output. |
123
+ | `-h`, `--help` | Prints the usage on standard output. |
124
+ | `-v`, `--version` | Prints the version on standard output. |
125
+
126
+ Give patterns with at least one of `--write`, `--check`, or `--list-different`.
127
+ `--write` can be combined with either `--check` or `--list-different`:
128
+ `--write --check` rewrites files and prints the check's summary and warnings;
129
+ `--write --list-different` rewrites files and lists only the ones that changed.
130
+ `--check` and `--list-different` cannot be combined. `--no-write`, `--no-check`,
131
+ and `--no-list-different` turn the option off. `--stdin-filepath` takes no
132
+ patterns, and with it `--write` writes no file. `--help` and `--version` only
133
+ print, whatever else of this table is given with them. With no argument at all,
134
+ `mmdfmt` prints the usage on standard error and exits with `2`.
135
+
136
+ `--write` alone prints a line for each file it formats, as Prettier does: the
137
+ name and the time that formatting it took, such as `docs/flow.mmd 12ms`,
138
+ followed by `(unchanged)` for a file that did not change. On a terminal that
139
+ shows colors, the name of an unchanged file is gray. To list only the files that
140
+ changed, give `--write --list-different`. The name of a file in what `mmdfmt`
141
+ prints is its path relative to the directory where it runs, with `/` between its
142
+ parts also on Windows, as Prettier writes it.
128
143
 
129
144
  There are no other options: no formatting options, no configuration file of its
130
145
  own, and no option for an ignore file. An option that takes no value ignores a
131
- value written after `=`: `--write=false` is read as `--write`, as the argument
132
- library [gunshi](https://gunshi.dev) reads it.
146
+ value written after `=`: `--write=false` is read as `--write`.
133
147
 
134
148
  When the reader of standard output goes away, as `head` does once it has its
135
149
  lines, `mmdfmt` writes no more there and says nothing, and finishes the run:
@@ -193,11 +207,30 @@ run:
193
207
  npx mmdfmt --check .
194
208
  ```
195
209
 
196
- When a file is not formatted, `--check` lists it on standard output and exits
197
- with `1`. When every file is formatted, it prints nothing and exits with `0`.
198
210
  Without the dependencies installed, `npx` would run the latest version instead
199
211
  of the pinned one.
200
212
 
213
+ `--check` prints `Checking formatting...` on standard output, then
214
+ `[warn] <name>` on standard error for each file that would change, and at the
215
+ end one summary. When a file would change, the summary is on standard error, and
216
+ the exit code is `1`:
217
+
218
+ ```txt
219
+ [warn] Code style issues found in the above file. Run mmdfmt with --write to fix.
220
+ ```
221
+
222
+ With more than one such file, it says `in <n> files` instead of
223
+ `in the above file`. On a terminal that shows colors, the word `warn` is yellow.
224
+ When no file would change, the summary is
225
+ `All diagrams in the matched files use Prettier code style!` on standard output,
226
+ and the exit code is `0`. `--list-different` prints only the names of the files
227
+ that would change, on standard output, with the same exit codes.
228
+
229
+ With `--write --check`, the files are rewritten, the summary is
230
+ `[warn] Code style issues fixed in the above file.` (or `in <n> files.`), and
231
+ the exit code is `0`. With an error, the exit code is `2`;
232
+ [Errors and exit codes](#errors-and-exit-codes) says which summary then follows.
233
+
201
234
  A `.mmd` or `.mermaid` file whose diagram mermaid.js rejects fails the check
202
235
  with `2`. A diagram in Markdown that mermaid.js rejects gives only a warning,
203
236
  because a document can show a broken diagram on purpose, and `mmdfmt` has no
@@ -248,25 +281,180 @@ whether the text is a diagram or Markdown, and its directory says which
248
281
  - A path under `node_modules` or a directory of version control, or listed in
249
282
  the `.gitignore` of the directory where `mmdfmt` runs, gets its text back
250
283
  unchanged.
284
+ - With `--check` or `--list-different`, the text is not written out: when it
285
+ would change, `(stdin)` goes to standard output and the exit code is `1`,
286
+ unless `--write` is given too; otherwise nothing is written and the exit code
287
+ is `0`. The position of a warning is in the text as it was read.
251
288
  - A path with another ending is an error.
252
289
 
253
- ## Indentation
290
+ ## From a script
254
291
 
255
- A diagram is indented by two spaces. When an `.editorconfig` or a Prettier
256
- configuration applies to the file, its indentation is used: `indent_style`,
257
- `indent_size`, and `tab_width` of `.editorconfig`, or `useTabs` and `tabWidth`
258
- of a [Prettier configuration file](https://prettier.io/docs/configuration),
259
- found as Prettier's CLI finds them, `overrides` included. For a code block, the
260
- file is the Markdown file. A configuration file that cannot be read is an error.
261
- For example, this `.editorconfig` indents diagrams by four spaces:
292
+ An editor extension, a language server, or another tool written for Node.js can
293
+ format the diagrams of a file as the `mmdfmt` command does, without running it.
294
+ (A tool that is not written for Node.js can run the command with
295
+ [`--stdin-filepath`](#from-an-editor-or-another-tool).) Add `mmdfmt` to the
296
+ dependencies of the tool, pinned as in [Installation](#installation), since a
297
+ new version can format a diagram a little differently:
298
+
299
+ ```sh
300
+ npm install --save-exact mmdfmt
301
+ ```
302
+
303
+ It needs Node.js `^22.13.0 || >=24`. Import its functions `resolveConfig`,
304
+ `format`, and `clearConfigCache`. Their arguments and results follow Prettier's
305
+ functions of the same names, and each section below says where they differ. This
306
+ formats the diagrams of `docs/notes.md`:
307
+
308
+ ```js
309
+ import { readFile } from "node:fs/promises"
310
+ import { format, resolveConfig } from "mmdfmt"
311
+
312
+ const filepath = "docs/notes.md"
313
+ const source = await readFile(filepath, "utf8")
314
+ const config = await resolveConfig(filepath)
315
+ const formatted = await format(source, { ...config, filepath })
316
+ ```
317
+
318
+ `formatted` is the text that the command writes for `docs/notes.md`: its
319
+ diagrams formatted, and the rest as written. Writing it to the file is up to the
320
+ tool.
321
+
322
+ ### `resolveConfig(fileUrlOrPath)`
323
+
324
+ `resolveConfig` finds the configuration of a file as the command finds it: the
325
+ Prettier configuration files and the `.editorconfig` that apply to the file,
326
+ `overrides` included (see [Configuration](#configuration)). Pass the path of the
327
+ file or a file URL; a relative path is resolved against the current directory,
328
+ so a language server passes an absolute path or a URL. The file itself is not
329
+ read, and need not exist.
330
+
331
+ It returns a promise of an object of Prettier options to pass to `format`, or of
332
+ `null` when no configuration applies to the file. Spreading `null` adds nothing,
333
+ so `{ ...config, filepath }` works in both cases. The object holds only the
334
+ options that the configuration sets, of the eight that `mmdfmt` reads, listed in
335
+ [Configuration](#configuration): with a configuration that sets no `tabWidth`,
336
+ `{ tabWidth: 4, ...config, filepath }` keeps a `tabWidth` of 4. With TypeScript,
337
+ its type is `ReadOptions`. The promise is rejected when a configuration file
338
+ cannot be read.
339
+
340
+ `resolveConfig` reads `.editorconfig` as the command does, and as Prettier's CLI
341
+ does by default; Prettier's `resolveConfig` reads it only when it is given
342
+ `editorconfig: true`.
343
+
344
+ ### `clearConfigCache()`
345
+
346
+ `resolveConfig` keeps the configuration files that it has read for the life of
347
+ the process, as Prettier's does, so a later call does not see a change to them.
348
+ Call `clearConfigCache` when the tool learns that a Prettier configuration file
349
+ or an `.editorconfig` has changed, for example from the editor's file watcher:
350
+ the next call of `resolveConfig` reads the files again. It returns a promise
351
+ that is resolved once the files are forgotten.
352
+
353
+ ### `format(source, options)`
354
+
355
+ `format` formats a text as Prettier's `format` does, except that in Markdown it
356
+ formats only the Mermaid code blocks and leaves the rest as written. It reads no
357
+ file and no configuration.
358
+
359
+ - `source`: the text of the file.
360
+ - `options.filepath`: the path of the file, required. Only its ending is used:
361
+ the text is read as one diagram for `.mmd` and `.mermaid`, and as Markdown for
362
+ `.md` and `.markdown`. The file need not exist.
363
+ - The other options: what `resolveConfig` returns for the same path, since the
364
+ `overrides` of a configuration apply by path. They are the eight options
365
+ listed in [Configuration](#configuration). For Markdown, `printWidth` is the
366
+ width for the whole file: a diagram in a list item or a block quote is
367
+ formatted to that width less the width of what stands before its lines (see
368
+ [Code blocks in detail](#code-blocks-in-detail)).
369
+ - Another option, such as `parser`, `endOfLine`, or `semi`, is not an option of
370
+ `format`: with TypeScript it is a type error, and in JavaScript it is ignored.
371
+ With TypeScript, the type of the options is `FormatOptions`.
372
+
373
+ It returns a promise of the formatted text. The line endings and a byte order
374
+ mark stay as they are in the text (see
375
+ [Code blocks in detail](#code-blocks-in-detail)).
376
+
377
+ In Markdown, `format` leaves three kinds of block as written and reports none of
378
+ them: a diagram that mermaid.js rejects, a block with a tab in its indentation
379
+ that is read partly as the diagram, and a block whose opening fence stands on
380
+ the line of a footnote label (see
381
+ [Code blocks in detail](#code-blocks-in-detail)). Prettier leaves an embedded
382
+ code block that it cannot format in the same way. To find the diagrams that
383
+ mermaid.js rejects, parse them with [`@mmd-toolkit/parser`](../parser) or lint
384
+ the file with [`@mmd-toolkit/eslint-plugin`](../eslint-plugin).
385
+
386
+ The promise is rejected:
387
+
388
+ - with the `SyntaxError` that Prettier throws for a `.mmd` or `.mermaid` text
389
+ that mermaid.js rejects, when it formats the text with `prettier-plugin-mmd`.
390
+ Its `loc.start` and `loc.end` give the `line` and the `column` where the error
391
+ starts and where it ends, both counted from 1. An error whose range runs on to
392
+ the start of a later line, such as an error at a line break, has no `loc.end`;
393
+ - with Prettier's error, when an option has a value that Prettier refuses, such
394
+ as `printWidth: "wide"` (`Invalid printWidth value. …`), for a `.mmd` or
395
+ `.mermaid` text, and for a Markdown text with a code block whose diagram
396
+ `mmdfmt` formats ([Code blocks in detail](#code-blocks-in-detail)), whether or
397
+ not mermaid.js rejects the diagram. A Markdown text with no such block is
398
+ returned as it is: one with no `mermaid` or `mmd` code block, or one whose
399
+ `mermaid` and `mmd` blocks are all left as written, after
400
+ `<!-- prettier-ignore -->`, between `<!-- prettier-ignore-start -->` and
401
+ `<!-- prettier-ignore-end -->`, on the line of a footnote label, or with a tab
402
+ in their indentation read partly as the diagram;
403
+ - with an error, when `options.filepath` does not end in `.md`, `.markdown`,
404
+ `.mmd`, or `.mermaid`.
405
+
406
+ ### Which files to format
407
+
408
+ The command formats only the files that end in `.md`, `.markdown`, `.mmd`, or
409
+ `.mermaid`, and skips a path under `node_modules` or a directory of version
410
+ control, or a path that the `.gitignore` of the directory where it runs lists
411
+ (see [Excluding files](#excluding-files)). `format` rejects the other endings,
412
+ but formats the text of any other path that it is given, wherever the path is: a
413
+ tool that should skip the same files as the command checks them before it calls
414
+ `format`.
415
+
416
+ ## Configuration
417
+
418
+ A diagram is indented by two spaces, and its line width is Prettier's 80. When
419
+ an `.editorconfig` or a Prettier configuration applies to the file, `mmdfmt`
420
+ reads eight options of it, found as Prettier's CLI finds it, `overrides`
421
+ included: `indent_style`, `indent_size`, `tab_width`, and `max_line_length` of
422
+ `.editorconfig`, or the options of a
423
+ [Prettier configuration file](https://prettier.io/docs/configuration). For a
424
+ code block, the file is the Markdown file. A configuration file that cannot be
425
+ read is an error. For example, this `.editorconfig` indents diagrams by four
426
+ spaces and lets a line stay up to 100 columns wide:
262
427
 
263
428
  ```ini
264
429
  [*.{md,mmd,mermaid}]
265
430
  indent_style = space
266
431
  indent_size = 4
432
+ max_line_length = 100
267
433
  ```
268
434
 
269
- Nothing else of a configuration is used.
435
+ The eight options are:
436
+
437
+ - `printWidth` is the line width. It decides two things in a diagram: whether a
438
+ data block `@{ … }` on one line is printed on several lines, and whether the
439
+ colons of the tasks of a Gantt section are lined up (see
440
+ [Formatter options](https://mmd-toolkit.github.io/mmd-toolkit/formatter/options.html#line-width)).
441
+ `max_line_length = off` is no limit. In a code block in a list or a block
442
+ quote, `printWidth` is less the width of what `mmdfmt` writes before the lines
443
+ (see [Code blocks in detail](#code-blocks-in-detail)).
444
+ - `tabWidth` and `useTabs` set the indentation of a diagram.
445
+ - `embeddedLanguageFormatting`, `singleQuote`, `bracketSpacing`, `proseWrap`,
446
+ and `trailingComma` apply to the YAML frontmatter of a diagram, as they do
447
+ when Prettier formats it with `prettier-plugin-mmd`.
448
+ `embeddedLanguageFormatting: "off"` leaves the frontmatter as written.
449
+
450
+ `mmdfmt` reads no other option, not even one that a later version of Prettier
451
+ adds. The range (`rangeStart` and `rangeEnd`), `cursorOffset`, the pragma
452
+ options (`requirePragma`, `insertPragma`, and `checkIgnorePragma`), `filepath`,
453
+ and the options of other languages are not used. `plugins` and `parser` are not
454
+ used either: `mmdfmt` always formats with `prettier-plugin-mmd`, so a plugin
455
+ that the configuration names is not loaded. `endOfLine` is not used, since a
456
+ file keeps its line endings (see
457
+ [Code blocks in detail](#code-blocks-in-detail)).
270
458
 
271
459
  ## Errors and exit codes
272
460
 
@@ -283,27 +471,38 @@ In a `.mmd` or `.mermaid` file, it is an error. In a Markdown code block, it is
283
471
  a warning. With `--write` and `--stdin-filepath`, the position of a warning is
284
472
  in the text after formatting, where the diagrams above it may have gained or
285
473
  lost lines, so that it points at the block in what you open after the run. With
286
- `--check`, which writes nothing, it is in the file as it is. Lines and columns
287
- count from 1, and a column counts UTF-16 code units, as most editors do.
474
+ `--check` or `--list-different` without `--write`, it is in the file as it is.
475
+ Lines and columns count from 1, and a column counts UTF-16 code units, as most
476
+ editors do.
288
477
  [Formatter compatibility](https://mmd-toolkit.github.io/mmd-toolkit/formatter/compatibility.html)
289
478
  explains which diagrams are rejected.
290
479
 
291
- | Code | Meaning |
292
- | ---- | ------------------------------------------------------------- |
293
- | `0` | No errors, and with `--check`, every file is formatted. |
294
- | `1` | With `--check`, a file would change, and there are no errors. |
295
- | `2` | An error. |
480
+ | Code | Meaning |
481
+ | ---- | ----------------------------------------------------------------------------------------------------- |
482
+ | `0` | No errors; with `--check` or `--list-different`, no file would change or `--write` is given. |
483
+ | `1` | With `--check` or `--list-different` without `--write`, a file would change, and there are no errors. |
484
+ | `2` | An error. |
296
485
 
297
486
  An error is a rejected diagram in a `.mmd` or `.mermaid` file, a file that
298
487
  cannot be read or written, a pattern that selects no file, a configuration that
299
488
  cannot be read, or a wrong use of the options. With an error, the code is `2`
300
489
  even when a file would change.
301
490
 
491
+ When a file cannot be formatted, such as a `.mmd` or `.mermaid` file whose
492
+ diagram mermaid.js rejects, the summary of `--check` is
493
+ `Error occurred when checking code style in the above file.` (or
494
+ `in <n> files.`) on standard output. As in Prettier's `--check`, the summary
495
+ counts only the files that cannot be formatted. A file that cannot be read, and
496
+ a pattern that selects no file, are reported as errors, but the summary is the
497
+ one it would be without them, also when no pattern selects any file. A file that
498
+ cannot be written counts among the files whose issues were fixed, and `--write`
499
+ and `--write --list-different` still list it.
500
+
302
501
  ## If you know Prettier
303
502
 
304
503
  The diagrams are formatted by Prettier with `prettier-plugin-mmd`, so the rules
305
- of the plugin apply. Two results differ from running Prettier with the plugin on
306
- Markdown:
504
+ of the plugin apply. Five results differ from running Prettier with the plugin
505
+ on Markdown and `.mmd` files:
307
506
 
308
507
  - Prettier removes the whitespace at the end of the last line of a code block,
309
508
  even where mermaid.js treats it as part of the diagram
@@ -312,10 +511,79 @@ Markdown:
312
511
  - Prettier formats a code block of Markdown, such as one marked `md`, as a
313
512
  Markdown document, and with it the diagrams in its code blocks. `mmdfmt`
314
513
  leaves every other code block as it is.
514
+ - Prettier prints what stands before the lines of a list item or a block quote
515
+ itself, while `mmdfmt` keeps it as written (see
516
+ [Code blocks in detail](#code-blocks-in-detail)). For a list item, Prettier
517
+ prints the marker and aligns the content to `tabWidth`. For a block quote, it
518
+ prints `> ` and drops the spaces and tabs between the `>` and the fence. Where
519
+ the two give the content another column, the line width left for a diagram in
520
+ the item or the quote differs by that, and a block of one line near the width
521
+ can be split by one and not by the other.
522
+ - In a list item or a block quote, Prettier lines up the colons of a Gantt
523
+ section without counting what stands before the lines, so a lined-up line can
524
+ be wider than the line width. `mmdfmt` counts it, so near the width a Gantt
525
+ section can be lined up by Prettier and not by `mmdfmt`, which then pads no
526
+ name to line the colons up: the whitespace before each colon stays as written,
527
+ and a line written wider than the line width stays so. `mmdfmt` still indents
528
+ the tasks as it does in any Gantt chart, so a colon moves along with its line
529
+ where the written indentation differs.
530
+ - Prettier leaves a diagram as written under four settings.
531
+ `requirePragma: true` leaves a Markdown file that has no `<!-- @format -->` or
532
+ `<!-- @prettier -->` comment at its top, after the frontmatter if there is
533
+ one. `checkIgnorePragma: true` leaves a Markdown file that has a
534
+ `<!-- @noformat -->` or `<!-- @noprettier -->` comment there. A range that
535
+ does not cover the whole file leaves a Markdown file or a `.mmd` file.
536
+ `embeddedLanguageFormatting: "off"` leaves every code block of a Markdown
537
+ file. `mmdfmt` formats the diagrams under all four. It does not read the first
538
+ three: it decides itself which files it formats (the patterns, and
539
+ `.gitignore`), and it formats whole diagrams. It reads
540
+ `embeddedLanguageFormatting` for the frontmatter of a diagram only, which it
541
+ then leaves as written.
315
542
 
316
543
  The command differs from Prettier's CLI too: it does not read `.prettierignore`,
317
- has no `--ignore-path`, `--ignore-unknown`, or formatting options, and uses only
318
- the indentation of a configuration.
544
+ has no `--ignore-path`, `--ignore-unknown`, or formatting options of its own,
545
+ and reads the configuration for the diagrams only. A value that Prettier refuses
546
+ for an option that `mmdfmt` does not read, such as `semi: "yes"`, is not an
547
+ error here, while Prettier's CLI reports it.
548
+
549
+ The check's success line says
550
+ `All diagrams in the matched files use Prettier code style!`, rather than
551
+ Prettier's `All matched files use Prettier code style!`: `mmdfmt` formats
552
+ nothing but diagrams, so the rest of a Markdown file may not use that style. The
553
+ warning asks you to run `mmdfmt --write`, because `prettier --write` would
554
+ format the whole Markdown file and, without the plugin configured, would not
555
+ format its diagrams.
556
+
557
+ Prettier reads `--write=false` as false; `mmdfmt` ignores a value written after
558
+ `=` on an option that takes no value, and reads it as `--write`. The same holds
559
+ for `--check=false` and `--list-different=false`. Prettier also takes a `true`
560
+ or `false` written after `--write` as its value; `mmdfmt` reads it as a pattern,
561
+ so `mmdfmt --write false notes.md` formats `notes.md` and reports that no file
562
+ matches `false`.
563
+
564
+ `--check --list-different` is an error in both, but `mmdfmt` prints
565
+ `mmdfmt: error: Optional argument '--check' conflicts with '--list-different'`
566
+ and exits with `2`, as for any wrong use of the options, while Prettier prints
567
+ `[error] Cannot use --check and --list-different together.` and exits with `1`.
568
+ When `mmdfmt` checks which options go together, a `--no-` form counts as giving
569
+ its option: `--no-check --list-different` is an error, as
570
+ `--check --list-different` is. Prettier accepts `--no-check --list-different`.
571
+
572
+ With `--check` or `--list-different` on standard input, Prettier exits with `0`
573
+ for a text it cannot parse; `mmdfmt` exits with `2` for a rejected diagram, as
574
+ everywhere else ([Errors and exit codes](#errors-and-exit-codes)). `mmdfmt`
575
+ reports a rejected diagram of a `.mmd` or `.mermaid` file on one line with its
576
+ position, such as `docs/flow.mmd:3:1: error: Unexpected end of text`, while
577
+ Prettier writes `[error] docs/flow.mmd: SyntaxError: Unexpected end of text` and
578
+ then the lines around the place, each after `[error]`. For a rejected diagram in
579
+ a Markdown file, `mmdfmt` writes a warning on one line, such as
580
+ `notes.md:6:1: warning: Unexpected end of text`, while Prettier writes nothing
581
+ about it; neither treats it as an error.
582
+
583
+ Prettier also colors the word `warn` yellow and the name of an unchanged file
584
+ gray where its output is not a terminal, if the `CI` environment variable is set
585
+ or the system is Windows. `mmdfmt` colors them only on a terminal that shows
586
+ colors, or when `FORCE_COLOR` is set, and has no `--color` or `--no-color`.
319
587
 
320
588
  ## Code blocks in detail
321
589
 
@@ -375,6 +643,20 @@ Two kinds of block are left as written, with a warning that gives the position:
375
643
 
376
644
  A diagram that is empty or only whitespace between its fences becomes empty.
377
645
 
646
+ The line width of a diagram in a list item or a block quote is the line width of
647
+ the file less the width of what `mmdfmt` writes before each of its lines, the
648
+ width being at least 1. Each character of it counts as one column, except that a
649
+ tab reaches the next multiple of `tabWidth`, and counts for nothing where
650
+ `tabWidth` is 0. For example, with a line width of 40, a diagram in a list item
651
+ whose lines start with two spaces is formatted for 38 columns, and with a
652
+ `tabWidth` of 4, a diagram in a block quote whose lines start with `>` and a tab
653
+ is formatted for 36 columns, as the tab reaches column 4. Prettier takes off the
654
+ width of what it prints before the lines from a data block `@{ … }` in the same
655
+ way, but what it prints can differ from what `mmdfmt` writes (see
656
+ [If you know Prettier](#if-you-know-prettier)). The colons of a Gantt section
657
+ are the exception: Prettier does not count what stands before the lines when it
658
+ lines them up (see the same section).
659
+
378
660
  A file keeps its line endings. Each line that `mmdfmt` writes ends as the first
379
661
  line of the file ends, or with `\n` in a file of one line, except the last,
380
662
  which ends as the last line of the diagram ended before formatting. The line
@@ -389,7 +671,7 @@ the column of an error or a warning, a line ends at `\n`, `\r\n`, or `\r`.
389
671
  ## Documentation
390
672
 
391
673
  - [Formatter options](https://mmd-toolkit.github.io/mmd-toolkit/formatter/options.html):
392
- how the indentation applies to diagrams.
674
+ how the indentation and the line width apply to diagrams.
393
675
  - [Formatter compatibility](https://mmd-toolkit.github.io/mmd-toolkit/formatter/compatibility.html):
394
676
  rejected diagrams, differences from mermaid.js, and what the formatting
395
677
  guarantees.
package/lib/cli.d.mts ADDED
@@ -0,0 +1 @@
1
+ export {}