mdrefine 0.2.2 → 0.2.4

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 CHANGED
@@ -8,6 +8,40 @@ 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.4 - 2026-10-19
12
+
13
+ ### Fixed
14
+
15
+ - In the Forgejo and Gitea dialects, no rule changes a definition description
16
+ any more, a line starting with `: ` below its term, or the blocks indented
17
+ below it. Forgejo and Gitea read the description as blocks, where the parser
18
+ reads text: `style/emphasis` changed code in a fenced block there and the
19
+ anchor of a heading, and the list rules moved a list out of the description
20
+ ([#354](https://github.com/viell-dev/slop-markdown-tools/pull/354)).
21
+
22
+ ## 0.2.3 - 2026-10-19
23
+
24
+ ### Fixed
25
+
26
+ - `style/block-spacing` adds no blank line below a list whose last item ends in
27
+ a fenced code block without its closing fence. Renderers put that line into
28
+ the code, while the parser does not, so the safety check did not see the
29
+ change ([#351](https://github.com/viell-dev/slop-markdown-tools/pull/351)).
30
+ - `style/block-spacing` adds no blank line between text that the parser reads as
31
+ an underlined heading in place of a list, at the end of a list item or block
32
+ quote, and text on the line below it. Renderers read that text as more of the
33
+ list item's text, and the blank line split it off
34
+ ([#351](https://github.com/viell-dev/slop-markdown-tools/pull/351)).
35
+ - `links/path` and `links/notation` write a `|` in a table cell as `\|`, because
36
+ one that is not escaped ends the cell. Before, `links/path` wrote every
37
+ wikilink it rewrote with a plain `|`, so that it also reported one whose
38
+ destination already had the configured form, and wrote a `|` from a file or
39
+ folder name into a new destination; `links/notation` wrote a plain `|` into a
40
+ new wikilink or Markdown label. The safety check refused those edits, and with
41
+ them all of the rule's other edits in the document. `links/path` now changes
42
+ only a wikilink's destination and keeps the rest as written, also outside
43
+ tables ([#349](https://github.com/viell-dev/slop-markdown-tools/pull/349)).
44
+
11
45
  ## 0.2.2 - 2026-10-18
12
46
 
13
47
  ### Fixed
package/CONTRIBUTING.md CHANGED
@@ -7,6 +7,11 @@ write them for a reader who has not seen the code. Agents maintaining the
7
7
  repository also follow [AGENTS.md](AGENTS.md). Everyone follows the [code of
8
8
  conduct](CODE_OF_CONDUCT.md).
9
9
 
10
+ If an agent wrote your issue or pull request, open it with a short note, such as
11
+ a `> [!NOTE]` callout, that says so, names the model and the tool that ran it,
12
+ and says whether you reviewed it. The maintaining agents mark their own posts
13
+ the same way.
14
+
10
15
  ## Report a defect
11
16
 
12
17
  Search the open and closed
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.2
62
+ npm install --save-dev --save-exact mdrefine@0.2.4
63
63
  npx mdtools lint
64
64
  npx mdtools format --diff
65
65
  npx mdtools format --write
@@ -207,15 +207,17 @@ function findingsProblem(findings, length) {
207
207
  * insert text between two of them. Renderers may read such text as list items
208
208
  * or code, and the indentation of the blocks below it otherwise, which the
209
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
210
+ * in `- 0. *r*` below a paragraph changes code on GitHub. The same goes for
211
+ * a definition description on Forgejo and Gitea and the blocks below it, which
212
+ * those renderers read as the description's blocks (issue #344). Only the part
213
+ * of the edit that changes the text counts, so that an edit that copies such
212
214
  * text, such as a list rule's, can still apply.
213
215
  */
214
216
  function misreadEdits(document) {
215
217
  const misread = misreadLists(document);
216
218
  // The blocks can hold one another; their union, in order, is searched in O(log n).
217
219
  const blocks = [];
218
- for (const [start, end] of Array.from([...misread.text, ...misread.nested], (node) => range(node)).sort((a, b) => a[0] - b[0])) {
220
+ for (const [start, end] of Array.from([...misread.text, ...misread.nested, ...misread.descriptions], (node) => range(node)).sort((a, b) => a[0] - b[0])) {
219
221
  const last = blocks.at(-1);
220
222
  if (last && start < last[1])
221
223
  last[1] = Math.max(last[1], end);
@@ -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,YAAY,EACZ,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,4BAA4B,CAAC;AAC1D,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,UAAU;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EAAE;wBACzD,KAAK;wBACL,OAAO,EAAE,GAAG,IAAI,4CAA4C,IAAI,mCAAmC;qBACpG,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;gBACH,OAAO;oBACL,MAAM;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"]}
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,YAAY,EACZ,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,4BAA4B,CAAC;AAC1D,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,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AAE,EAAE,CAAC,CAAC;oBAC3E,OAAO,UAAU,CAAC,MAAM,EAAE,sBAAsB,EAAE,OAAO,EAAE;wBACzD,KAAK;wBACL,OAAO,EAAE,GAAG,IAAI,4CAA4C,IAAI,mCAAmC;qBACpG,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;gBACH,OAAO;oBACL,MAAM;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. The same goes for\n * a definition description on Forgejo and Gitea and the blocks below it, which\n * those renderers read as the description's blocks (issue #344). Only the part\n * of 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(\n [...misread.text, ...misread.nested, ...misread.descriptions],\n (node) => 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"]}
@@ -9,6 +9,15 @@ import type { Document, Edit, Rule } from "../core/types.js";
9
9
  * whatever contains it.
10
10
  */
11
11
  export declare function takesLines(node: Nodes): boolean;
12
+ /**
13
+ * Whether a blank line added directly below `node`, at its own level, would be
14
+ * read by renderers as part of a fenced code block that ends a list item in
15
+ * `node` and has no closing fence. Such a block runs to the end of the item,
16
+ * and renderers count the item's last blank lines as its content, while the
17
+ * parser does not (issue #350). A block quote ends at a blank line, and so
18
+ * does the code in it.
19
+ */
20
+ export declare function endsInOpenFence(source: string, node: Nodes): boolean;
12
21
  /**
13
22
  * Whether a line ending added at the end of the document would change its
14
23
  * last block. Besides the blocks of `takesLines`, the parser counts a last
@@ -101,6 +101,28 @@ export function takesLines(node) {
101
101
  }
102
102
  return unclosed(node) && (node.type === "obsidianComment" || !quoted);
103
103
  }
104
+ /**
105
+ * Whether a blank line added directly below `node`, at its own level, would be
106
+ * read by renderers as part of a fenced code block that ends a list item in
107
+ * `node` and has no closing fence. Such a block runs to the end of the item,
108
+ * and renderers count the item's last blank lines as its content, while the
109
+ * parser does not (issue #350). A block quote ends at a blank line, and so
110
+ * does the code in it.
111
+ */
112
+ export function endsInOpenFence(source, node) {
113
+ let item = false;
114
+ while (containers.has(node.type) && "children" in node && node.children.length) {
115
+ if (node.type === "blockquote")
116
+ return false;
117
+ if (node.type === "listItem")
118
+ item = true;
119
+ node = node.children.at(-1);
120
+ }
121
+ if (!item || node.type !== "code" || !located(node))
122
+ return false;
123
+ const fence = codeFence(source, node);
124
+ return fence !== undefined && !fence.close;
125
+ }
104
126
  /**
105
127
  * Whether a line ending added at the end of the document would change its
106
128
  * last block. Besides the blocks of `takesLines`, the parser counts a last