mdrefine 0.2.0 → 0.2.2
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/CHANGELOG.md +56 -0
- package/CONTRIBUTING.md +13 -0
- package/README.md +1 -1
- package/dist/core/engine.js +73 -10
- package/dist/core/engine.js.map +1 -1
- package/dist/rules/blocks.js +10 -3
- package/dist/rules/blocks.js.map +1 -1
- package/dist/rules/dialects.js +12 -2
- package/dist/rules/dialects.js.map +1 -1
- package/dist/rules/lists.js +17 -0
- package/dist/rules/lists.js.map +1 -1
- package/dist/rules/style.js +118 -35
- package/dist/rules/style.js.map +1 -1
- package/dist/syntax/misread-lists.d.ts +46 -0
- package/dist/syntax/misread-lists.js +100 -0
- package/dist/syntax/misread-lists.js.map +1 -0
- package/dist/syntax/parse.d.ts +27 -3
- package/dist/syntax/parse.js +55 -7
- package/dist/syntax/parse.js.map +1 -1
- package/docs/design.md +43 -21
- package/docs/dialects.md +13 -9
- package/docs/plugins.md +4 -4
- package/docs/quick-start.md +1 -1
- package/docs/rules.md +57 -17
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,62 @@ release's section is also its [GitHub
|
|
|
8
8
|
release](https://github.com/viell-dev/slop-markdown-tools/releases)'s notes; the
|
|
9
9
|
prereleases' notes there are longer than their entries here.
|
|
10
10
|
|
|
11
|
+
## 0.2.2 - 2026-10-18
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- Formatting leaves a list that the parser reads as text as written, with the
|
|
16
|
+
blocks indented below it and the list after them. The parser reads a list that
|
|
17
|
+
does not start at 1, or an empty item, as text at the start of a list item or
|
|
18
|
+
block quote below a paragraph and after an indented code block, where GitHub
|
|
19
|
+
reads a list. Before, `style/ordered-list` and `style/list-marker` joined the
|
|
20
|
+
next list to it, `style/list-indent` moved a list out of its items,
|
|
21
|
+
`style/emphasis` changed what GitHub shows as code, `style/heading` made a
|
|
22
|
+
heading of it, and `style/block-spacing` made it loose. Every rule's edits in
|
|
23
|
+
such text are now left out, plugins' too. `style/block-spacing` now separates
|
|
24
|
+
text from a list such as `- 1. Step`, which the parser reads as GitHub does
|
|
25
|
+
([#341](https://github.com/viell-dev/slop-markdown-tools/pull/341)).
|
|
26
|
+
- `style/wrap` leaves a paragraph as written when a code span in it continues on
|
|
27
|
+
an indented lazy continuation line, as after `>* ` without a space. Before,
|
|
28
|
+
the safety check refused all of the rule's edits in such a document
|
|
29
|
+
([#340](https://github.com/viell-dev/slop-markdown-tools/pull/340)).
|
|
30
|
+
- `github/alert-marker` no longer capitalizes a marker that GitHub shows as
|
|
31
|
+
text: in a block quote inside another quote or a list, with text after the
|
|
32
|
+
marker on its line, or with nothing below it. Before, the visible text changed
|
|
33
|
+
([#337](https://github.com/viell-dev/slop-markdown-tools/pull/337)).
|
|
34
|
+
- `style/wrap` and `style/inline-code` keep a code span written across lines as
|
|
35
|
+
written when a line inside it ends with a backslash. Where its backticks do
|
|
36
|
+
not pair, as on GitHub after an unpaired longer run, that backslash is a hard
|
|
37
|
+
line break, which joining turned into a literal backslash
|
|
38
|
+
([#337](https://github.com/viell-dev/slop-markdown-tools/pull/337)).
|
|
39
|
+
- `style/thematic-break` no longer writes `---` directly below display math,
|
|
40
|
+
which GitHub builds from a paragraph and read as a heading
|
|
41
|
+
([#337](https://github.com/viell-dev/slop-markdown-tools/pull/337)).
|
|
42
|
+
- Formatting no longer changes what GitHub, Forgejo, Gitea, and Obsidian show
|
|
43
|
+
for the block directly below TOML front matter. They read the front matter's
|
|
44
|
+
lines as a paragraph, which that block can continue or underline as a heading:
|
|
45
|
+
`style/thematic-break` wrote `---` there, which made the front matter a
|
|
46
|
+
heading, and `style/heading` split such a heading in two. The safety check now
|
|
47
|
+
also compares the reading without TOML front matter, and the rules leave such
|
|
48
|
+
a block as written
|
|
49
|
+
([#338](https://github.com/viell-dev/slop-markdown-tools/pull/338)).
|
|
50
|
+
|
|
51
|
+
## 0.2.1 - 2026-10-18
|
|
52
|
+
|
|
53
|
+
### Fixed
|
|
54
|
+
|
|
55
|
+
- The Obsidian dialect reads strikethrough with two tildes only, as Obsidian
|
|
56
|
+
shows it; `~a~` is text there. Before, `style/emphasis` left emphasis that the
|
|
57
|
+
misread strikethrough covered unchanged
|
|
58
|
+
([#327](https://github.com/viell-dev/slop-markdown-tools/pull/327)).
|
|
59
|
+
- `style/emphasis` and `style/strong` no longer change markers that GitHub reads
|
|
60
|
+
otherwise than the parser: after an earlier emphasis, in `~~b *c~~ d*`, where
|
|
61
|
+
GitHub shows the asterisks as text; next to tildes, in `x~~*b b*~~`, where a
|
|
62
|
+
`_` would be text on GitHub; and in runs of markers that the parser pairs
|
|
63
|
+
otherwise than CommonMark, as in `xab***a* a*y`. Each rewrite changed what
|
|
64
|
+
GitHub showed while the safety check, which uses the parser's reading, saw no
|
|
65
|
+
change ([#327](https://github.com/viell-dev/slop-markdown-tools/pull/327)).
|
|
66
|
+
|
|
11
67
|
## 0.2.0 - 2026-10-18
|
|
12
68
|
|
|
13
69
|
The first stable release. It holds everything in the earlier prereleases, and
|
package/CONTRIBUTING.md
CHANGED
|
@@ -109,6 +109,19 @@ in `math.test.ts` against the renderers' output recorded in `math-renderers.ts`,
|
|
|
109
109
|
the engine, configuration, and plugins in `engine.test.ts`, and the diff that
|
|
110
110
|
`format` prints in `diff.test.ts`.
|
|
111
111
|
|
|
112
|
+
The safety check compares the parser's readings, so `renderers.test.ts` also
|
|
113
|
+
compares the HTML of two other implementations, commonmark.js and markdown-it,
|
|
114
|
+
before and after formatting. Its inputs are documents that
|
|
115
|
+
`scripts/rendering.mjs` generates from fixed seeds and the CommonMark
|
|
116
|
+
specification's examples in `tests/fixtures/commonmark/`. Each known difference
|
|
117
|
+
is listed with its issue and must still differ, so that a fix shows up as an
|
|
118
|
+
entry to remove; a new one fails the test. The Rendering workflow compares
|
|
119
|
+
GitHub's rendering in the same way every week, through its Markdown API. Run it
|
|
120
|
+
by hand with `gh workflow run rendering.yml`, optionally with `-f seed=N` to
|
|
121
|
+
repeat a run's new seed, or locally after a build with
|
|
122
|
+
`node scripts/github-rendering.mjs`, which needs an authenticated `gh` and takes
|
|
123
|
+
ten to fifteen minutes; its first lines say what it compares.
|
|
124
|
+
|
|
112
125
|
`tests/integration/` runs the built CLI as a child process in temporary
|
|
113
126
|
workspaces, and runs `examples/` and `benchmarks/` as they are, without the
|
|
114
127
|
machine's user and system Git settings, which would change what Git ignores. A
|
package/README.md
CHANGED
|
@@ -59,7 +59,7 @@ mdrefine needs Node.js 22.12 or newer. The package is `mdrefine`, and its
|
|
|
59
59
|
command is `mdtools`:
|
|
60
60
|
|
|
61
61
|
```sh
|
|
62
|
-
npm install --save-dev --save-exact mdrefine@0.2.
|
|
62
|
+
npm install --save-dev --save-exact mdrefine@0.2.2
|
|
63
63
|
npx mdtools lint
|
|
64
64
|
npx mdtools format --diff
|
|
65
65
|
npx mdtools format --write
|
package/dist/core/engine.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Ajv } from "ajv";
|
|
|
2
2
|
import { deepFreeze } from "./frozen.js";
|
|
3
3
|
import { resolveConfig, setting } from "../config/resolve.js";
|
|
4
4
|
import { optionErrors, shown } from "../config/problems.js";
|
|
5
|
-
import { codeSpanText,
|
|
5
|
+
import { codeSpanText, otherReading, parse, range, splitByteOrderMark, startsWithMarker, } from "../syntax/parse.js";
|
|
6
6
|
import { styleRules } from "../rules/style.js";
|
|
7
7
|
import { blockRules } from "../rules/blocks.js";
|
|
8
8
|
import { dialectRules } from "../rules/dialects.js";
|
|
@@ -11,6 +11,7 @@ import { linkRules } from "../rules/links.js";
|
|
|
11
11
|
import { contentRules } from "../rules/content.js";
|
|
12
12
|
import { listRules } from "../rules/lists.js";
|
|
13
13
|
import { headingAnchorSource, headingAttributeSource } from "../workspace/heading-attributes.js";
|
|
14
|
+
import { misreadLists } from "../syntax/misread-lists.js";
|
|
14
15
|
import { suppressions } from "./directives.js";
|
|
15
16
|
import { checkRanges, covers, holds, moved, shifted, widen } from "./scope.js";
|
|
16
17
|
/**
|
|
@@ -199,6 +200,61 @@ function findingsProblem(findings, length) {
|
|
|
199
200
|
}
|
|
200
201
|
return undefined;
|
|
201
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Whether an edit would change text that the parser read where renderers may
|
|
205
|
+
* read a list, or a block indented below it, which renderers may read inside
|
|
206
|
+
* that list (`misreadLists`, issue #191): replace some of their characters, or
|
|
207
|
+
* insert text between two of them. Renderers may read such text as list items
|
|
208
|
+
* or code, and the indentation of the blocks below it otherwise, which the
|
|
209
|
+
* safety check, comparing the parser's readings, cannot see: `_r_` for `*r*`
|
|
210
|
+
* in `- 0. *r*` below a paragraph changes code on GitHub. Only the part of
|
|
211
|
+
* the edit that changes the text counts, so that an edit that copies such
|
|
212
|
+
* text, such as a list rule's, can still apply.
|
|
213
|
+
*/
|
|
214
|
+
function misreadEdits(document) {
|
|
215
|
+
const misread = misreadLists(document);
|
|
216
|
+
// The blocks can hold one another; their union, in order, is searched in O(log n).
|
|
217
|
+
const blocks = [];
|
|
218
|
+
for (const [start, end] of Array.from([...misread.text, ...misread.nested], (node) => range(node)).sort((a, b) => a[0] - b[0])) {
|
|
219
|
+
const last = blocks.at(-1);
|
|
220
|
+
if (last && start < last[1])
|
|
221
|
+
last[1] = Math.max(last[1], end);
|
|
222
|
+
else
|
|
223
|
+
blocks.push([start, end]);
|
|
224
|
+
}
|
|
225
|
+
if (!blocks.length)
|
|
226
|
+
return () => false;
|
|
227
|
+
const { source } = document;
|
|
228
|
+
const within = (from, to) => {
|
|
229
|
+
let low = 0;
|
|
230
|
+
let high = blocks.length;
|
|
231
|
+
while (low < high) {
|
|
232
|
+
const middle = (low + high) >> 1;
|
|
233
|
+
if (blocks[middle][1] <= from)
|
|
234
|
+
low = middle + 1;
|
|
235
|
+
else
|
|
236
|
+
high = middle;
|
|
237
|
+
}
|
|
238
|
+
const block = blocks[low];
|
|
239
|
+
return block !== undefined && from < block[1] && to > block[0];
|
|
240
|
+
};
|
|
241
|
+
return (edit) => {
|
|
242
|
+
if (!within(edit.start, edit.end))
|
|
243
|
+
return false;
|
|
244
|
+
const before = source.slice(edit.start, edit.end);
|
|
245
|
+
const { text } = edit;
|
|
246
|
+
if (before === text)
|
|
247
|
+
return false;
|
|
248
|
+
const shorter = Math.min(before.length, text.length);
|
|
249
|
+
let prefix = 0;
|
|
250
|
+
while (prefix < shorter && before[prefix] === text[prefix])
|
|
251
|
+
prefix++;
|
|
252
|
+
let suffix = 0;
|
|
253
|
+
while (suffix < shorter - prefix && before.at(-1 - suffix) === text.at(-1 - suffix))
|
|
254
|
+
suffix++;
|
|
255
|
+
return within(edit.start + prefix, edit.end - suffix);
|
|
256
|
+
};
|
|
257
|
+
}
|
|
202
258
|
function host(workspace) {
|
|
203
259
|
const errors = new Set();
|
|
204
260
|
return workspace ? { workspace: guarded(workspace, errors), errors } : { errors };
|
|
@@ -242,11 +298,16 @@ function failure(error) {
|
|
|
242
298
|
* throws, or returns something that is not a list of valid findings, is
|
|
243
299
|
* skipped for the document and reported as `engine/rule-error` instead. An
|
|
244
300
|
* error of the workspace itself, such as a file that could not be read, is
|
|
245
|
-
* not the rule's and is thrown on.
|
|
301
|
+
* not the rule's and is thrown on. Suppressed findings are left out, and so
|
|
302
|
+
* are findings whose edits would change text that the parser read in place of
|
|
303
|
+
* a list, or the blocks that renderers read inside that list: the finding
|
|
304
|
+
* describes what the parser read, and following it by hand would make the
|
|
305
|
+
* change too.
|
|
246
306
|
*/
|
|
247
307
|
function inspect(document, config, rules, { workspace, errors: hostErrors }, include = () => true) {
|
|
248
308
|
const result = [];
|
|
249
309
|
const suppressed = suppressions(document);
|
|
310
|
+
const misread = misreadEdits(document);
|
|
250
311
|
const starts = lineStarts(document.source);
|
|
251
312
|
for (const [name, value] of Object.entries(config.rules)) {
|
|
252
313
|
const enabled = setting(value);
|
|
@@ -278,7 +339,7 @@ function inspect(document, config, rules, { workspace, errors: hostErrors }, inc
|
|
|
278
339
|
continue;
|
|
279
340
|
}
|
|
280
341
|
for (const finding of findings)
|
|
281
|
-
if (!suppressed(name, finding))
|
|
342
|
+
if (!suppressed(name, finding) && !(finding.edit && misread(finding.edit)))
|
|
282
343
|
result.push(diagnostic(starts, name, enabled.severity, finding));
|
|
283
344
|
}
|
|
284
345
|
return result.sort(sortDiagnostics);
|
|
@@ -459,11 +520,12 @@ function semanticTree(document, workspace, origins) {
|
|
|
459
520
|
}
|
|
460
521
|
const result = normalize(document.tree);
|
|
461
522
|
// Where front matter would end inside a code block, an HTML block, or
|
|
462
|
-
// display math, the document is read without it, and
|
|
463
|
-
// the meaning of both
|
|
464
|
-
|
|
523
|
+
// display math, the document is read without it, and renderers read TOML
|
|
524
|
+
// front matter as a paragraph. An edit has to keep the meaning of both
|
|
525
|
+
// readings.
|
|
526
|
+
const reading = otherReading(document.tree);
|
|
465
527
|
if (reading)
|
|
466
|
-
result.
|
|
528
|
+
result.otherReading = normalize(reading);
|
|
467
529
|
return result;
|
|
468
530
|
}
|
|
469
531
|
const isBranch = (value) => typeof value === "object" && value !== null && Array.isArray(value.children);
|
|
@@ -477,8 +539,9 @@ function divergence(before, after, workspace) {
|
|
|
477
539
|
const origins = new Map();
|
|
478
540
|
let a = semanticTree(before, workspace, origins);
|
|
479
541
|
let b = semanticTree(after, workspace);
|
|
480
|
-
// Where only the reading
|
|
481
|
-
|
|
542
|
+
// Where only the other reading differs, the place is in that reading, and
|
|
543
|
+
// otherwise in the document's own.
|
|
544
|
+
const reading = (value) => value.otherReading;
|
|
482
545
|
if (isBranch(a) &&
|
|
483
546
|
isBranch(b) &&
|
|
484
547
|
isBranch(reading(a)) &&
|
|
@@ -494,7 +557,7 @@ function divergence(before, after, workspace) {
|
|
|
494
557
|
offset = node?.position?.start.offset ?? offset;
|
|
495
558
|
if (!isBranch(a) || !isBranch(b))
|
|
496
559
|
return offset;
|
|
497
|
-
const own = (value) => JSON.stringify({ ...value, children: undefined });
|
|
560
|
+
const own = (value) => JSON.stringify({ ...value, children: undefined, otherReading: undefined });
|
|
498
561
|
if (own(a) !== own(b))
|
|
499
562
|
return offset;
|
|
500
563
|
const { children } = b;
|
package/dist/core/engine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/core/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,KAAK,EACL,KAAK,EACL,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AACjG,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAgB/E;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAA6C,UAAU,CAAC;IAC/E,GAAG,UAAU;IACb,GAAG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AE,GAAG,SAAS,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC;oBACrF,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBAC5B,CAAC;YACJ,CAAC;YACD,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;gBAClB,OAAO,SAAS,CACd,iBAAiB,MAAM,CAAC,OAAO,CAAC,+CAA+C,CAChF,CAAC;YACJ,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACnB,CAAC;QACD,OAAO,SAAS,CACd,iBAAiB,MAAM,CAAC,OAAO,CAAC,qEAAqE,CACtG,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,MAAM,KAAK,CAAC;QAC1C,OAAO,SAAS,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC","sourcesContent":["import { Ajv } from \"ajv\";\nimport type { AnySchema, ValidateFunction } from \"ajv\";\nimport { deepFreeze } from \"./frozen.js\";\nimport type { Nodes } from \"mdast\";\nimport { resolveConfig, setting } from \"../config/resolve.js\";\nimport { optionErrors, shown } from \"../config/problems.js\";\nimport {\n codeSpanText,\n frontMatterReading,\n parse,\n range,\n splitByteOrderMark,\n startsWithMarker,\n} from \"../syntax/parse.js\";\nimport { styleRules } from \"../rules/style.js\";\nimport { blockRules } from \"../rules/blocks.js\";\nimport { dialectRules } from \"../rules/dialects.js\";\nimport { structureRules } from \"../rules/structure.js\";\nimport { linkRules } from \"../rules/links.js\";\nimport { contentRules } from \"../rules/content.js\";\nimport { listRules } from \"../rules/lists.js\";\nimport { headingAnchorSource, headingAttributeSource } from \"../workspace/heading-attributes.js\";\nimport { suppressions } from \"./directives.js\";\nimport { checkRanges, covers, holds, moved, shifted, widen } from \"./scope.js\";\nimport type {\n Diagnostic,\n Document,\n Edit,\n Finding,\n FormatResult,\n JsonSchema,\n Plugin,\n ProcessOptions,\n ResolvedConfig,\n Rule,\n SourceRange,\n Workspace,\n} from \"./types.js\";\n\n/**\n * The built-in rules by rule ID. The table and the rules in it are frozen, so\n * that no caller can change what another one runs.\n */\nexport const builtInRules: Readonly<Record<string, Readonly<Rule>>> = deepFreeze({\n ...styleRules,\n ...blockRules,\n ...dialectRules,\n ...linkRules,\n ...structureRules,\n ...contentRules,\n ...listRules,\n});\nconst phases = [\"inline\", \"block\", \"document\"] as const;\n/** What is wrong with a plugin's rule, or undefined when it has the shape of a `Rule`. */\nfunction ruleProblem(rule: unknown): string | undefined {\n if (!rule || typeof rule !== \"object\") return `it is ${shown(rule)}, not an object`;\n const { check, kind, phase, description, schema } = rule as Record<string, unknown>;\n if (typeof check !== \"function\") return `its check is ${shown(check)}, not a function`;\n if (kind !== \"style\" && kind !== \"problem\")\n return `its kind is ${shown(kind)}, not \"style\" or \"problem\"`;\n if (phase !== undefined && !(phases as readonly unknown[]).includes(phase))\n return `its phase is ${shown(phase)}, not \"inline\", \"block\", or \"document\"`;\n if (typeof description !== \"string\")\n return `its description is ${shown(description)}, not a string`;\n if (\n schema !== undefined &&\n typeof schema !== \"boolean\" &&\n (!schema || typeof schema !== \"object\" || Array.isArray(schema))\n )\n return `its schema is ${shown(schema)}, not a JSON Schema`;\n // Options are checked before each run, synchronously; an asynchronous\n // check would come back after the run, too late to stop it.\n if (schema && typeof schema === \"object\" && (schema as { $async?: unknown }).$async === true)\n return \"its schema is asynchronous ($async), and options are checked synchronously\";\n return undefined;\n}\n/**\n * The prefix of the engine's own diagnostics, such as `engine/rule-error`. A\n * plugin of this name could report findings that pass for the engine's, which\n * concern the whole document and make the CLI exit with code 2.\n */\nexport const reservedPluginName = \"engine\";\n/**\n * The built-in rules and those of `plugins`, by rule ID, in a new table. A\n * plugin name that is invalid, reserved, or used twice, a rule ID that exists\n * already, and a plugin rule that does not have the shape of a `Rule` are\n * errors that name them.\n */\nexport function ruleRegistry(plugins: readonly Plugin[] = []): Record<string, Readonly<Rule>> {\n const rules = { ...builtInRules };\n const names = new Set<string>();\n for (const plugin of plugins) {\n if (plugin.name === reservedPluginName)\n throw new Error(\n `Invalid plugin name: ${reservedPluginName} is reserved for the engine's own diagnostics`,\n );\n if (!/^[a-z][a-z\\d-]*$/.test(plugin.name) || names.has(plugin.name))\n throw new Error(`Invalid or duplicate plugin name: ${plugin.name}`);\n names.add(plugin.name);\n for (const [name, rule] of Object.entries(plugin.rules ?? {})) {\n const id = `${plugin.name}/${name}`;\n if (Object.hasOwn(rules, id)) throw new Error(`Duplicate rule: ${id}`);\n const problem = ruleProblem(rule);\n if (problem) throw new Error(`Invalid rule ${id}: ${problem}.`);\n rules[id] = rule;\n }\n }\n return rules;\n}\n/** Checks the options of built-in rules, whose schemas have no `$id` that could collide. */\nconst ruleValidator = new Ajv({ allErrors: true });\nconst builtInSchemas = new Set(Object.values(builtInRules).map((rule) => rule.schema));\n/**\n * Each option schema compiled once, however many documents use it. A plugin\n * schema gets a validator of its own, because distinct plugins may\n * legitimately reuse an `$id` with different schemas.\n */\nconst compiledSchemas = new WeakMap<object, ValidateFunction>();\nfunction optionsValidator(name: string, schema: JsonSchema): ValidateFunction {\n // Ajv keeps compiled boolean schemas itself.\n if (typeof schema !== \"object\") return ruleValidator.compile(schema);\n let validate = compiledSchemas.get(schema);\n if (!validate) {\n try {\n validate = (\n builtInSchemas.has(schema) ? ruleValidator : new Ajv({ allErrors: true })\n ).compile(schema as AnySchema);\n } catch (error) {\n throw new Error(\n `Invalid rule ${name}: its schema cannot be compiled: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n // A schema can become asynchronous through one that it refers to.\n if ((validate as { $async?: unknown }).$async === true)\n throw new Error(\n `Invalid rule ${name}: its schema is asynchronous ($async), and options are checked synchronously`,\n );\n compiledSchemas.set(schema, validate);\n }\n return validate;\n}\nfunction prepare(options: ProcessOptions) {\n // Only these options, so that resolveConfig's check for the prereleases' form sees no others.\n const { config: given, path, plugins, defaultDialect } = options;\n const config = resolveConfig({ config: given, path, plugins, defaultDialect });\n const rules = ruleRegistry(options.plugins);\n for (const [name, value] of Object.entries(config.rules)) {\n // Names such as `toString` are found on every object; only defined rules count.\n if (!Object.hasOwn(rules, name)) throw new Error(`Unknown rule: ${name}`);\n const rule = rules[name]!;\n const enabled = setting(value);\n // A schema of `false` means that the rule takes no options. A setting that\n // gives none is checked as empty options, which `false` would refuse too.\n if (rule.schema === false && enabled.severity !== \"off\") {\n if (Object.keys(enabled.options).length)\n throw new Error(`Invalid options for ${name}: the rule takes no options`);\n } else if (rule.schema !== undefined && enabled.severity !== \"off\") {\n const validate = optionsValidator(name, rule.schema);\n if (!validate(enabled.options))\n throw new Error(\n `Invalid options for ${name}: ${optionErrors(validate.errors ?? [], enabled.options)}`,\n );\n }\n }\n return { config, rules };\n}\n/** CommonMark's line endings. */\nconst lineBreaks = /\\r\\n|\\r|\\n/g;\n/** Offsets where each line starts, computed once per source so findings locate in O(log lines). */\nfunction lineStarts(source: string): number[] {\n const starts = [0];\n for (const match of source.matchAll(lineBreaks)) starts.push(match.index + match[0].length);\n return starts;\n}\nfunction diagnostic(\n starts: number[],\n rule: string,\n severity: \"warn\" | \"error\",\n finding: Finding,\n): Diagnostic {\n let low = 0;\n let high = starts.length - 1;\n while (low < high) {\n const middle = (low + high + 1) >> 1;\n if (starts[middle]! <= finding.start) low = middle;\n else high = middle - 1;\n }\n return { ...finding, rule, severity, line: low + 1, column: finding.start - starts[low]! + 1 };\n}\nconst sortDiagnostics = (a: Diagnostic, b: Diagnostic) =>\n a.start - b.start || a.rule.localeCompare(b.rule);\n/** Diagnostics of the engine itself; they concern the whole document. */\nconst fromEngine = (item: Diagnostic) => item.rule.startsWith(\"engine/\");\n/** Why `value` is not an offset from `from` to `to`, or undefined when it is one. */\nfunction offsetProblem(what: string, value: unknown, from: number, to: number) {\n return Number.isInteger(value) && (value as number) >= from && (value as number) <= to\n ? undefined\n : `${what} is ${shown(value)}, not an offset from ${from} to ${to}`;\n}\n/**\n * What is wrong with the findings that a rule returned for a source of\n * `length` UTF-16 units, as the rest of a sentence about the rule, or\n * undefined when every finding can be reported and every edit applied.\n */\nfunction findingsProblem(findings: unknown, length: number): string | undefined {\n if (!Array.isArray(findings)) return `returned ${shown(findings)} instead of a list of findings`;\n for (const finding of findings as unknown[]) {\n if (!finding || typeof finding !== \"object\")\n return `returned a finding that is ${shown(finding)}, not an object`;\n const { message, start, end, edit } = finding as Record<string, unknown>;\n const problem =\n (typeof message === \"string\"\n ? undefined\n : `whose message is ${shown(message)}, not a string`) ??\n offsetProblem(\"whose start\", start, 0, length) ??\n (end === undefined ? undefined : offsetProblem(\"whose end\", end, start as number, length)) ??\n (edit === undefined || (edit && typeof edit === \"object\")\n ? undefined\n : `whose edit is ${shown(edit)}, not an object`);\n if (problem) return `returned a finding ${problem}`;\n if (edit === undefined) continue;\n const { start: from, end: to, text } = edit as Record<string, unknown>;\n const invalid =\n offsetProblem(\"whose start\", from, 0, length) ??\n offsetProblem(\"whose end\", to, from as number, length) ??\n (typeof text === \"string\" ? undefined : `whose text is ${shown(text)}, not a string`);\n if (invalid) return `returned an edit ${invalid}`;\n }\n return undefined;\n}\n/**\n * The workspace of a run as the engine and its rules use it, and the errors\n * that it threw. Such an error is the host's, such as a file that could not be\n * read, and neither a rule's nor a refusal to format: it stops the run.\n */\ninterface Host {\n workspace?: Workspace;\n errors: Set<unknown>;\n}\nfunction host(workspace: Workspace | undefined): Host {\n const errors = new Set<unknown>();\n return workspace ? { workspace: guarded(workspace, errors), errors } : { errors };\n}\n/**\n * `workspace` as rules see it. What its `resolve` throws is added to `errors`:\n * such an error is the host's, such as a file that could not be read, and not\n * the rule's. Rules still see it as it was thrown.\n */\nfunction guarded(workspace: Workspace, errors: Set<unknown>): Workspace {\n const resolve: Workspace[\"resolve\"] = (...query) => {\n try {\n return workspace.resolve(...query);\n } catch (error) {\n errors.add(error);\n throw error;\n }\n };\n // Other members, such as a host's own, reach the workspace itself.\n return new Proxy(workspace, {\n get(target, key) {\n if (key === \"resolve\") return resolve;\n const value: unknown = Reflect.get(target, key);\n return typeof value === \"function\" ? (value as () => unknown).bind(target) : value;\n },\n });\n}\n/** A thrown value as text, without letting it throw again. */\nfunction failure(error: unknown): string {\n try {\n return error instanceof Error ? `${error.name}: ${error.message}` : String(error);\n } catch {\n return \"a value that cannot be shown\";\n }\n}\n/**\n * The diagnostics of the enabled rules that `include` selects. A rule that\n * throws, or returns something that is not a list of valid findings, is\n * skipped for the document and reported as `engine/rule-error` instead. An\n * error of the workspace itself, such as a file that could not be read, is\n * not the rule's and is thrown on.\n */\nfunction inspect(\n document: Document,\n config: ResolvedConfig,\n rules: Record<string, Rule>,\n { workspace, errors: hostErrors }: Host,\n include: (rule: Rule) => boolean = () => true,\n): Diagnostic[] {\n const result: Diagnostic[] = [];\n const suppressed = suppressions(document);\n const starts = lineStarts(document.source);\n for (const [name, value] of Object.entries(config.rules)) {\n const enabled = setting(value);\n const rule = rules[name]!;\n if (enabled.severity === \"off\" || !include(rule)) continue;\n let findings: Finding[] = [];\n let problem: string | undefined;\n try {\n const returned: unknown = rule.check({\n document,\n options: enabled.options,\n ...(workspace ? { workspace } : {}),\n });\n problem = findingsProblem(returned, document.source.length);\n if (!problem) findings = returned as Finding[];\n } catch (error) {\n if (hostErrors.has(error)) throw error;\n problem = `failed (${failure(error)})`;\n }\n if (problem) {\n result.push(\n diagnostic([0], \"engine/rule-error\", \"error\", {\n start: 0,\n message: `Rule ${name} ${problem}; the rule was skipped for this document.`,\n }),\n );\n continue;\n }\n for (const finding of findings)\n if (!suppressed(name, finding))\n result.push(diagnostic(starts, name, enabled.severity, finding));\n }\n return result.sort(sortDiagnostics);\n}\n/**\n * Locate diagnostics of a document that `parse` read without the byte order\n * marks it starts with in the text as given, so that their edits apply to that\n * text. Lines and columns stay as they are: the marks are invisible.\n */\nfunction located(diagnostics: Diagnostic[], mark: string): Diagnostic[] {\n if (!mark) return diagnostics;\n const by = mark.length;\n return diagnostics.map((item) => ({\n ...item,\n start: item.start + by,\n ...(item.end !== undefined ? { end: item.end + by } : {}),\n ...(item.edit\n ? { edit: { ...item.edit, start: item.edit.start + by, end: item.edit.end + by } }\n : {}),\n }));\n}\n/**\n * The diagnostics of the enabled rules for `source`, sorted by position. A rule\n * that fails is skipped and reported as `engine/rule-error`. An invalid\n * configuration, an unknown rule, invalid rule options, an invalid plugin, and\n * an error that the workspace throws are thrown.\n */\nexport function lint(source: string, options: ProcessOptions = {}): Diagnostic[] {\n if (options.ranges) checkRanges(options.ranges, source);\n const { config, rules } = prepare(options);\n const [mark, text] = splitByteOrderMark(source);\n const document = parse(text, config.dialect, options.path, options.plugins);\n const diagnostics = inspect(document, config, rules, host(options.workspace));\n // Ranges count the marks, and the document's positions do not.\n const scope =\n options.ranges && widen(document.tree, document.source, shifted(options.ranges, -mark.length));\n return located(\n scope\n ? diagnostics.filter((item) => fromEngine(item) || covers(scope, item.start))\n : diagnostics,\n mark,\n );\n}\n/**\n * `source` with `edits` applied, which are `{ start, end, text }` replacements\n * at UTF-16 offsets into it. Repeats of one edit count once; an edit outside\n * the source, or one that overlaps another, is an error.\n */\nexport function applyEdits(source: string, edits: readonly Edit[]): string {\n return splice(source, acceptedEdits(source, edits));\n}\n/** `source` with `edits`, which are sorted and do not overlap, applied. */\nfunction splice(source: string, edits: readonly Edit[]): string {\n // Assemble the result in one pass; rebuilding the string per edit is quadratic.\n const parts: string[] = [];\n let cursor = 0;\n for (const edit of edits) {\n parts.push(source.slice(cursor, edit.start), edit.text);\n cursor = edit.end;\n }\n parts.push(source.slice(cursor));\n return parts.join(\"\");\n}\n/**\n * The edits that `applyEdits` applies, sorted by position and without repeats\n * of the same edit. An edit outside the source, or overlapping another one, is\n * an error.\n */\nfunction acceptedEdits(source: string, edits: readonly Edit[]): Edit[] {\n const sorted = [...edits].sort((a, b) => a.start - b.start || a.end - b.end);\n let previous: Edit | undefined;\n const accepted: Edit[] = [];\n for (const edit of sorted) {\n if (\n !Number.isInteger(edit.start) ||\n !Number.isInteger(edit.end) ||\n edit.start < 0 ||\n edit.end < edit.start ||\n edit.end > source.length\n )\n throw new Error(\"Rule returned an invalid edit range.\");\n if (\n previous &&\n edit.start === previous.start &&\n edit.end === previous.end &&\n edit.text === previous.text\n )\n continue;\n if (previous && (edit.start < previous.end || edit.start === previous.start))\n throw new Error(\n \"Enabled rules proposed overlapping edits; disable one of the conflicting rules.\",\n );\n accepted.push(edit);\n previous = edit;\n }\n return accepted;\n}\n/**\n * The meaning of a parsed document as text, which `format` compares before and\n * after edits to refuse a change of meaning: its syntax tree without positions,\n * with runs of whitespace in text alike, and with each link's destination as\n * the workspace resolves it, so that two spellings of one target are the same.\n */\nexport function semanticFingerprint(document: Document, workspace?: Workspace): string {\n return JSON.stringify(semanticTree(document, workspace));\n}\n/**\n * The document's meaning as plain data whose keys are in sorted order. With\n * `origins`, each object of the result that stands for a node of the document\n * is mapped to that node.\n */\nfunction semanticTree(\n document: Document,\n workspace?: Workspace,\n origins?: Map<unknown, Nodes>,\n): unknown {\n const canonicalUrl = (url: string, wiki = false) => {\n const resolution = workspace?.resolve(document.path, url, document.dialect, wiki);\n // A target that is uncertain, because a directory could not be read, is not\n // an identity: only the same spelling is known to name the same note.\n return resolution?.status === \"resolved\" && !resolution.unreadable\n ? `${resolution.target}#${resolution.fragment ?? \"\"}`\n : url;\n };\n // Keys are emitted in sorted order so the JSON text is canonical without a replacer.\n function normalize(node: Nodes, calloutHeader = false): unknown {\n if (node.type === \"wikiLink\") {\n const link = node.embed\n ? { label: node.label, type: \"embed\", url: canonicalUrl(node.target, true) }\n : {\n children: [{ type: \"text\", value: node.label ?? node.target }],\n title: null,\n type: \"link\",\n url: canonicalUrl(node.target, true),\n };\n origins?.set(link, node);\n return link;\n }\n const result: Record<string, unknown> = {};\n // Forgejo and Gitea read a heading's trailing `{...}` block as attributes,\n // character for character, where the tree holds ordinary inline content,\n // and generate the anchor from the heading's last line as written.\n if (node.type === \"heading\") {\n const attributes = headingAttributeSource(document, node);\n if (attributes !== undefined) result.attributes = attributes;\n const anchors = headingAnchorSource(document, node);\n if (anchors !== undefined) result.anchors = anchors;\n }\n if (calloutHeader && document.dialect !== \"commonmark\" && node.type === \"paragraph\") {\n const [start, end] = range(node);\n const header = document.source.slice(start, end).split(/\\r\\n|\\r|\\n/, 1)[0]!;\n if (startsWithMarker(header, node)) {\n // CommonMark merges an Obsidian callout's title, or the line of a\n // GitHub alert's marker, and the body into one paragraph. Preserve\n // their boundary too, also for a marker written as `\\[!NOTE]`.\n const title = header.replace(\n /^\\[!([\\w-]+)\\]/,\n (_, marker: string) => `[!${marker.toLowerCase()}]`,\n );\n result.calloutTitle = normalize(parse(title, document.dialect, document.path).tree);\n }\n }\n for (const key of Object.keys(node).sort()) {\n const value = (node as unknown as Record<string, unknown>)[key];\n if (key === \"position\" || key === \"data\") continue;\n if (key === \"children\" && \"children\" in node) {\n result.children = node.children.map((child, index) =>\n normalize(child, index === 0 && (node.type === \"blockquote\" || calloutHeader)),\n );\n } else if (key === \"url\" && typeof value === \"string\") result[key] = canonicalUrl(value);\n else if (key === \"value\" && node.type === \"text\") {\n let text = node.value.replace(/[ \\t\\r\\n]+/g, \" \");\n if (calloutHeader && document.dialect !== \"commonmark\")\n text = text.replace(\n /^\\[!([\\w-]+)\\]/,\n (_, marker: string) => `[!${marker.toLowerCase()}]`,\n );\n result[key] = text;\n } else if (key === \"value\" && node.type === \"inlineCode\")\n // A code span is compared by the text that GitHub shows, which its\n // value in the tree does not hold where it spans lines.\n result[key] = codeSpanText(node);\n // An image's description renders as plain text, and a reference's label\n // matches its definition with whitespace collapsed.\n else if ((key === \"alt\" || key === \"label\") && typeof value === \"string\")\n result[key] = value.replace(/[ \\t\\r\\n]+/g, \" \");\n else result[key] = value;\n }\n origins?.set(result, node);\n return result;\n }\n const result = normalize(document.tree) as Record<string, unknown>;\n // Where front matter would end inside a code block, an HTML block, or\n // display math, the document is read without it, and an edit has to keep\n // the meaning of both readings.\n const reading = frontMatterReading(document.tree);\n if (reading) result.frontMatterReading = normalize(reading);\n return result;\n}\n/** A part of a semantic tree that has children. */\ntype Branch = Record<string, unknown> & { children: unknown[] };\nconst isBranch = (value: unknown): value is Branch =>\n typeof value === \"object\" && value !== null && Array.isArray((value as Branch).children);\n/**\n * Where the meaning of `after` first differs from that of `before`, as an\n * offset into `before`'s source: the start of the first node, in document\n * order, whose meaning is not the same, or the end of the node that `after`\n * gives more content.\n */\nfunction divergence(before: Document, after: Document, workspace?: Workspace): number {\n const origins = new Map<unknown, Nodes>();\n let a = semanticTree(before, workspace, origins);\n let b = semanticTree(after, workspace);\n // Where only the reading with front matter differs, the place is in that reading.\n const reading = (value: unknown) =>\n (value as { frontMatterReading?: unknown }).frontMatterReading;\n if (\n isBranch(a) &&\n isBranch(b) &&\n isBranch(reading(a)) &&\n isBranch(reading(b)) &&\n JSON.stringify(a.children) === JSON.stringify(b.children)\n ) {\n a = reading(a);\n b = reading(b);\n }\n let offset = 0;\n for (;;) {\n const node = origins.get(a);\n // A node made up for the comparison, or one without a position, is placed at its parent.\n offset = node?.position?.start.offset ?? offset;\n if (!isBranch(a) || !isBranch(b)) return offset;\n const own = (value: Branch) => JSON.stringify({ ...value, children: undefined });\n if (own(a) !== own(b)) return offset;\n const { children } = b;\n const index = a.children.findIndex(\n (child, at) => JSON.stringify(child) !== JSON.stringify(children[at]),\n );\n if (index < 0) return node?.position?.end.offset ?? offset;\n a = a.children[index];\n b = children[index];\n }\n}\n/**\n * Format a document: apply the edits of the enabled style rules, in passes\n * until nothing changes, leaving out the edits of a rule that would change the\n * document's meaning. Byte order marks that it starts with stay in the output\n * and are not part of what the rules see. Errors are thrown as by `lint`.\n */\nexport function format(source: string, options: ProcessOptions = {}): FormatResult {\n if (options.ranges) checkRanges(options.ranges, source);\n const [mark, text] = splitByteOrderMark(source);\n // Ranges count the marks, and the document's positions do not.\n const result = formatText(text, options, options.ranges && shifted(options.ranges, -mark.length));\n return {\n output: mark + result.output,\n changed: result.changed,\n diagnostics: located(result.diagnostics, mark),\n ...(result.scope ? { scope: shifted(result.scope, mark.length) } : {}),\n };\n}\n/** An edit that a rule proposed, with the rule's ID. */\ninterface Proposal extends Edit {\n rule: string;\n}\nconst byPosition = (a: Edit, b: Edit) => a.start - b.start || a.end - b.end;\n/**\n * The proposals to apply together, in the order of the source. An edit that\n * overlaps one before it, or repeats it, is left out; the next pass, which\n * runs the rules again on the changed text, reconsiders it.\n */\nfunction compatible(proposals: readonly Proposal[]): Proposal[] {\n const result: Proposal[] = [];\n let previous: Proposal | undefined;\n for (const edit of [...proposals].sort(byPosition)) {\n if (previous && (edit.start < previous.end || edit.start === previous.start)) continue;\n result.push(edit);\n previous = edit;\n }\n return result;\n}\n/** Rule IDs as a list in prose. */\nfunction listed(names: Iterable<string>): string {\n const items = [...names];\n return items.length < 3\n ? items.join(\" and \")\n : `${items.slice(0, -1).join(\", \")}, and ${items.at(-1)}`;\n}\n/**\n * Format a document without byte order marks, limited to `ranges` in its\n * positions. Each phase applies the edits of its rules together when the\n * result means what the original document means. Otherwise it adds the rules'\n * edits one rule at a time and leaves out the edits of each rule that would\n * change the meaning; the result reports each such rule with the place where\n * the meaning would first differ. Passes repeat until one changes nothing;\n * formatting that does not settle leaves the whole document unchanged.\n */\nfunction formatText(\n source: string,\n options: ProcessOptions,\n ranges: SourceRange[] | undefined,\n): FormatResult {\n const { config, rules } = prepare(options);\n // What the workspace throws stops formatting, as it stops `lint`.\n const hosted = host(options.workspace);\n const { workspace } = hosted;\n let output = source;\n let document = parse(source, config.dialect, options.path, options.plugins);\n // Where edits may apply, in the positions of the current output.\n const initial = ranges && widen(document.tree, source, ranges);\n let scope = initial;\n // Engine findings concern the whole document and are always reported.\n const reported = (items: Diagnostic[]) =>\n scope ? items.filter((item) => fromEngine(item) || covers(scope!, item.start)) : items;\n const unchanged = (message: string): FormatResult => ({\n output: source,\n changed: false,\n diagnostics: [diagnostic([0], \"engine/unsafe-format\", \"error\", { start: 0, message })],\n ...(initial ? { scope: initial } : {}),\n });\n // The original fingerprint is only needed once an edit produces a candidate.\n let fingerprint: string | undefined;\n /** `candidate` parsed, and whether it means what the original document means. */\n const check = (candidate: string) => {\n const parsed = parse(candidate, config.dialect, options.path, options.plugins);\n // Every document accepted so far means what the original means, so the current one serves.\n fingerprint ??= semanticFingerprint(document, workspace);\n return {\n document: parsed,\n safe: semanticFingerprint(parsed, workspace) === fingerprint,\n };\n };\n const seen = new Set([source]);\n /** The rules whose edits changed the document in the latest pass. */\n let applied = new Set<string>();\n try {\n for (let pass = 0; pass < 8; pass++) {\n const before = output;\n const findings: Diagnostic[] = [];\n applied = new Set();\n /** The rules whose edits this pass left out, with the document before and after them. */\n const refused: { rule: string; before: Document; after: Document }[] = [];\n const accept = (edits: Proposal[], text: string, parsed: Document) => {\n output = text;\n // Rules consume the document without mutating it. Reuse the validated\n // tree until another phase changes its source, including final diagnostics.\n document = parsed;\n if (scope) scope = moved(scope, edits);\n for (const edit of edits) applied.add(edit.rule);\n };\n for (const phase of phases) {\n const diagnostics = inspect(\n document,\n config,\n rules,\n hosted,\n (rule) => rule.kind === \"style\" && (rule.phase ?? \"inline\") === phase,\n );\n findings.push(...diagnostics);\n // With ranges, an edit that reaches outside them is not applied. One\n // that changes nothing need not be tried, and must not hold others back.\n const proposals: Proposal[] = [];\n for (const { edit, rule } of diagnostics)\n if (\n edit &&\n (!scope || holds(scope, edit)) &&\n output.slice(edit.start, edit.end) !== edit.text\n )\n proposals.push({ start: edit.start, end: edit.end, text: edit.text, rule });\n // The rules of this phase whose edits would change the meaning.\n const excluded = new Set<string>();\n for (;;) {\n const edits = compatible(proposals.filter((edit) => !excluded.has(edit.rule)));\n if (!edits.length) break;\n const candidate = splice(output, edits);\n if (candidate === output) break;\n const tried = check(candidate);\n if (tried.safe) {\n accept(edits, candidate, tried.document);\n break;\n }\n // Taken only when a phase fails, so the usual path parses each candidate once.\n let kept: Proposal[] = [];\n let keptOutput = output;\n let keptDocument = document;\n for (const rule of new Set(edits.map((edit) => edit.rule))) {\n const trial = [...kept, ...edits.filter((edit) => edit.rule === rule)].sort(byPosition);\n // All the edits together are already known to fail.\n const whole = trial.length === edits.length;\n const text = whole ? candidate : splice(output, trial);\n const result = whole ? tried : check(text);\n if (result.safe) {\n kept = trial;\n keptOutput = text;\n keptDocument = result.document;\n } else {\n excluded.add(rule);\n refused.push({ rule, before: document, after: result.document });\n }\n }\n if (keptOutput !== output) {\n accept(kept, keptOutput, keptDocument);\n break;\n }\n // Nothing was kept: the edits that overlapped refused ones get their turn.\n }\n }\n if (output === before) {\n // No phase changed the document, so every style finding of this pass\n // describes the final document; only the non-style rules still need to run.\n const remaining = inspect(document, config, rules, hosted, (rule) => rule.kind !== \"style\");\n // A refusal of this pass was tried on the final text, unless one\n // phase undid what an earlier one did.\n const starts = refused.length ? lineStarts(output) : [];\n const refusals = refused.map(({ rule, before: tried, after }) => {\n const start = tried.source === output ? divergence(tried, after, workspace) : 0;\n const { line } = diagnostic(starts, rule, \"error\", { start, message: \"\" });\n return diagnostic(starts, \"engine/unsafe-format\", \"error\", {\n start,\n message: `${rule} would change the parsed meaning at line ${line}; none of its edits were applied.`,\n });\n });\n return {\n output,\n changed: output !== source,\n diagnostics: reported([...findings, ...remaining, ...refusals]).sort(sortDiagnostics),\n ...(scope ? { scope } : {}),\n };\n }\n if (seen.has(output))\n return unchanged(\n `Formatting by ${listed(applied)} oscillates; the document was left unchanged.`,\n );\n seen.add(output);\n }\n return unchanged(\n `Formatting by ${listed(applied)} did not converge in eight passes; the document was left unchanged.`,\n );\n } catch (error) {\n if (hosted.errors.has(error)) throw error;\n return unchanged(error instanceof Error ? error.message : String(error));\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/core/engine.ts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oBACN,OAAO,EAAE,MAAM,KAAK,MAAM;oBAC1B,WAAW,EAAE,QAAQ,CAAC,CAAC,GAAG,QAAQ,EAAE,GAAG,SAAS,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC;oBACrF,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBAC5B,CAAC;YACJ,CAAC;YACD,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;gBAClB,OAAO,SAAS,CACd,iBAAiB,MAAM,CAAC,OAAO,CAAC,+CAA+C,CAChF,CAAC;YACJ,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACnB,CAAC;QACD,OAAO,SAAS,CACd,iBAAiB,MAAM,CAAC,OAAO,CAAC,qEAAqE,CACtG,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,MAAM,KAAK,CAAC;QAC1C,OAAO,SAAS,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC","sourcesContent":["import { Ajv } from \"ajv\";\nimport type { AnySchema, ValidateFunction } from \"ajv\";\nimport { deepFreeze } from \"./frozen.js\";\nimport type { Nodes } from \"mdast\";\nimport { resolveConfig, setting } from \"../config/resolve.js\";\nimport { optionErrors, shown } from \"../config/problems.js\";\nimport {\n codeSpanText,\n otherReading,\n parse,\n range,\n splitByteOrderMark,\n startsWithMarker,\n} from \"../syntax/parse.js\";\nimport { styleRules } from \"../rules/style.js\";\nimport { blockRules } from \"../rules/blocks.js\";\nimport { dialectRules } from \"../rules/dialects.js\";\nimport { structureRules } from \"../rules/structure.js\";\nimport { linkRules } from \"../rules/links.js\";\nimport { contentRules } from \"../rules/content.js\";\nimport { listRules } from \"../rules/lists.js\";\nimport { headingAnchorSource, headingAttributeSource } from \"../workspace/heading-attributes.js\";\nimport { misreadLists } from \"../syntax/misread-lists.js\";\nimport { suppressions } from \"./directives.js\";\nimport { checkRanges, covers, holds, moved, shifted, widen } from \"./scope.js\";\nimport type {\n Diagnostic,\n Document,\n Edit,\n Finding,\n FormatResult,\n JsonSchema,\n Plugin,\n ProcessOptions,\n ResolvedConfig,\n Rule,\n SourceRange,\n Workspace,\n} from \"./types.js\";\n\n/**\n * The built-in rules by rule ID. The table and the rules in it are frozen, so\n * that no caller can change what another one runs.\n */\nexport const builtInRules: Readonly<Record<string, Readonly<Rule>>> = deepFreeze({\n ...styleRules,\n ...blockRules,\n ...dialectRules,\n ...linkRules,\n ...structureRules,\n ...contentRules,\n ...listRules,\n});\nconst phases = [\"inline\", \"block\", \"document\"] as const;\n/** What is wrong with a plugin's rule, or undefined when it has the shape of a `Rule`. */\nfunction ruleProblem(rule: unknown): string | undefined {\n if (!rule || typeof rule !== \"object\") return `it is ${shown(rule)}, not an object`;\n const { check, kind, phase, description, schema } = rule as Record<string, unknown>;\n if (typeof check !== \"function\") return `its check is ${shown(check)}, not a function`;\n if (kind !== \"style\" && kind !== \"problem\")\n return `its kind is ${shown(kind)}, not \"style\" or \"problem\"`;\n if (phase !== undefined && !(phases as readonly unknown[]).includes(phase))\n return `its phase is ${shown(phase)}, not \"inline\", \"block\", or \"document\"`;\n if (typeof description !== \"string\")\n return `its description is ${shown(description)}, not a string`;\n if (\n schema !== undefined &&\n typeof schema !== \"boolean\" &&\n (!schema || typeof schema !== \"object\" || Array.isArray(schema))\n )\n return `its schema is ${shown(schema)}, not a JSON Schema`;\n // Options are checked before each run, synchronously; an asynchronous\n // check would come back after the run, too late to stop it.\n if (schema && typeof schema === \"object\" && (schema as { $async?: unknown }).$async === true)\n return \"its schema is asynchronous ($async), and options are checked synchronously\";\n return undefined;\n}\n/**\n * The prefix of the engine's own diagnostics, such as `engine/rule-error`. A\n * plugin of this name could report findings that pass for the engine's, which\n * concern the whole document and make the CLI exit with code 2.\n */\nexport const reservedPluginName = \"engine\";\n/**\n * The built-in rules and those of `plugins`, by rule ID, in a new table. A\n * plugin name that is invalid, reserved, or used twice, a rule ID that exists\n * already, and a plugin rule that does not have the shape of a `Rule` are\n * errors that name them.\n */\nexport function ruleRegistry(plugins: readonly Plugin[] = []): Record<string, Readonly<Rule>> {\n const rules = { ...builtInRules };\n const names = new Set<string>();\n for (const plugin of plugins) {\n if (plugin.name === reservedPluginName)\n throw new Error(\n `Invalid plugin name: ${reservedPluginName} is reserved for the engine's own diagnostics`,\n );\n if (!/^[a-z][a-z\\d-]*$/.test(plugin.name) || names.has(plugin.name))\n throw new Error(`Invalid or duplicate plugin name: ${plugin.name}`);\n names.add(plugin.name);\n for (const [name, rule] of Object.entries(plugin.rules ?? {})) {\n const id = `${plugin.name}/${name}`;\n if (Object.hasOwn(rules, id)) throw new Error(`Duplicate rule: ${id}`);\n const problem = ruleProblem(rule);\n if (problem) throw new Error(`Invalid rule ${id}: ${problem}.`);\n rules[id] = rule;\n }\n }\n return rules;\n}\n/** Checks the options of built-in rules, whose schemas have no `$id` that could collide. */\nconst ruleValidator = new Ajv({ allErrors: true });\nconst builtInSchemas = new Set(Object.values(builtInRules).map((rule) => rule.schema));\n/**\n * Each option schema compiled once, however many documents use it. A plugin\n * schema gets a validator of its own, because distinct plugins may\n * legitimately reuse an `$id` with different schemas.\n */\nconst compiledSchemas = new WeakMap<object, ValidateFunction>();\nfunction optionsValidator(name: string, schema: JsonSchema): ValidateFunction {\n // Ajv keeps compiled boolean schemas itself.\n if (typeof schema !== \"object\") return ruleValidator.compile(schema);\n let validate = compiledSchemas.get(schema);\n if (!validate) {\n try {\n validate = (\n builtInSchemas.has(schema) ? ruleValidator : new Ajv({ allErrors: true })\n ).compile(schema as AnySchema);\n } catch (error) {\n throw new Error(\n `Invalid rule ${name}: its schema cannot be compiled: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n // A schema can become asynchronous through one that it refers to.\n if ((validate as { $async?: unknown }).$async === true)\n throw new Error(\n `Invalid rule ${name}: its schema is asynchronous ($async), and options are checked synchronously`,\n );\n compiledSchemas.set(schema, validate);\n }\n return validate;\n}\nfunction prepare(options: ProcessOptions) {\n // Only these options, so that resolveConfig's check for the prereleases' form sees no others.\n const { config: given, path, plugins, defaultDialect } = options;\n const config = resolveConfig({ config: given, path, plugins, defaultDialect });\n const rules = ruleRegistry(options.plugins);\n for (const [name, value] of Object.entries(config.rules)) {\n // Names such as `toString` are found on every object; only defined rules count.\n if (!Object.hasOwn(rules, name)) throw new Error(`Unknown rule: ${name}`);\n const rule = rules[name]!;\n const enabled = setting(value);\n // A schema of `false` means that the rule takes no options. A setting that\n // gives none is checked as empty options, which `false` would refuse too.\n if (rule.schema === false && enabled.severity !== \"off\") {\n if (Object.keys(enabled.options).length)\n throw new Error(`Invalid options for ${name}: the rule takes no options`);\n } else if (rule.schema !== undefined && enabled.severity !== \"off\") {\n const validate = optionsValidator(name, rule.schema);\n if (!validate(enabled.options))\n throw new Error(\n `Invalid options for ${name}: ${optionErrors(validate.errors ?? [], enabled.options)}`,\n );\n }\n }\n return { config, rules };\n}\n/** CommonMark's line endings. */\nconst lineBreaks = /\\r\\n|\\r|\\n/g;\n/** Offsets where each line starts, computed once per source so findings locate in O(log lines). */\nfunction lineStarts(source: string): number[] {\n const starts = [0];\n for (const match of source.matchAll(lineBreaks)) starts.push(match.index + match[0].length);\n return starts;\n}\nfunction diagnostic(\n starts: number[],\n rule: string,\n severity: \"warn\" | \"error\",\n finding: Finding,\n): Diagnostic {\n let low = 0;\n let high = starts.length - 1;\n while (low < high) {\n const middle = (low + high + 1) >> 1;\n if (starts[middle]! <= finding.start) low = middle;\n else high = middle - 1;\n }\n return { ...finding, rule, severity, line: low + 1, column: finding.start - starts[low]! + 1 };\n}\nconst sortDiagnostics = (a: Diagnostic, b: Diagnostic) =>\n a.start - b.start || a.rule.localeCompare(b.rule);\n/** Diagnostics of the engine itself; they concern the whole document. */\nconst fromEngine = (item: Diagnostic) => item.rule.startsWith(\"engine/\");\n/** Why `value` is not an offset from `from` to `to`, or undefined when it is one. */\nfunction offsetProblem(what: string, value: unknown, from: number, to: number) {\n return Number.isInteger(value) && (value as number) >= from && (value as number) <= to\n ? undefined\n : `${what} is ${shown(value)}, not an offset from ${from} to ${to}`;\n}\n/**\n * What is wrong with the findings that a rule returned for a source of\n * `length` UTF-16 units, as the rest of a sentence about the rule, or\n * undefined when every finding can be reported and every edit applied.\n */\nfunction findingsProblem(findings: unknown, length: number): string | undefined {\n if (!Array.isArray(findings)) return `returned ${shown(findings)} instead of a list of findings`;\n for (const finding of findings as unknown[]) {\n if (!finding || typeof finding !== \"object\")\n return `returned a finding that is ${shown(finding)}, not an object`;\n const { message, start, end, edit } = finding as Record<string, unknown>;\n const problem =\n (typeof message === \"string\"\n ? undefined\n : `whose message is ${shown(message)}, not a string`) ??\n offsetProblem(\"whose start\", start, 0, length) ??\n (end === undefined ? undefined : offsetProblem(\"whose end\", end, start as number, length)) ??\n (edit === undefined || (edit && typeof edit === \"object\")\n ? undefined\n : `whose edit is ${shown(edit)}, not an object`);\n if (problem) return `returned a finding ${problem}`;\n if (edit === undefined) continue;\n const { start: from, end: to, text } = edit as Record<string, unknown>;\n const invalid =\n offsetProblem(\"whose start\", from, 0, length) ??\n offsetProblem(\"whose end\", to, from as number, length) ??\n (typeof text === \"string\" ? undefined : `whose text is ${shown(text)}, not a string`);\n if (invalid) return `returned an edit ${invalid}`;\n }\n return undefined;\n}\n/**\n * Whether an edit would change text that the parser read where renderers may\n * read a list, or a block indented below it, which renderers may read inside\n * that list (`misreadLists`, issue #191): replace some of their characters, or\n * insert text between two of them. Renderers may read such text as list items\n * or code, and the indentation of the blocks below it otherwise, which the\n * safety check, comparing the parser's readings, cannot see: `_r_` for `*r*`\n * in `- 0. *r*` below a paragraph changes code on GitHub. Only the part of\n * the edit that changes the text counts, so that an edit that copies such\n * text, such as a list rule's, can still apply.\n */\nfunction misreadEdits(document: Document): (edit: Edit) => boolean {\n const misread = misreadLists(document);\n // The blocks can hold one another; their union, in order, is searched in O(log n).\n const blocks: [number, number][] = [];\n for (const [start, end] of Array.from([...misread.text, ...misread.nested], (node) =>\n range(node),\n ).sort((a, b) => a[0] - b[0])) {\n const last = blocks.at(-1);\n if (last && start < last[1]) last[1] = Math.max(last[1], end);\n else blocks.push([start, end]);\n }\n if (!blocks.length) return () => false;\n const { source } = document;\n const within = (from: number, to: number) => {\n let low = 0;\n let high = blocks.length;\n while (low < high) {\n const middle = (low + high) >> 1;\n if (blocks[middle]![1] <= from) low = middle + 1;\n else high = middle;\n }\n const block = blocks[low];\n return block !== undefined && from < block[1] && to > block[0];\n };\n return (edit) => {\n if (!within(edit.start, edit.end)) return false;\n const before = source.slice(edit.start, edit.end);\n const { text } = edit;\n if (before === text) return false;\n const shorter = Math.min(before.length, text.length);\n let prefix = 0;\n while (prefix < shorter && before[prefix] === text[prefix]) prefix++;\n let suffix = 0;\n while (suffix < shorter - prefix && before.at(-1 - suffix) === text.at(-1 - suffix)) suffix++;\n return within(edit.start + prefix, edit.end - suffix);\n };\n}\n/**\n * The workspace of a run as the engine and its rules use it, and the errors\n * that it threw. Such an error is the host's, such as a file that could not be\n * read, and neither a rule's nor a refusal to format: it stops the run.\n */\ninterface Host {\n workspace?: Workspace;\n errors: Set<unknown>;\n}\nfunction host(workspace: Workspace | undefined): Host {\n const errors = new Set<unknown>();\n return workspace ? { workspace: guarded(workspace, errors), errors } : { errors };\n}\n/**\n * `workspace` as rules see it. What its `resolve` throws is added to `errors`:\n * such an error is the host's, such as a file that could not be read, and not\n * the rule's. Rules still see it as it was thrown.\n */\nfunction guarded(workspace: Workspace, errors: Set<unknown>): Workspace {\n const resolve: Workspace[\"resolve\"] = (...query) => {\n try {\n return workspace.resolve(...query);\n } catch (error) {\n errors.add(error);\n throw error;\n }\n };\n // Other members, such as a host's own, reach the workspace itself.\n return new Proxy(workspace, {\n get(target, key) {\n if (key === \"resolve\") return resolve;\n const value: unknown = Reflect.get(target, key);\n return typeof value === \"function\" ? (value as () => unknown).bind(target) : value;\n },\n });\n}\n/** A thrown value as text, without letting it throw again. */\nfunction failure(error: unknown): string {\n try {\n return error instanceof Error ? `${error.name}: ${error.message}` : String(error);\n } catch {\n return \"a value that cannot be shown\";\n }\n}\n/**\n * The diagnostics of the enabled rules that `include` selects. A rule that\n * throws, or returns something that is not a list of valid findings, is\n * skipped for the document and reported as `engine/rule-error` instead. An\n * error of the workspace itself, such as a file that could not be read, is\n * not the rule's and is thrown on. Suppressed findings are left out, and so\n * are findings whose edits would change text that the parser read in place of\n * a list, or the blocks that renderers read inside that list: the finding\n * describes what the parser read, and following it by hand would make the\n * change too.\n */\nfunction inspect(\n document: Document,\n config: ResolvedConfig,\n rules: Record<string, Rule>,\n { workspace, errors: hostErrors }: Host,\n include: (rule: Rule) => boolean = () => true,\n): Diagnostic[] {\n const result: Diagnostic[] = [];\n const suppressed = suppressions(document);\n const misread = misreadEdits(document);\n const starts = lineStarts(document.source);\n for (const [name, value] of Object.entries(config.rules)) {\n const enabled = setting(value);\n const rule = rules[name]!;\n if (enabled.severity === \"off\" || !include(rule)) continue;\n let findings: Finding[] = [];\n let problem: string | undefined;\n try {\n const returned: unknown = rule.check({\n document,\n options: enabled.options,\n ...(workspace ? { workspace } : {}),\n });\n problem = findingsProblem(returned, document.source.length);\n if (!problem) findings = returned as Finding[];\n } catch (error) {\n if (hostErrors.has(error)) throw error;\n problem = `failed (${failure(error)})`;\n }\n if (problem) {\n result.push(\n diagnostic([0], \"engine/rule-error\", \"error\", {\n start: 0,\n message: `Rule ${name} ${problem}; the rule was skipped for this document.`,\n }),\n );\n continue;\n }\n for (const finding of findings)\n if (!suppressed(name, finding) && !(finding.edit && misread(finding.edit)))\n result.push(diagnostic(starts, name, enabled.severity, finding));\n }\n return result.sort(sortDiagnostics);\n}\n/**\n * Locate diagnostics of a document that `parse` read without the byte order\n * marks it starts with in the text as given, so that their edits apply to that\n * text. Lines and columns stay as they are: the marks are invisible.\n */\nfunction located(diagnostics: Diagnostic[], mark: string): Diagnostic[] {\n if (!mark) return diagnostics;\n const by = mark.length;\n return diagnostics.map((item) => ({\n ...item,\n start: item.start + by,\n ...(item.end !== undefined ? { end: item.end + by } : {}),\n ...(item.edit\n ? { edit: { ...item.edit, start: item.edit.start + by, end: item.edit.end + by } }\n : {}),\n }));\n}\n/**\n * The diagnostics of the enabled rules for `source`, sorted by position. A rule\n * that fails is skipped and reported as `engine/rule-error`. An invalid\n * configuration, an unknown rule, invalid rule options, an invalid plugin, and\n * an error that the workspace throws are thrown.\n */\nexport function lint(source: string, options: ProcessOptions = {}): Diagnostic[] {\n if (options.ranges) checkRanges(options.ranges, source);\n const { config, rules } = prepare(options);\n const [mark, text] = splitByteOrderMark(source);\n const document = parse(text, config.dialect, options.path, options.plugins);\n const diagnostics = inspect(document, config, rules, host(options.workspace));\n // Ranges count the marks, and the document's positions do not.\n const scope =\n options.ranges && widen(document.tree, document.source, shifted(options.ranges, -mark.length));\n return located(\n scope\n ? diagnostics.filter((item) => fromEngine(item) || covers(scope, item.start))\n : diagnostics,\n mark,\n );\n}\n/**\n * `source` with `edits` applied, which are `{ start, end, text }` replacements\n * at UTF-16 offsets into it. Repeats of one edit count once; an edit outside\n * the source, or one that overlaps another, is an error.\n */\nexport function applyEdits(source: string, edits: readonly Edit[]): string {\n return splice(source, acceptedEdits(source, edits));\n}\n/** `source` with `edits`, which are sorted and do not overlap, applied. */\nfunction splice(source: string, edits: readonly Edit[]): string {\n // Assemble the result in one pass; rebuilding the string per edit is quadratic.\n const parts: string[] = [];\n let cursor = 0;\n for (const edit of edits) {\n parts.push(source.slice(cursor, edit.start), edit.text);\n cursor = edit.end;\n }\n parts.push(source.slice(cursor));\n return parts.join(\"\");\n}\n/**\n * The edits that `applyEdits` applies, sorted by position and without repeats\n * of the same edit. An edit outside the source, or overlapping another one, is\n * an error.\n */\nfunction acceptedEdits(source: string, edits: readonly Edit[]): Edit[] {\n const sorted = [...edits].sort((a, b) => a.start - b.start || a.end - b.end);\n let previous: Edit | undefined;\n const accepted: Edit[] = [];\n for (const edit of sorted) {\n if (\n !Number.isInteger(edit.start) ||\n !Number.isInteger(edit.end) ||\n edit.start < 0 ||\n edit.end < edit.start ||\n edit.end > source.length\n )\n throw new Error(\"Rule returned an invalid edit range.\");\n if (\n previous &&\n edit.start === previous.start &&\n edit.end === previous.end &&\n edit.text === previous.text\n )\n continue;\n if (previous && (edit.start < previous.end || edit.start === previous.start))\n throw new Error(\n \"Enabled rules proposed overlapping edits; disable one of the conflicting rules.\",\n );\n accepted.push(edit);\n previous = edit;\n }\n return accepted;\n}\n/**\n * The meaning of a parsed document as text, which `format` compares before and\n * after edits to refuse a change of meaning: its syntax tree without positions,\n * with runs of whitespace in text alike, and with each link's destination as\n * the workspace resolves it, so that two spellings of one target are the same.\n */\nexport function semanticFingerprint(document: Document, workspace?: Workspace): string {\n return JSON.stringify(semanticTree(document, workspace));\n}\n/**\n * The document's meaning as plain data whose keys are in sorted order. With\n * `origins`, each object of the result that stands for a node of the document\n * is mapped to that node.\n */\nfunction semanticTree(\n document: Document,\n workspace?: Workspace,\n origins?: Map<unknown, Nodes>,\n): unknown {\n const canonicalUrl = (url: string, wiki = false) => {\n const resolution = workspace?.resolve(document.path, url, document.dialect, wiki);\n // A target that is uncertain, because a directory could not be read, is not\n // an identity: only the same spelling is known to name the same note.\n return resolution?.status === \"resolved\" && !resolution.unreadable\n ? `${resolution.target}#${resolution.fragment ?? \"\"}`\n : url;\n };\n // Keys are emitted in sorted order so the JSON text is canonical without a replacer.\n function normalize(node: Nodes, calloutHeader = false): unknown {\n if (node.type === \"wikiLink\") {\n const link = node.embed\n ? { label: node.label, type: \"embed\", url: canonicalUrl(node.target, true) }\n : {\n children: [{ type: \"text\", value: node.label ?? node.target }],\n title: null,\n type: \"link\",\n url: canonicalUrl(node.target, true),\n };\n origins?.set(link, node);\n return link;\n }\n const result: Record<string, unknown> = {};\n // Forgejo and Gitea read a heading's trailing `{...}` block as attributes,\n // character for character, where the tree holds ordinary inline content,\n // and generate the anchor from the heading's last line as written.\n if (node.type === \"heading\") {\n const attributes = headingAttributeSource(document, node);\n if (attributes !== undefined) result.attributes = attributes;\n const anchors = headingAnchorSource(document, node);\n if (anchors !== undefined) result.anchors = anchors;\n }\n if (calloutHeader && document.dialect !== \"commonmark\" && node.type === \"paragraph\") {\n const [start, end] = range(node);\n const header = document.source.slice(start, end).split(/\\r\\n|\\r|\\n/, 1)[0]!;\n if (startsWithMarker(header, node)) {\n // CommonMark merges an Obsidian callout's title, or the line of a\n // GitHub alert's marker, and the body into one paragraph. Preserve\n // their boundary too, also for a marker written as `\\[!NOTE]`.\n const title = header.replace(\n /^\\[!([\\w-]+)\\]/,\n (_, marker: string) => `[!${marker.toLowerCase()}]`,\n );\n result.calloutTitle = normalize(parse(title, document.dialect, document.path).tree);\n }\n }\n for (const key of Object.keys(node).sort()) {\n const value = (node as unknown as Record<string, unknown>)[key];\n if (key === \"position\" || key === \"data\") continue;\n if (key === \"children\" && \"children\" in node) {\n result.children = node.children.map((child, index) =>\n normalize(child, index === 0 && (node.type === \"blockquote\" || calloutHeader)),\n );\n } else if (key === \"url\" && typeof value === \"string\") result[key] = canonicalUrl(value);\n else if (key === \"value\" && node.type === \"text\") {\n let text = node.value.replace(/[ \\t\\r\\n]+/g, \" \");\n if (calloutHeader && document.dialect !== \"commonmark\")\n text = text.replace(\n /^\\[!([\\w-]+)\\]/,\n (_, marker: string) => `[!${marker.toLowerCase()}]`,\n );\n result[key] = text;\n } else if (key === \"value\" && node.type === \"inlineCode\")\n // A code span is compared by the text that GitHub shows, which its\n // value in the tree does not hold where it spans lines.\n result[key] = codeSpanText(node);\n // An image's description renders as plain text, and a reference's label\n // matches its definition with whitespace collapsed.\n else if ((key === \"alt\" || key === \"label\") && typeof value === \"string\")\n result[key] = value.replace(/[ \\t\\r\\n]+/g, \" \");\n else result[key] = value;\n }\n origins?.set(result, node);\n return result;\n }\n const result = normalize(document.tree) as Record<string, unknown>;\n // Where front matter would end inside a code block, an HTML block, or\n // display math, the document is read without it, and renderers read TOML\n // front matter as a paragraph. An edit has to keep the meaning of both\n // readings.\n const reading = otherReading(document.tree);\n if (reading) result.otherReading = normalize(reading);\n return result;\n}\n/** A part of a semantic tree that has children. */\ntype Branch = Record<string, unknown> & { children: unknown[] };\nconst isBranch = (value: unknown): value is Branch =>\n typeof value === \"object\" && value !== null && Array.isArray((value as Branch).children);\n/**\n * Where the meaning of `after` first differs from that of `before`, as an\n * offset into `before`'s source: the start of the first node, in document\n * order, whose meaning is not the same, or the end of the node that `after`\n * gives more content.\n */\nfunction divergence(before: Document, after: Document, workspace?: Workspace): number {\n const origins = new Map<unknown, Nodes>();\n let a = semanticTree(before, workspace, origins);\n let b = semanticTree(after, workspace);\n // Where only the other reading differs, the place is in that reading, and\n // otherwise in the document's own.\n const reading = (value: unknown) => (value as { otherReading?: unknown }).otherReading;\n if (\n isBranch(a) &&\n isBranch(b) &&\n isBranch(reading(a)) &&\n isBranch(reading(b)) &&\n JSON.stringify(a.children) === JSON.stringify(b.children)\n ) {\n a = reading(a);\n b = reading(b);\n }\n let offset = 0;\n for (;;) {\n const node = origins.get(a);\n // A node made up for the comparison, or one without a position, is placed at its parent.\n offset = node?.position?.start.offset ?? offset;\n if (!isBranch(a) || !isBranch(b)) return offset;\n const own = (value: Branch) =>\n JSON.stringify({ ...value, children: undefined, otherReading: undefined });\n if (own(a) !== own(b)) return offset;\n const { children } = b;\n const index = a.children.findIndex(\n (child, at) => JSON.stringify(child) !== JSON.stringify(children[at]),\n );\n if (index < 0) return node?.position?.end.offset ?? offset;\n a = a.children[index];\n b = children[index];\n }\n}\n/**\n * Format a document: apply the edits of the enabled style rules, in passes\n * until nothing changes, leaving out the edits of a rule that would change the\n * document's meaning. Byte order marks that it starts with stay in the output\n * and are not part of what the rules see. Errors are thrown as by `lint`.\n */\nexport function format(source: string, options: ProcessOptions = {}): FormatResult {\n if (options.ranges) checkRanges(options.ranges, source);\n const [mark, text] = splitByteOrderMark(source);\n // Ranges count the marks, and the document's positions do not.\n const result = formatText(text, options, options.ranges && shifted(options.ranges, -mark.length));\n return {\n output: mark + result.output,\n changed: result.changed,\n diagnostics: located(result.diagnostics, mark),\n ...(result.scope ? { scope: shifted(result.scope, mark.length) } : {}),\n };\n}\n/** An edit that a rule proposed, with the rule's ID. */\ninterface Proposal extends Edit {\n rule: string;\n}\nconst byPosition = (a: Edit, b: Edit) => a.start - b.start || a.end - b.end;\n/**\n * The proposals to apply together, in the order of the source. An edit that\n * overlaps one before it, or repeats it, is left out; the next pass, which\n * runs the rules again on the changed text, reconsiders it.\n */\nfunction compatible(proposals: readonly Proposal[]): Proposal[] {\n const result: Proposal[] = [];\n let previous: Proposal | undefined;\n for (const edit of [...proposals].sort(byPosition)) {\n if (previous && (edit.start < previous.end || edit.start === previous.start)) continue;\n result.push(edit);\n previous = edit;\n }\n return result;\n}\n/** Rule IDs as a list in prose. */\nfunction listed(names: Iterable<string>): string {\n const items = [...names];\n return items.length < 3\n ? items.join(\" and \")\n : `${items.slice(0, -1).join(\", \")}, and ${items.at(-1)}`;\n}\n/**\n * Format a document without byte order marks, limited to `ranges` in its\n * positions. Each phase applies the edits of its rules together when the\n * result means what the original document means. Otherwise it adds the rules'\n * edits one rule at a time and leaves out the edits of each rule that would\n * change the meaning; the result reports each such rule with the place where\n * the meaning would first differ. Passes repeat until one changes nothing;\n * formatting that does not settle leaves the whole document unchanged.\n */\nfunction formatText(\n source: string,\n options: ProcessOptions,\n ranges: SourceRange[] | undefined,\n): FormatResult {\n const { config, rules } = prepare(options);\n // What the workspace throws stops formatting, as it stops `lint`.\n const hosted = host(options.workspace);\n const { workspace } = hosted;\n let output = source;\n let document = parse(source, config.dialect, options.path, options.plugins);\n // Where edits may apply, in the positions of the current output.\n const initial = ranges && widen(document.tree, source, ranges);\n let scope = initial;\n // Engine findings concern the whole document and are always reported.\n const reported = (items: Diagnostic[]) =>\n scope ? items.filter((item) => fromEngine(item) || covers(scope!, item.start)) : items;\n const unchanged = (message: string): FormatResult => ({\n output: source,\n changed: false,\n diagnostics: [diagnostic([0], \"engine/unsafe-format\", \"error\", { start: 0, message })],\n ...(initial ? { scope: initial } : {}),\n });\n // The original fingerprint is only needed once an edit produces a candidate.\n let fingerprint: string | undefined;\n /** `candidate` parsed, and whether it means what the original document means. */\n const check = (candidate: string) => {\n const parsed = parse(candidate, config.dialect, options.path, options.plugins);\n // Every document accepted so far means what the original means, so the current one serves.\n fingerprint ??= semanticFingerprint(document, workspace);\n return {\n document: parsed,\n safe: semanticFingerprint(parsed, workspace) === fingerprint,\n };\n };\n const seen = new Set([source]);\n /** The rules whose edits changed the document in the latest pass. */\n let applied = new Set<string>();\n try {\n for (let pass = 0; pass < 8; pass++) {\n const before = output;\n const findings: Diagnostic[] = [];\n applied = new Set();\n /** The rules whose edits this pass left out, with the document before and after them. */\n const refused: { rule: string; before: Document; after: Document }[] = [];\n const accept = (edits: Proposal[], text: string, parsed: Document) => {\n output = text;\n // Rules consume the document without mutating it. Reuse the validated\n // tree until another phase changes its source, including final diagnostics.\n document = parsed;\n if (scope) scope = moved(scope, edits);\n for (const edit of edits) applied.add(edit.rule);\n };\n for (const phase of phases) {\n const diagnostics = inspect(\n document,\n config,\n rules,\n hosted,\n (rule) => rule.kind === \"style\" && (rule.phase ?? \"inline\") === phase,\n );\n findings.push(...diagnostics);\n // With ranges, an edit that reaches outside them is not applied. One\n // that changes nothing need not be tried, and must not hold others back.\n const proposals: Proposal[] = [];\n for (const { edit, rule } of diagnostics)\n if (\n edit &&\n (!scope || holds(scope, edit)) &&\n output.slice(edit.start, edit.end) !== edit.text\n )\n proposals.push({ start: edit.start, end: edit.end, text: edit.text, rule });\n // The rules of this phase whose edits would change the meaning.\n const excluded = new Set<string>();\n for (;;) {\n const edits = compatible(proposals.filter((edit) => !excluded.has(edit.rule)));\n if (!edits.length) break;\n const candidate = splice(output, edits);\n if (candidate === output) break;\n const tried = check(candidate);\n if (tried.safe) {\n accept(edits, candidate, tried.document);\n break;\n }\n // Taken only when a phase fails, so the usual path parses each candidate once.\n let kept: Proposal[] = [];\n let keptOutput = output;\n let keptDocument = document;\n for (const rule of new Set(edits.map((edit) => edit.rule))) {\n const trial = [...kept, ...edits.filter((edit) => edit.rule === rule)].sort(byPosition);\n // All the edits together are already known to fail.\n const whole = trial.length === edits.length;\n const text = whole ? candidate : splice(output, trial);\n const result = whole ? tried : check(text);\n if (result.safe) {\n kept = trial;\n keptOutput = text;\n keptDocument = result.document;\n } else {\n excluded.add(rule);\n refused.push({ rule, before: document, after: result.document });\n }\n }\n if (keptOutput !== output) {\n accept(kept, keptOutput, keptDocument);\n break;\n }\n // Nothing was kept: the edits that overlapped refused ones get their turn.\n }\n }\n if (output === before) {\n // No phase changed the document, so every style finding of this pass\n // describes the final document; only the non-style rules still need to run.\n const remaining = inspect(document, config, rules, hosted, (rule) => rule.kind !== \"style\");\n // A refusal of this pass was tried on the final text, unless one\n // phase undid what an earlier one did.\n const starts = refused.length ? lineStarts(output) : [];\n const refusals = refused.map(({ rule, before: tried, after }) => {\n const start = tried.source === output ? divergence(tried, after, workspace) : 0;\n const { line } = diagnostic(starts, rule, \"error\", { start, message: \"\" });\n return diagnostic(starts, \"engine/unsafe-format\", \"error\", {\n start,\n message: `${rule} would change the parsed meaning at line ${line}; none of its edits were applied.`,\n });\n });\n return {\n output,\n changed: output !== source,\n diagnostics: reported([...findings, ...remaining, ...refusals]).sort(sortDiagnostics),\n ...(scope ? { scope } : {}),\n };\n }\n if (seen.has(output))\n return unchanged(\n `Formatting by ${listed(applied)} oscillates; the document was left unchanged.`,\n );\n seen.add(output);\n }\n return unchanged(\n `Formatting by ${listed(applied)} did not converge in eight passes; the document was left unchanged.`,\n );\n } catch (error) {\n if (hosted.errors.has(error)) throw error;\n return unchanged(error instanceof Error ? error.message : String(error));\n }\n}\n"]}
|
package/dist/rules/blocks.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import stringWidth from "string-width";
|
|
2
|
-
import { frontMatterReading, range, startsWithMarker, unclosedFrontMatter, } from "../syntax/parse.js";
|
|
2
|
+
import { belowTomlFrontMatter, frontMatterReading, joinsTomlFrontMatter, range, startsWithMarker, unclosedFrontMatter, } from "../syntax/parse.js";
|
|
3
3
|
import { walk } from "../syntax/walk.js";
|
|
4
4
|
/** A JSON Schema for an options object with these properties and no others. */
|
|
5
5
|
function schema(properties) {
|
|
@@ -290,6 +290,12 @@ const thematicBreak = {
|
|
|
290
290
|
lineStart(source, start) === start &&
|
|
291
291
|
unclosedFrontMatter(source) === "---")
|
|
292
292
|
return;
|
|
293
|
+
// Renderers without TOML front matter read its lines as a paragraph,
|
|
294
|
+
// which a line of `---` directly below underlines as a heading, as one
|
|
295
|
+
// written there already does (issue #333).
|
|
296
|
+
if ((marker === "---" && belowTomlFrontMatter(document.tree, node)) ||
|
|
297
|
+
joinsTomlFrontMatter(document.tree, node))
|
|
298
|
+
return;
|
|
293
299
|
// On the line of list items whose markers are the new marker's character,
|
|
294
300
|
// the items and the break would become one thematic break, as `- ---`,
|
|
295
301
|
// `1. - ---`, and `* ***` are.
|
|
@@ -299,10 +305,11 @@ const thematicBreak = {
|
|
|
299
305
|
return;
|
|
300
306
|
if (marker === "---") {
|
|
301
307
|
// Directly below a paragraph or a link reference definition, `---`
|
|
302
|
-
// would underline it as a heading
|
|
308
|
+
// would underline it as a heading, and so it would display math,
|
|
309
|
+
// which GitHub builds from a paragraph (issue #336).
|
|
303
310
|
const above = index && parent ? lastBlock(parent.children[index - 1]) : undefined;
|
|
304
311
|
if (above &&
|
|
305
|
-
(above.type === "paragraph" || above.type === "definition") &&
|
|
312
|
+
(above.type === "paragraph" || above.type === "definition" || above.type === "math") &&
|
|
306
313
|
above.position?.end.line === node.position.start.line - 1)
|
|
307
314
|
return;
|
|
308
315
|
}
|