mdrefine 0.2.0-rc.3 → 0.2.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,EACd,cAAc,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAiBpE,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CACzB,MAAM,QAAQ,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,oBAAoB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAC/D,CAAC;AACzB,wEAAwE;AACx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C,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;QACvE,EAAE;QACF,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;KAC9B,CAAC,CAAC,CAAC;IACJ,IAAI,KAAK,CAAC,IAAI;QAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;;QAE9E,KAAK,MAAM,IAAI,IAAI,KAAK;YACtB,+EAA+E;YAC/E,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,GAAG,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CACvE,CAAC;AACR,CAAC,CAAC,CAAC;AACL,IAAI,CAAC;IACH,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC;AAC7B,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IACf,yEAAyE;IACzE,8EAA8E;IAC9E,oEAAoE;IACpE,IAAI,KAAK,YAAY,cAAc;QAAE,OAAO,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAChF,CAAC;QACJ,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC7F,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC;AACH,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { Command, CommanderError, InvalidArgumentError, Option } from \"commander\";\nimport { createTwoFilesPatch } from \"diff\";\nimport { readFile, realpath } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { format, lint, ruleRegistry } from \"../core/engine.js\";\nimport { loadConfig } from \"../config/load.js\";\nimport { dialectAliases, dialects, resolveConfig } from \"../config/resolve.js\";\nimport {\n replacementFailure,\n replacementProblem,\n skippedMessage,\n writeFormatted,\n} from \"../workspace/files.js\";\nimport { assumedDialect, checkRoot, discoverFrom } from \"../workspace/discovery.js\";\nimport { enclosingVault } from \"../workspace/vault.js\";\nimport { refusal, refusalText } from \"../workspace/access.js\";\nimport { decodeText, NotUtf8Error } from \"../workspace/encoding.js\";\nimport type { Diagnostic, DialectName } from \"../core/types.js\";\n\ninterface Flags {\n config?: string;\n root?: string;\n dialect?: DialectName;\n json?: boolean;\n check?: boolean;\n diff?: boolean;\n write?: boolean;\n stdinFilepath?: string;\n maxWarnings?: number;\n exclude?: string[];\n quiet?: boolean;\n fix?: boolean;\n}\nconst manifest = JSON.parse(\n await readFile(fileURLToPath(new URL(\"../../package.json\", import.meta.url)), \"utf8\"),\n) as { version: string };\n// Subcommands inherit these settings, so they come before the commands.\nconst program = new Command()\n .name(\"mdtools\")\n .description(\"Lint and format Markdown with explicit dialects and configurable rules.\")\n .version(manifest.version, \"-V, --version\", \"Print the version\")\n .helpOption(\"-h, --help\", \"Print help for the command\")\n .helpCommand(\"help [command]\", \"Print help for a command\")\n // Commander starts its messages with \"error: \", the tool with its name.\n .configureOutput({\n outputError: (text, write) => write(`mdtools: ${text.replace(/^error: /, \"\")}`),\n })\n // Throw instead of exiting, so that a usage error can end with code 2.\n .exitOverride();\nconst configOption = [\n \"--config <file>\",\n \"Use this JSON, JSONC, or JavaScript configuration file instead of searching for one\",\n] as const;\n/** The dialects, each with its other names, as in \"forgejo (alias: codeberg)\". */\nconst dialectList = dialects\n .map((dialect) => {\n const aliases = Object.entries(dialectAliases).flatMap(([name, of]) =>\n of === dialect ? [name] : [],\n );\n return aliases.length ? `${dialect} (alias: ${aliases.join(\", \")})` : dialect;\n })\n .join(\", \");\n/** The options that choose the configuration, the workspace, and the dialect. */\nfunction workspaceOptions(command: Command): Command {\n return command\n .option(...configOption)\n .option(\n \"--root <directory>\",\n \"Workspace root (default: the configuration file's directory; without one, the Git repository or vault where the search stopped, else the current directory)\",\n )\n .option(\n \"--dialect <dialect>\",\n `${dialectList} (when none is named: github, or obsidian inside a vault)`,\n (value: string) => {\n if (!Object.hasOwn(dialectAliases, value) && !(dialects as string[]).includes(value))\n throw new InvalidArgumentError(`The dialects are ${dialectList}.`);\n return value as DialectName;\n },\n );\n}\nfunction common(command: Command): Command {\n return (\n workspaceOptions(command)\n .option(\n \"--exclude <path>\",\n \"Exclude an exact file or directory (repeatable)\",\n (value: string, previous: string[] = []) => [...previous, value],\n )\n .option(\"--json\", \"Machine-readable output\")\n .option(\"--quiet\", \"Report errors only: leave warnings out of the report and its counts\")\n .option(\"--stdin-filepath <file>\", \"Filename context for stdin\")\n .option(\n \"--max-warnings <count>\",\n \"Fail when warning count exceeds this nonnegative integer\",\n (value: string) => {\n const number = Number(value);\n if (!Number.isInteger(number) || number < 0)\n throw new Error(\"--max-warnings must be a nonnegative integer.\");\n return number;\n },\n )\n // Not an option: `run` answers it with the option that does what it asks for.\n .addOption(new Option(\"--fix\").hideHelp())\n );\n}\n/**\n * The configuration and workspace root that the options name. `--dialect` is\n * applied to a copy, because an .mjs configuration may export a frozen object.\n */\nasync function workspace(flags: Flags) {\n // Without this check the first thing to fail would be the search for a\n // configuration file in the root, with a message about a file the user never named.\n if (flags.root !== undefined) await checkRoot(flags.root);\n const loaded = await loadConfig(path.resolve(flags.root ?? \".\"), flags.config);\n return {\n ...loaded,\n root: path.resolve(flags.root ?? loaded.root),\n config: flags.dialect ? { ...loaded.config, dialect: flags.dialect } : loaded.config,\n };\n}\n/**\n * The real path of `file`, which need not exist: the real path of the nearest\n * directory above it that does, with the rest of `file` appended.\n */\nasync function located(file: string): Promise<string> {\n const rest: string[] = [];\n for (let current = path.resolve(file); ;) {\n try {\n return path.join(await realpath(current), ...rest);\n } catch {\n const parent = path.dirname(current);\n if (parent === current) return path.resolve(file);\n rest.unshift(path.basename(current));\n current = parent;\n }\n }\n}\n/**\n * The path of `file`, which need not exist, from the workspace root, with\n * forward slashes, or undefined when it lies outside. Both are located through\n * their real paths, as discovery locates files, so that a root reached through\n * a link still holds the files below it.\n */\nasync function workspacePath(root: string, file: string): Promise<string | undefined> {\n const actual = await realpath(root).catch(() => root);\n const name = path\n .relative(actual, await located(file))\n .split(path.sep)\n .join(\"/\");\n return name === \"..\" || name.startsWith(\"../\") || path.isAbsolute(name) ? undefined : name;\n}\n/** The library's diagnostics for a document that it could not process as configured. */\nconst failures = new Set([\"engine/unsafe-format\", \"engine/rule-error\"]);\ninterface Report {\n path: string;\n changed?: boolean;\n diagnostics: Diagnostic[];\n output?: string;\n}\nasync function run(mode: \"lint\" | \"format\", inputs: string[], flags: Flags) {\n // ESLint and markdownlint-cli2 fix with --fix, Prettier with --write.\n if (flags.fix)\n throw new Error(\n mode === \"lint\"\n ? \"unknown option '--fix': lint never changes files; 'mdtools format --write' applies the fixes.\"\n : \"unknown option '--fix': format writes its changes with --write.\",\n );\n if ([flags.check, flags.diff, flags.write].filter(Boolean).length > 1)\n throw new Error(\"Choose only one of --check, --diff, and --write.\");\n if (inputs.includes(\"-\") && flags.exclude?.length)\n throw new Error(\"--exclude cannot be combined with stdin.\");\n const { root, ...loaded } = await workspace(flags);\n const stdin = inputs.includes(\"-\");\n if (stdin && (inputs.length !== 1 || flags.write))\n throw new Error(\"stdin must be the only input and cannot be combined with --write.\");\n /** The text read from stdin, by the name it is given in the workspace. */\n let documents: Record<string, string> | undefined;\n if (stdin) {\n const name = await workspacePath(root, flags.stdinFilepath ?? path.join(root, \"stdin.md\"));\n if (name === undefined) throw new Error(\"--stdin-filepath must be within the workspace.\");\n const chunks: Buffer[] = [];\n for await (const chunk of process.stdin) chunks.push(chunk as Buffer);\n try {\n documents = { [name]: decodeText(Buffer.concat(chunks), \"stdin\") };\n } catch (error) {\n // There is no file to report it for, and nothing else to process.\n if (error instanceof NotUtf8Error)\n throw new Error(`stdin is not UTF-8 text (${error.reason})`, { cause: error });\n throw error;\n }\n }\n // Paths on the command line are relative to the working directory, and no\n // path selects the whole workspace; stdin is the only document then.\n const discovery = await discoverFrom(\n {\n root,\n ...(stdin ? { inputs: [] } : inputs.length ? { inputs } : {}),\n exclude: flags.exclude ?? [],\n config: loaded.config,\n plugins: loaded.plugins,\n ...(documents ? { documents } : {}),\n },\n process.cwd(),\n );\n const reports: Report[] = [];\n const changes: { file: string; before: string; after: string }[] = [];\n // Selected files that the system refused to let the tool read, or that are not UTF-8 text.\n const unread: string[] = [];\n for (const name of discovery.selected) {\n const options = discovery.options(name);\n let source: string;\n try {\n source = discovery.read(name);\n } catch (error) {\n // Report the file and carry on with the others; any other error is a fault.\n const code = refusal(error);\n const problem = code\n ? `could not be read (${refusalText(code)})`\n : error instanceof NotUtf8Error\n ? `is not UTF-8 text (${error.reason})`\n : undefined;\n if (!problem) throw error;\n unread.push(name);\n reports.push({\n path: name,\n ...(mode === \"format\" ? { changed: false } : {}),\n diagnostics: [\n {\n start: 0,\n message: `The file ${problem} and was not ${mode === \"lint\" ? \"linted\" : \"formatted\"}.`,\n rule: \"engine/unreadable-file\",\n severity: \"error\",\n line: 1,\n column: 1,\n },\n ],\n });\n continue;\n }\n if (mode === \"lint\") reports.push({ path: name, diagnostics: lint(source, options) });\n else {\n const result = format(source, options);\n reports.push({\n path: name,\n changed: result.changed,\n diagnostics: result.diagnostics,\n ...(stdin && !flags.check ? { output: result.output } : {}),\n });\n if (result.changed) changes.push({ file: name, before: source, after: result.output });\n }\n }\n // A document that could not be read, had a rule refused or failing on it, or\n // could not be written is a failure to operate, reported for its own file,\n // and the run ends with status 2. Files do not depend on one another's\n // content, so every other changed document is still written, and so is the\n // result of one with a refused or failing rule, which the engine checked.\n const failed =\n unread.length > 0 ||\n reports.some((report) => report.diagnostics.some((item) => failures.has(item.rule)));\n // Changed files that could not be written, each reported for its file.\n const unwritten: string[] = [];\n const refuse = (file: string, message: string) => {\n unwritten.push(file);\n reports\n .find((report) => report.path === file)!\n .diagnostics.unshift({\n start: 0,\n message: `${message}.`,\n rule: \"engine/unwritable-file\",\n severity: \"error\",\n line: 1,\n column: 1,\n });\n };\n // The files that were written, in the order of the report.\n const written: string[] = [];\n if (flags.write)\n for (const change of changes) {\n const file = path.join(discovery.root, change.file);\n // A file that may not be written, such as a read-only one, is left alone.\n const problem = await replacementProblem(file);\n if (problem) {\n refuse(change.file, `${problem}; the file is unchanged`);\n continue;\n }\n try {\n await writeFormatted(file, change.before, change.after);\n written.push(change.file);\n } catch (error) {\n const failure = replacementFailure(error);\n if (!failure) throw error;\n refuse(change.file, failure);\n }\n }\n // As in ESLint, --quiet leaves warnings out of the report and of what counts them.\n if (flags.quiet)\n for (const report of reports)\n report.diagnostics = report.diagnostics.filter((item) => item.severity !== \"warn\");\n const diagnostics = reports.flatMap((report) => report.diagnostics);\n const count = (severity: Diagnostic[\"severity\"]) =>\n diagnostics.filter((item) => item.severity === severity).length;\n if (flags.json)\n process.stdout.write(\n JSON.stringify(\n {\n version: manifest.version,\n mode,\n // The files' paths are relative to it, for programs to join.\n root,\n files: reports,\n written,\n ...(discovery.skipped.length ? { skipped: discovery.skipped } : {}),\n },\n null,\n 2,\n ) + \"\\n\",\n );\n else {\n // Text names documents from the current directory, as Prettier does, so\n // that a terminal or an editor opens them from where the command ran.\n const here = await realpath(process.cwd()).catch(() => process.cwd());\n const shown = (name: string) =>\n path.relative(here, path.join(discovery.root, name)).split(path.sep).join(\"/\");\n // Warnings about the run, not about a document: they do not change the exit status.\n for (const item of discovery.skipped)\n process.stderr.write(`mdtools: warning: ${skippedMessage(item, shown)}\\n`);\n if (stdin && mode === \"format\" && !flags.check && !flags.diff)\n process.stdout.write(reports[0]?.output ?? \"\");\n else if (mode === \"format\" && !flags.check && !flags.write)\n for (const change of changes)\n process.stdout.write(\n createTwoFilesPatch(\n `a/${shown(change.file)}`,\n `b/${shown(change.file)}`,\n change.before,\n change.after,\n ),\n );\n for (const report of reports)\n for (const item of report.diagnostics)\n process.stderr.write(\n `${shown(report.path)}:${item.line}:${item.column}: ${item.severity} ${item.rule}: ${item.message}\\n`,\n );\n // The files to fix when a check fails, as Prettier's --check lists them.\n if (mode === \"format\" && flags.check && !stdin)\n for (const change of changes) process.stderr.write(`${shown(change.file)}\\n`);\n if (!stdin) {\n // Lint changes nothing, so its summary counts what it reported instead.\n const outcome =\n mode === \"lint\"\n ? `${count(\"error\")} error(s), ${count(\"warn\")} warning(s)`\n : flags.write\n ? `${written.length} written`\n : `${changes.length} would change`;\n process.stderr.write(\n `${discovery.selected.length - unread.length} file(s) ${mode === \"lint\" ? \"linted\" : \"processed\"}; ${outcome}${unread.length ? `; ${unread.length} could not be read` : \"\"}${unwritten.length ? `; ${unwritten.length} could not be written` : \"\"}.\\n`,\n );\n }\n }\n const errors = count(\"error\") > 0;\n const tooManyWarnings = flags.maxWarnings !== undefined && count(\"warn\") > flags.maxWarnings;\n process.exitCode =\n failed || unwritten.length > 0\n ? 2\n : errors || tooManyWarnings || (flags.check && changes.length > 0)\n ? 1\n : 0;\n}\ncommon(\n program\n .command(\"lint\")\n .argument(\"[paths...]\", \"Files, directories, or glob patterns to select, or - for stdin\"),\n)\n .description(\"Report the findings of the enabled rules; never writes\")\n .action((inputs: string[], flags: Flags) => run(\"lint\", inputs, flags));\ncommon(\n program\n .command(\"format\")\n .argument(\"[paths...]\", \"Files, directories, or glob patterns to select, or - for stdin\"),\n)\n .description(\"Format documents: print a diff (the default), check, or write\")\n .option(\"--check\", \"Fail if formatting changes would be needed, and name the files\")\n .option(\"--diff\", \"Preview the complete diff (default for file inputs)\")\n .option(\"--write\", \"Write validated formatting changes\")\n .action((inputs: string[], flags: Flags) => run(\"format\", inputs, flags));\n// The options belong to `config`, which reads them before or after `explain`;\n// `explain` repeats them so that its help lists them.\nworkspaceOptions(\n workspaceOptions(program.command(\"config\").description(\"Inspect the configuration\"))\n .command(\"explain\")\n .description(\"Print, as JSON, the configuration in effect for one document\")\n .argument(\"<file>\", \"The document, which need not exist\"),\n).action(async (file: string, _flags: unknown, command: Command) => {\n const flags = command.optsWithGlobals<Flags>();\n const { root, config, plugins, file: source } = await workspace(flags);\n const name = await workspacePath(root, file);\n if (name === undefined) throw new Error(`Input is outside the workspace: ${file}`);\n // The search for the document's vault starts from the root's real path too.\n const actual = await realpath(root).catch(() => root);\n process.stdout.write(\n JSON.stringify(\n {\n root,\n config: source ?? null,\n path: name,\n effective: resolveConfig({\n config,\n path: name,\n plugins,\n defaultDialect: assumedDialect(await enclosingVault(path.join(actual, name))),\n }),\n },\n null,\n 2,\n ) + \"\\n\",\n );\n});\nprogram\n .command(\"rules\")\n .description(\"List the built-in rules and those of the configuration's plugins\")\n .option(...configOption)\n .option(\"--json\", \"Print the list as JSON\")\n .action(async (flags: Flags) => {\n const { plugins } = await loadConfig(path.resolve(\".\"), flags.config);\n const rules = Object.entries(ruleRegistry(plugins)).map(([id, rule]) => ({\n id,\n kind: rule.kind,\n description: rule.description,\n }));\n if (flags.json) process.stdout.write(JSON.stringify({ rules }, null, 2) + \"\\n\");\n else\n for (const rule of rules)\n // One line per rule, even when a plugin's description has line breaks or tabs.\n process.stdout.write(\n `${rule.id}\\t${rule.kind}\\t${rule.description.replace(/\\s+/g, \" \")}\\n`,\n );\n });\ntry {\n await program.parseAsync();\n} catch (error) {\n // Commander has printed the help, the version, or what is wrong with the\n // command line. Help and the version succeed; a usage error ends with code 2,\n // as in ESLint and Prettier, so that it does not pass for findings.\n if (error instanceof CommanderError) process.exitCode = error.exitCode === 0 ? 0 : 2;\n else {\n process.stderr.write(`mdtools: ${error instanceof Error ? error.message : String(error)}\\n`);\n process.exitCode = 2;\n }\n}\n"]}
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,oBAAo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derError, InvalidArgumentError, Option } from \"commander\";\nimport { readFile, realpath } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { format, lint, ruleRegistry } from \"../core/engine.js\";\nimport { loadConfig } from \"../config/load.js\";\nimport { dialectAliases, dialects, resolveConfig } from \"../config/resolve.js\";\nimport {\n isIgnoredInput,\n replacementFailure,\n replacementProblem,\n skippedMessage,\n writeFormatted,\n} from \"../workspace/files.js\";\nimport { assumedDialect, checkRoot, discoverFrom } from \"../workspace/discovery.js\";\nimport { enclosingVault } from \"../workspace/vault.js\";\nimport { refusal, refusalText } from \"../workspace/access.js\";\nimport { decodeText, NotUtf8Error } from \"../workspace/encoding.js\";\nimport { unifiedDiff } from \"./diff.js\";\nimport type { Diagnostic, DialectName } from \"../core/types.js\";\n\ninterface Flags {\n config?: string;\n root?: string;\n dialect?: DialectName;\n json?: boolean;\n check?: boolean;\n diff?: boolean;\n write?: boolean;\n stdinFilepath?: string;\n maxWarnings?: number;\n exclude?: string[];\n quiet?: boolean;\n /** False with `--no-warn-ignored`. */\n warnIgnored?: boolean;\n fix?: boolean;\n}\nconst manifest = JSON.parse(\n await readFile(fileURLToPath(new URL(\"../../package.json\", import.meta.url)), \"utf8\"),\n) as { version: string };\n// Subcommands inherit these settings, so they come before the commands.\nconst program = new Command()\n .name(\"mdtools\")\n .description(\"Lint and format Markdown with explicit dialects and configurable rules.\")\n .version(manifest.version, \"-V, --version\", \"Print the version\")\n .helpOption(\"-h, --help\", \"Print help for the command\")\n .helpCommand(\"help [command]\", \"Print help for a command\")\n // Commander starts its messages with \"error: \", the tool with its name.\n .configureOutput({\n outputError: (text, write) => write(`mdtools: ${text.replace(/^error: /, \"\")}`),\n })\n // Throw instead of exiting, so that a usage error can end with code 2.\n .exitOverride();\nconst configOption = [\n \"--config <file>\",\n \"Use this JSON, JSONC, or JavaScript configuration file instead of searching for one\",\n] as const;\n/** The dialects, each with its other names, as in \"forgejo (alias: codeberg)\". */\nconst dialectList = dialects\n .map((dialect) => {\n const aliases = Object.entries(dialectAliases).flatMap(([name, of]) =>\n of === dialect ? [name] : [],\n );\n return aliases.length ? `${dialect} (alias: ${aliases.join(\", \")})` : dialect;\n })\n .join(\", \");\n/** The options that choose the configuration, the workspace, and the dialect. */\nfunction workspaceOptions(command: Command): Command {\n return command\n .option(...configOption)\n .option(\n \"--root <directory>\",\n \"Workspace root (default: the configuration file's directory; without one, the Git repository or vault where the search stopped, else the current directory)\",\n )\n .option(\n \"--dialect <dialect>\",\n `${dialectList} (when none is named: github, or obsidian inside a vault)`,\n (value: string) => {\n if (!Object.hasOwn(dialectAliases, value) && !(dialects as string[]).includes(value))\n throw new InvalidArgumentError(`The dialects are ${dialectList}.`);\n return value as DialectName;\n },\n );\n}\nfunction common(command: Command): Command {\n return (\n workspaceOptions(command)\n .option(\n \"--exclude <path>\",\n \"Exclude an exact file or directory (repeatable)\",\n (value: string, previous: string[] = []) => [...previous, value],\n )\n .option(\"--json\", \"Machine-readable output\")\n .option(\"--quiet\", \"Report errors only: leave warnings out of the report and its counts\")\n .option(\n \"--no-warn-ignored\",\n \"Do not warn about named files and directories that are skipped as ignored\",\n )\n .option(\"--stdin-filepath <file>\", \"Filename context for stdin\")\n .option(\n \"--max-warnings <count>\",\n \"Fail when warning count exceeds this nonnegative integer\",\n (value: string) => {\n const number = Number(value);\n if (!Number.isInteger(number) || number < 0)\n throw new Error(\"--max-warnings must be a nonnegative integer.\");\n return number;\n },\n )\n // Not an option: `run` answers it with the option that does what it asks for.\n .addOption(new Option(\"--fix\").hideHelp())\n );\n}\n/**\n * The configuration and workspace root that the options name. `--dialect` is\n * applied to a copy, because an .mjs configuration may export a frozen object.\n */\nasync function workspace(flags: Flags) {\n // Without this check the first thing to fail would be the search for a\n // configuration file in the root, with a message about a file the user never named.\n if (flags.root !== undefined) await checkRoot(flags.root);\n const loaded = await loadConfig(path.resolve(flags.root ?? \".\"), flags.config);\n return {\n ...loaded,\n root: path.resolve(flags.root ?? loaded.root),\n config: flags.dialect ? { ...loaded.config, dialect: flags.dialect } : loaded.config,\n };\n}\n/**\n * The real path of `file`, which need not exist: the real path of the nearest\n * directory above it that does, with the rest of `file` appended.\n */\nasync function located(file: string): Promise<string> {\n const rest: string[] = [];\n for (let current = path.resolve(file); ;) {\n try {\n return path.join(await realpath(current), ...rest);\n } catch {\n const parent = path.dirname(current);\n if (parent === current) return path.resolve(file);\n rest.unshift(path.basename(current));\n current = parent;\n }\n }\n}\n/**\n * The path of `file`, which need not exist, from the workspace root, with\n * forward slashes, or undefined when it lies outside. Both are located through\n * their real paths, as discovery locates files, so that a root reached through\n * a link still holds the files below it.\n */\nasync function workspacePath(root: string, file: string): Promise<string | undefined> {\n const actual = await realpath(root).catch(() => root);\n const name = path\n .relative(actual, await located(file))\n .split(path.sep)\n .join(\"/\");\n return name === \"..\" || name.startsWith(\"../\") || path.isAbsolute(name) ? undefined : name;\n}\n/** The library's diagnostics for a document that it could not process as configured. */\nconst failures = new Set([\"engine/unsafe-format\", \"engine/rule-error\"]);\ninterface Report {\n path: string;\n changed?: boolean;\n diagnostics: Diagnostic[];\n output?: string;\n}\nasync function run(mode: \"lint\" | \"format\", inputs: string[], flags: Flags) {\n // ESLint and markdownlint-cli2 fix with --fix, Prettier with --write.\n if (flags.fix)\n throw new Error(\n mode === \"lint\"\n ? \"unknown option '--fix': lint never changes files; 'mdtools format --write' applies the fixes.\"\n : \"unknown option '--fix': format writes its changes with --write.\",\n );\n if ([flags.check, flags.diff, flags.write].filter(Boolean).length > 1)\n throw new Error(\"Choose only one of --check, --diff, and --write.\");\n if (inputs.includes(\"-\") && flags.exclude?.length)\n throw new Error(\"--exclude cannot be combined with stdin.\");\n const { root, ...loaded } = await workspace(flags);\n const stdin = inputs.includes(\"-\");\n if (stdin && (inputs.length !== 1 || flags.write))\n throw new Error(\"stdin must be the only input and cannot be combined with --write.\");\n /** The text read from stdin, by the name it is given in the workspace. */\n let documents: Record<string, string> | undefined;\n if (stdin) {\n const name = await workspacePath(root, flags.stdinFilepath ?? path.join(root, \"stdin.md\"));\n if (name === undefined) throw new Error(\"--stdin-filepath must be within the workspace.\");\n const chunks: Buffer[] = [];\n for await (const chunk of process.stdin) chunks.push(chunk as Buffer);\n try {\n documents = { [name]: decodeText(Buffer.concat(chunks), \"stdin\") };\n } catch (error) {\n // There is no file to report it for, and nothing else to process.\n if (error instanceof NotUtf8Error)\n throw new Error(`stdin is not UTF-8 text (${error.reason})`, { cause: error });\n throw error;\n }\n }\n // Paths on the command line are relative to the working directory, and no\n // path selects the whole workspace; stdin is the only document then. Ignore\n // rules apply to the path that `--stdin-filepath` names, as to a named file,\n // and not to the default name.\n const discovery = await discoverFrom(\n {\n root,\n ...(stdin ? { inputs: [] } : inputs.length ? { inputs } : {}),\n exclude: flags.exclude ?? [],\n config: loaded.config,\n plugins: loaded.plugins,\n ...(documents ? { documents } : {}),\n },\n process.cwd(),\n flags.stdinFilepath !== undefined,\n );\n const reports: Report[] = [];\n const changes: { file: string; before: string; after: string }[] = [];\n // Selected files that the system refused to let the tool read, or that are not UTF-8 text.\n const unread: string[] = [];\n for (const name of discovery.selected) {\n const options = discovery.options(name);\n let source: string;\n try {\n source = discovery.read(name);\n } catch (error) {\n // Report the file and carry on with the others; any other error is a fault.\n const code = refusal(error);\n const problem = code\n ? `could not be read (${refusalText(code)})`\n : error instanceof NotUtf8Error\n ? `is not UTF-8 text (${error.reason})`\n : undefined;\n if (!problem) throw error;\n unread.push(name);\n reports.push({\n path: name,\n ...(mode === \"format\" ? { changed: false } : {}),\n diagnostics: [\n {\n start: 0,\n message: `The file ${problem} and was not ${mode === \"lint\" ? \"linted\" : \"formatted\"}.`,\n rule: \"engine/unreadable-file\",\n severity: \"error\",\n line: 1,\n column: 1,\n },\n ],\n });\n continue;\n }\n if (mode === \"lint\") reports.push({ path: name, diagnostics: lint(source, options) });\n else {\n const result = format(source, options);\n reports.push({\n path: name,\n changed: result.changed,\n diagnostics: result.diagnostics,\n ...(stdin && !flags.check ? { output: result.output } : {}),\n });\n if (result.changed) changes.push({ file: name, before: source, after: result.output });\n }\n }\n // A document that could not be read, had a rule refused or failing on it, or\n // could not be written is a failure to operate, reported for its own file,\n // and the run ends with status 2. Files do not depend on one another's\n // content, so every other changed document is still written, and so is the\n // result of one with a refused or failing rule, which the engine checked.\n const failed =\n unread.length > 0 ||\n reports.some((report) => report.diagnostics.some((item) => failures.has(item.rule)));\n // Changed files that could not be written, each reported for its file.\n const unwritten: string[] = [];\n const refuse = (file: string, message: string) => {\n unwritten.push(file);\n reports\n .find((report) => report.path === file)!\n .diagnostics.unshift({\n start: 0,\n message: `${message}.`,\n rule: \"engine/unwritable-file\",\n severity: \"error\",\n line: 1,\n column: 1,\n });\n };\n // The files that were written, in the order of the report.\n const written: string[] = [];\n if (flags.write)\n for (const change of changes) {\n const file = path.join(discovery.root, change.file);\n // A file that may not be written, such as a read-only one, is left alone.\n const problem = await replacementProblem(file);\n if (problem) {\n refuse(change.file, `${problem}; the file is unchanged`);\n continue;\n }\n try {\n await writeFormatted(file, change.before, change.after);\n written.push(change.file);\n } catch (error) {\n const failure = replacementFailure(error);\n if (!failure) throw error;\n refuse(change.file, failure);\n }\n }\n // As in ESLint, --quiet leaves warnings out of the report and of what counts them.\n if (flags.quiet)\n for (const report of reports)\n report.diagnostics = report.diagnostics.filter((item) => item.severity !== \"warn\");\n const diagnostics = reports.flatMap((report) => report.diagnostics);\n const count = (severity: Diagnostic[\"severity\"]) =>\n diagnostics.filter((item) => item.severity === severity).length;\n if (flags.json)\n process.stdout.write(\n JSON.stringify(\n {\n version: manifest.version,\n mode,\n // The files' paths are relative to it, for programs to join.\n root,\n files: reports,\n written,\n ...(discovery.skipped.length ? { skipped: discovery.skipped } : {}),\n },\n null,\n 2,\n ) + \"\\n\",\n );\n else {\n // Text names documents from the current directory, as Prettier does, so\n // that a terminal or an editor opens them from where the command ran.\n const here = await realpath(process.cwd()).catch(() => process.cwd());\n const shown = (name: string) =>\n path.relative(here, path.join(discovery.root, name)).split(path.sep).join(\"/\");\n // Warnings about the run, not about a document: they do not change the exit status.\n // A caller that passes every changed file can leave out those about ignored ones.\n for (const item of discovery.skipped)\n if (flags.warnIgnored !== false || !isIgnoredInput(item))\n process.stderr.write(`mdtools: warning: ${skippedMessage(item, shown)}\\n`);\n // An ignored document from stdin comes back unchanged, as in Prettier, so\n // that an editor that replaces its text with the output loses nothing.\n if (stdin && mode === \"format\" && !flags.check && !flags.diff)\n process.stdout.write(reports[0]?.output ?? Object.values(documents ?? {})[0] ?? \"\");\n else if (mode === \"format\" && !flags.check && !flags.write)\n for (const change of changes)\n process.stdout.write(\n unifiedDiff(\n `a/${shown(change.file)}`,\n `b/${shown(change.file)}`,\n change.before,\n change.after,\n ),\n );\n for (const report of reports)\n for (const item of report.diagnostics)\n process.stderr.write(\n `${shown(report.path)}:${item.line}:${item.column}: ${item.severity} ${item.rule}: ${item.message}\\n`,\n );\n // The files to fix when a check fails, as Prettier's --check lists them.\n if (mode === \"format\" && flags.check && !stdin)\n for (const change of changes) process.stderr.write(`${shown(change.file)}\\n`);\n if (!stdin) {\n // Lint changes nothing, so its summary counts what it reported instead.\n const outcome =\n mode === \"lint\"\n ? `${count(\"error\")} error(s), ${count(\"warn\")} warning(s)`\n : flags.write\n ? `${written.length} written`\n : `${changes.length} would change`;\n process.stderr.write(\n `${discovery.selected.length - unread.length} file(s) ${mode === \"lint\" ? \"linted\" : \"processed\"}; ${outcome}${unread.length ? `; ${unread.length} could not be read` : \"\"}${unwritten.length ? `; ${unwritten.length} could not be written` : \"\"}.\\n`,\n );\n }\n }\n const errors = count(\"error\") > 0;\n const tooManyWarnings = flags.maxWarnings !== undefined && count(\"warn\") > flags.maxWarnings;\n process.exitCode =\n failed || unwritten.length > 0\n ? 2\n : errors || tooManyWarnings || (flags.check && changes.length > 0)\n ? 1\n : 0;\n}\ncommon(\n program\n .command(\"lint\")\n .argument(\"[paths...]\", \"Files, directories, or glob patterns to select, or - for stdin\"),\n)\n .description(\"Report the findings of the enabled rules; never writes\")\n .action((inputs: string[], flags: Flags) => run(\"lint\", inputs, flags));\ncommon(\n program\n .command(\"format\")\n .argument(\"[paths...]\", \"Files, directories, or glob patterns to select, or - for stdin\"),\n)\n .description(\"Format documents: print a diff (the default), check, or write\")\n .option(\"--check\", \"Fail if formatting changes would be needed, and name the files\")\n .option(\"--diff\", \"Preview the complete diff (default for file inputs)\")\n .option(\"--write\", \"Write validated formatting changes\")\n .action((inputs: string[], flags: Flags) => run(\"format\", inputs, flags));\n// The options belong to `config`, which reads them before or after `explain`;\n// `explain` repeats them so that its help lists them.\nworkspaceOptions(\n workspaceOptions(program.command(\"config\").description(\"Inspect the configuration\"))\n .command(\"explain\")\n .description(\"Print, as JSON, the configuration in effect for one document\")\n .argument(\"<file>\", \"The document, which need not exist\"),\n).action(async (file: string, _flags: unknown, command: Command) => {\n const flags = command.optsWithGlobals<Flags>();\n const { root, config, plugins, file: source } = await workspace(flags);\n const name = await workspacePath(root, file);\n if (name === undefined) throw new Error(`Input is outside the workspace: ${file}`);\n // The search for the document's vault starts from the root's real path too.\n const actual = await realpath(root).catch(() => root);\n process.stdout.write(\n JSON.stringify(\n {\n root,\n config: source ?? null,\n path: name,\n effective: resolveConfig({\n config,\n path: name,\n plugins,\n defaultDialect: assumedDialect(await enclosingVault(path.join(actual, name))),\n }),\n },\n null,\n 2,\n ) + \"\\n\",\n );\n});\nprogram\n .command(\"rules\")\n .description(\"List the built-in rules and those of the configuration's plugins\")\n .option(...configOption)\n .option(\"--json\", \"Print the list as JSON\")\n .action(async (flags: Flags) => {\n const { plugins } = await loadConfig(path.resolve(\".\"), flags.config);\n const rules = Object.entries(ruleRegistry(plugins)).map(([id, rule]) => ({\n id,\n kind: rule.kind,\n description: rule.description,\n }));\n if (flags.json) process.stdout.write(JSON.stringify({ rules }, null, 2) + \"\\n\");\n else\n for (const rule of rules)\n // One line per rule, even when a plugin's description has line breaks or tabs.\n process.stdout.write(\n `${rule.id}\\t${rule.kind}\\t${rule.description.replace(/\\s+/g, \" \")}\\n`,\n );\n });\ntry {\n await program.parseAsync();\n} catch (error) {\n // Commander has printed the help, the version, or what is wrong with the\n // command line. Help and the version succeed; a usage error ends with code 2,\n // as in ESLint and Prettier, so that it does not pass for findings.\n if (error instanceof CommanderError) process.exitCode = error.exitCode === 0 ? 0 : 2;\n else {\n process.stderr.write(`mdtools: ${error instanceof Error ? error.message : String(error)}\\n`);\n process.exitCode = 2;\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import stringWidth from "string-width";
2
- import { range, startsWithMarker } from "../syntax/parse.js";
2
+ import { frontMatterReading, 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) {
@@ -171,7 +171,10 @@ export function underlineEdit(document, node) {
171
171
  if (/^(?::[ \t]|\\\[)/.test(text))
172
172
  return undefined;
173
173
  const newline = /\r\n|\r|\n/.exec(source)?.[0] ?? "\n";
174
- const underline = (node.depth === 1 ? "=" : "-").repeat(Math.max(3, stringWidth(text)));
174
+ // Below a first line of `---` that opens no front matter, an underline of
175
+ // `---` alone would close it (issue #278).
176
+ const shortest = node.depth === 2 && unclosedFrontMatter(source) === "---" ? 4 : 3;
177
+ const underline = (node.depth === 1 ? "=" : "-").repeat(Math.max(shortest, stringWidth(text)));
175
178
  return { start, end: lineEnd(source, start), text: `${text}${newline}${underline}` };
176
179
  }
177
180
  /** The fences of a code or math block, or undefined for an indented code block. */
@@ -274,9 +277,18 @@ const thematicBreak = {
274
277
  const end = start + source.slice(start, last).replace(/[ \t]+$/, "").length;
275
278
  if (source.slice(start, end) === marker)
276
279
  return;
277
- // At the start of the document, `---` is tried as front matter, and when
278
- // that fails the parser reads the document after it differently.
279
- if (start === 0 && (marker === "---" || source.startsWith("---")))
280
+ // At the start of the document, a break written `---` would open front
281
+ // matter if a later line closed it, as a line of `---` alone does, also
282
+ // one that this rule writes. A first-line `---` that the parser reads as a
283
+ // break and site generators as front matter stays (issue #295).
284
+ if (start === 0 &&
285
+ (marker === "---" || (source.startsWith("---") && frontMatterReading(document.tree))))
286
+ return;
287
+ // Below a first line of `---` that opens no front matter, a line of `---`
288
+ // alone would close it (issue #278).
289
+ if (marker === "---" &&
290
+ lineStart(source, start) === start &&
291
+ unclosedFrontMatter(source) === "---")
280
292
  return;
281
293
  // On the line of list items whose markers are the new marker's character,
282
294
  // the items and the break would become one thematic break, as `- ---`,
@@ -1 +1 @@
1
- {"version":3,"file":"blocks.js","sourceRoot":"","sources":["../../src/rules/blocks.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,+EAA+E;AAC/E,SAAS,MAAM,CAAC,UAAmC;IACjD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC;AACrE,CAAC;AACD,oEAAoE;AACpE,MAAM,SAAS,GAAG,YAAY,CAAC;AAC/B,SAAS,SAAS,CAAC,MAAc,EAAE,EAAU;IAC3C,OAAO,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,IAAI,IAAI,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,IAAI;QAAE,EAAE,EAAE,CAAC;IAC1E,OAAO,EAAE,CAAC;AACZ,CAAC;AACD,SAAS,OAAO,CAAC,MAAc,EAAE,EAAU;IACzC,OAAO,EAAE,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,EAAE,CAAC,KAAK,IAAI,IAAI,MAAM,CAAC,EAAE,CAAC,KAAK,IAAI;QAAE,EAAE,EAAE,CAAC;IAC9E,OAAO,EAAE,CAAC;AACZ,CAAC;AAOD,SAAS,aAAa,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MAAM,CAAC,SAAS,CAAC,EAAE,KAAK,KAAK,SAAS,IAAI,MAAM,CAAC,SAAS,CAAE,CAAC,KAAK,GAAG,GAAG,CAAC;YACtF,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,QAAQ,CAAC,IAAI,CAAC;oBACZ,KAAK;oBACL,GAAG;oBACH,OAAO,EAAE,oDAAoD;oBAC7D,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE;iBAC/B,CAAC,CAAC;gBACH,SAAS;YACX,CAAC;YACD,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAE,CAAC;YAC/B,IAAI,CAAC,SAAS,IAAI,GAAG,CAAC,KAAK,KAAK,KAAK,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC;gBACnF,SAAS;YACX,QAAQ,CAAC,IAAI,CAAC;gBACZ,KAAK;gBACL,GAAG;gBACH,OAAO,EAAE,2CAA2C;gBACpD,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE;aACjC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAyB;IAC9C,mBAAmB,EAAE,UAAU;IAC/B,kBAAkB,EAAE,aAAa;IACjC,sBAAsB,EAAE,aAAa;IACrC,sBAAsB,EAAE,aAAa;CACtC,CAAC","sourcesContent":["import type { Code, Heading, Nodes } from \"mdast\";\nimport stringWidth from \"string-width\";\nimport type { Document, Edit, Finding, Rule } from \"../core/types.js\";\nimport { range, startsWithMarker } from \"../syntax/parse.js\";\nimport { walk } from \"../syntax/walk.js\";\n\n/** A JSON Schema for an options object with these properties and no others. */\nfunction schema(properties: Record<string, unknown>) {\n return { type: \"object\", properties, additionalProperties: false };\n}\n/** Any CommonMark line ending, including a lone carriage return. */\nconst lineBreak = /\\r\\n|\\r|\\n/;\nfunction lineStart(source: string, at: number): number {\n while (at > 0 && source[at - 1] !== \"\\n\" && source[at - 1] !== \"\\r\") at--;\n return at;\n}\nfunction lineEnd(source: string, at: number): number {\n while (at < source.length && source[at] !== \"\\n\" && source[at] !== \"\\r\") at++;\n return at;\n}\n/** A physical line: where it starts, where its content ends, and where the next line starts. */\ninterface Line {\n start: number;\n end: number;\n next: number;\n}\nfunction physicalLines(source: string): Line[] {\n const lines: Line[] = [];\n let start = 0;\n for (const match of source.matchAll(/\\r\\n|\\r|\\n/g)) {\n lines.push({ start, end: match.index, next: match.index + match[0].length });\n start = match.index + match[0].length;\n }\n if (start < source.length) lines.push({ start, end: source.length, next: source.length });\n return lines;\n}\n/** Whether the parser gave a node, perhaps one of a plugin's syntax, a source position. */\nfunction located(node: Nodes): boolean {\n return node.position?.start.offset !== undefined && node.position.end.offset !== undefined;\n}\n/** Blocks whose lines hold other blocks, and blank lines between them. */\nconst containers = new Set([\"root\", \"blockquote\", \"list\", \"listItem\", \"footnoteDefinition\"]);\n/** Sort ranges and merge those that overlap or touch. */\nfunction merged(ranges: [number, number][]): [number, number][] {\n const result: [number, number][] = [];\n for (const [start, end] of ranges.filter(([a, b]) => a < b).sort((x, y) => x[0] - y[0])) {\n const last = result.at(-1);\n if (last && start <= last[1]) last[1] = Math.max(last[1], end);\n else result.push([start, end]);\n }\n return result;\n}\n\n/**\n * HTML blocks that end only at an end marker, by what starts them, with the\n * markers that end them, in lowercase, and the offset from which they are\n * searched: CommonMark's kinds 1 to 5. The other kinds end at a blank line.\n * These are CommonMark's markers, not HTML's: a comment's block ends only at\n * `-->`, not at `--!>`.\n */\nconst htmlEnds: [RegExp, string[], number][] = [\n [\n /^<(?:pre|script|style|textarea)(?:[\\t\\n\\r >]|$)/i,\n [\"</pre>\", \"</script>\", \"</style>\", \"</textarea>\"],\n 1,\n ],\n [/^<!--/, [\"-->\"], 2],\n [/^<\\?/, [\"?>\"], 1],\n [/^<!\\[CDATA\\[/, [\"]]>\"], 9],\n [/^<![A-Za-z]/, [\">\"], 2],\n];\n/**\n * Whether a block is an HTML block of a kind that ends only at its end marker,\n * or an Obsidian comment, and lacks that marker. Such a block runs to the end\n * of its container and takes in every line ending and blank line up to there.\n */\nfunction unclosed(node: Nodes): boolean {\n if (node.type === \"obsidianComment\") return node.value.indexOf(\"%%\", 2) < 0;\n if (node.type !== \"html\") return false;\n // The value keeps the block's indentation.\n const value = node.value.replace(/^[ \\t]+/, \"\");\n for (const [opening, ends, from] of htmlEnds) {\n if (!opening.test(value)) continue;\n const rest = value.slice(from).toLowerCase();\n return !ends.some((end) => rest.includes(end));\n }\n return false;\n}\n/**\n * Whether a line added directly below `node`, at its own level, would become\n * part of an HTML block or Obsidian comment that `node` ends with and that has\n * no end marker. The parser lets such an HTML block run on through the blank\n * lines of a list item or footnote, and through a final line ending, but a\n * block quote ends it. An Obsidian comment runs on to the end of the document,\n * whatever contains it.\n */\nexport function takesLines(node: Nodes): boolean {\n let quoted = false;\n while (containers.has(node.type) && \"children\" in node && node.children.length) {\n if (node.type === \"blockquote\") quoted = true;\n node = node.children.at(-1)!;\n }\n return unclosed(node) && (node.type === \"obsidianComment\" || !quoted);\n}\n/**\n * Whether a line ending added at the end of the document would change its\n * last block. Besides the blocks of `takesLines`, the parser counts a last\n * line of blank space in a code or math block that has no closing fence only\n * when a line ending follows it.\n */\nexport function takesFinalLineEnding(document: Document): boolean {\n if (takesLines(document.tree)) return true;\n if (!/(?:^|[\\r\\n])[ \\t]+$/.test(document.source)) return false;\n const last = lastBlock(document.tree);\n if ((last.type !== \"code\" && last.type !== \"math\") || !located(last)) return false;\n const fence = codeFence(document.source, last);\n return fence !== undefined && !fence.close;\n}\n\n/**\n * Whether `style/heading` writes headings of levels 1 and 2 underlined: with\n * `setext`, or with `consistent` when the document's first heading is.\n */\nexport function underlinedHeadings(document: Document, style: unknown): boolean {\n if (style !== \"consistent\") return style === \"setext\";\n let first: Heading | undefined;\n walk(document.tree, \"heading\", (node) => {\n if (!first && located(node)) first = node;\n });\n return first !== undefined && /[\\r\\n]/.test(document.source.slice(...range(first)));\n}\n/**\n * The start of a line that would not begin a paragraph after a blank line: a\n * list item, heading, block quote, thematic break, fence, HTML, math, or\n * Obsidian comment, a link reference definition, or a table row, which `---`\n * below it could make a table.\n */\nconst notParagraph =\n /^(?:[-+*](?:[ \\t]|$)|\\d{1,9}[.)](?:[ \\t]|$)|#{1,6}(?:[ \\t]|$)|>|([-*_])[ \\t]*(?:\\1[ \\t]*){2,}$|`{3,}|~{3,}|<|\\$\\$|%%|\\[[^]*\\]:)|\\|/;\n/**\n * The edit that writes the `#` heading `node`, of level 1 or 2, underlined\n * with `===` or `---`, or undefined where its text could not stand on a line\n * of its own as the same heading. Only headings at the start of a line of the\n * document itself, below a blank line or at the start, are underlined:\n * directly below text, the heading's line would continue a paragraph. On\n * Forgejo and Gitea, a heading with a `{` keeps its form, because their\n * attribute blocks depend on it.\n */\nexport function underlineEdit(document: Document, node: Heading): Edit | undefined {\n const { source } = document;\n const first = node.children[0];\n const last = node.children.at(-1);\n if (node.depth > 2 || !first || !last || !located(first) || !located(last)) return undefined;\n const [start] = range(node);\n if (lineStart(source, start) !== start) return undefined;\n if (start > 0) {\n const above = lineStart(source, start - (source.startsWith(\"\\r\\n\", start - 2) ? 2 : 1));\n if (!/^[ \\t]*$/.test(source.slice(above, lineEnd(source, above)))) return undefined;\n }\n const text = source.slice(range(first)[0], range(last)[1]);\n if (notParagraph.test(text) || text.endsWith(\"\\\\\")) return undefined;\n if ((document.dialect === \"forgejo\" || document.dialect === \"gitea\") && text.includes(\"{\"))\n return undefined;\n // Forgejo and Gitea open a definition or display math with these.\n if (/^(?::[ \\t]|\\\\\\[)/.test(text)) return undefined;\n const newline = /\\r\\n|\\r|\\n/.exec(source)?.[0] ?? \"\\n\";\n const underline = (node.depth === 1 ? \"=\" : \"-\").repeat(Math.max(3, stringWidth(text)));\n return { start, end: lineEnd(source, start), text: `${text}${newline}${underline}` };\n}\n\n/** The fences of a fenced code or math block: the marker runs, as source ranges. */\ninterface Fence {\n marker: \"`\" | \"~\" | \"$\";\n open: [number, number];\n /** Absent when the block runs to the end of its container without a closing fence. */\n close?: [number, number];\n}\n/** The fences of a code or math block, or undefined for an indented code block. */\nfunction codeFence(\n source: string,\n node: Code | Extract<Nodes, { type: \"math\" }>,\n): Fence | undefined {\n const [start, end] = range(node);\n // A fenced block starts at its fence; an indented one at its indentation.\n const opening = /^(?:`{3,}|~{3,}|\\${2,})/.exec(source.slice(start, lineEnd(source, start)));\n if (!opening) return undefined;\n const marker = opening[0][0] as Fence[\"marker\"];\n const fence: Fence = { marker, open: [start, start + opening[0].length] };\n // The block's lines are the opening fence, the content, and the closing\n // fence if there is one. An empty value is no line or one blank line, and a\n // closing fence is never blank.\n const lines = source.slice(start, end).split(lineBreak);\n const last = lines.at(-1)!;\n const closing = new RegExp(\n `(?:${marker === \"$\" ? \"\\\\$\" : marker}){${opening[0].length},}(?=[ \\\\t]*$)`,\n ).exec(last);\n const content = node.value === \"\" ? undefined : node.value.split(lineBreak).length;\n if (closing && lines.length > 1 && (content === undefined || lines.length === content + 2)) {\n const at = end - last.length + closing.index;\n fence.close = [at, at + closing[0].length];\n }\n return fence;\n}\n\nconst codeFenceRule: Rule = {\n description: \"Write code fences with one marker and the length their content needs.\",\n kind: \"style\",\n phase: \"block\",\n schema: schema({ marker: { enum: [\"```\", \"~~~\", \"consistent\"] } }),\n check({ document, options }) {\n const { source } = document;\n const fences: { node: Code; fence: Fence }[] = [];\n walk(document.tree, \"code\", (node) => {\n const fence = located(node) ? codeFence(source, node) : undefined;\n if (fence) fences.push({ node, fence });\n });\n // `consistent` takes the marker of the first fence in the document.\n const marker =\n options.marker === \"~~~\"\n ? \"~\"\n : options.marker === \"consistent\"\n ? (fences[0]?.fence.marker ?? \"`\")\n : \"`\";\n const findings: Finding[] = [];\n for (const { node, fence } of fences) {\n // The info string of a backtick fence cannot contain a backtick.\n if (\n marker === \"`\" &&\n source.slice(fence.open[1], lineEnd(source, fence.open[1])).includes(\"`\")\n )\n continue;\n // A content line of the marker alone, at any indentation, could close a\n // fence that is not longer than it.\n let longest = 0;\n for (const line of node.value.split(lineBreak)) {\n const run = /^[ \\t]*(`+|~+)[ \\t]*$/.exec(line)?.[1];\n if (run?.[0] === marker) longest = Math.max(longest, run.length);\n }\n const text = marker.repeat(Math.max(3, longest + 1));\n for (const [start, end] of fence.close ? [fence.open, fence.close] : [fence.open])\n if (source.slice(start, end) !== text)\n findings.push({\n start,\n end,\n message: `Use ${text} for the code fence.`,\n edit: { start, end, text },\n });\n }\n return findings;\n },\n};\n\n/** The innermost last block of a container, where its text ends. */\nfunction lastBlock(node: Nodes): Nodes {\n while (containers.has(node.type) && \"children\" in node && node.children.length)\n node = node.children.at(-1)!;\n return node;\n}\nconst thematicBreak: Rule = {\n description: \"Write thematic breaks with one marker.\",\n kind: \"style\",\n phase: \"block\",\n schema: schema({ marker: { enum: [\"---\", \"***\", \"___\", \"consistent\"] } }),\n check({ document, options }) {\n const { source } = document;\n let marker = typeof options.marker === \"string\" ? options.marker : \"---\";\n // `consistent` takes the character of the first thematic break in the document.\n if (marker === \"consistent\") {\n let first: string | undefined;\n walk(document.tree, \"thematicBreak\", (node) => {\n if (first === undefined && located(node)) first = source[range(node)[0]];\n });\n marker = (first ?? \"-\").repeat(3);\n }\n const findings: Finding[] = [];\n walk(document.tree, \"thematicBreak\", (node, index, parent) => {\n if (!located(node)) return;\n const [start, last] = range(node);\n // The break's range includes blank space after its markers.\n const end = start + source.slice(start, last).replace(/[ \\t]+$/, \"\").length;\n if (source.slice(start, end) === marker) return;\n // At the start of the document, `---` is tried as front matter, and when\n // that fails the parser reads the document after it differently.\n if (start === 0 && (marker === \"---\" || source.startsWith(\"---\"))) return;\n // On the line of list items whose markers are the new marker's character,\n // the items and the break would become one thematic break, as `- ---`,\n // `1. - ---`, and `* ***` are.\n const items = new RegExp(`[ \\\\t${marker[0] === \"-\" ? \"\\\\-\" : marker[0]}]*$`);\n const prefix = source.slice(lineStart(source, start), start);\n if (items.exec(prefix)![0].includes(marker[0]!)) return;\n if (marker === \"---\") {\n // Directly below a paragraph or a link reference definition, `---`\n // would underline it as a heading.\n const above = index && parent ? lastBlock(parent.children[index - 1]!) : undefined;\n if (\n above &&\n (above.type === \"paragraph\" || above.type === \"definition\") &&\n above.position?.end.line === node.position!.start.line - 1\n )\n return;\n }\n findings.push({\n start,\n end,\n message: `Write the thematic break as ${marker}.`,\n edit: { start, end, text: marker },\n });\n });\n return findings;\n },\n};\n\n/** Where blank lines are content, or their number counts, as source ranges. */\nfunction contentBlocks(document: Document): [number, number][] {\n const blocks: [number, number][] = [];\n walk(document.tree, (node, _, parent) => {\n if (!located(node)) return;\n if (parent && containers.has(parent.type) && !containers.has(node.type))\n blocks.push(range(node));\n // In a block quote, a list, list item, or footnote can extend over the\n // blank lines below its last block. The parser then reads a list as loose,\n // or a list item as tight, by how many there are.\n const last =\n node.type === \"list\" || node.type === \"listItem\" || node.type === \"footnoteDefinition\"\n ? node.children.at(-1)\n : undefined;\n if (last && located(last) && range(last)[1] < range(node)[1])\n blocks.push([range(last)[1], range(node)[1]]);\n });\n return merged(blocks);\n}\nconst blankLines: Rule = {\n description: \"Limit blank lines in a row and remove those around the document.\",\n kind: \"style\",\n phase: \"document\",\n // Fewer than one blank line would join the blocks that it separates.\n schema: schema({ maximum: { type: \"integer\", minimum: 1 } }),\n check({ document, options }) {\n const { source } = document;\n const maximum = typeof options.maximum === \"number\" ? options.maximum : 1;\n const lines = physicalLines(source);\n const text = (line: Line) => source.slice(line.start, line.end);\n const empty = (line: Line) => /^[ \\t]*$/.test(text(line));\n // A line of blank space and block quote markers is blank inside its quotes.\n const blank = (line: Line) => /^[ \\t>]*$/.test(text(line));\n const blocks = contentBlocks(document);\n let block = 0;\n /** Whether a line lies inside a block that began above it; asked in document order. */\n const inside = (line: Line) => {\n while (block < blocks.length && blocks[block]![1] < line.end) block++;\n return block < blocks.length && blocks[block]![0] < line.start;\n };\n const findings: Finding[] = [];\n const remove = (from: number, to: number, message: string) =>\n findings.push({ start: from, end: to, message, edit: { start: from, end: to, text: \"\" } });\n let first = 0;\n while (first < lines.length && empty(lines[first]!)) first++;\n if (first === lines.length) {\n if (source) remove(0, source.length, \"Remove the blank lines.\");\n return findings;\n }\n let last = lines.length;\n // A block without its end, such as an unclosed fence, takes in the blank lines at the end.\n const inBlock = lines.map((line) => blank(line) && inside(line));\n while (empty(lines[last - 1]!) && !inBlock[last - 1]) last--;\n // Below blank lines, `---` or `+++` on the first line would open front matter.\n if (first > 0 && !/^(?:-{3}|\\+{3})/.test(text(lines[first]!)))\n remove(0, lines[first]!.start, \"Remove the blank lines at the start of the document.\");\n // Blank lines in a row with the same block quote markers and indentation\n // are one separation, however many there are.\n const trimmed = (line: Line) => text(line).replace(/[ \\t]+$/, \"\");\n const message =\n maximum === 1\n ? \"Remove the repeated blank line.\"\n : `Remove the blank lines beyond ${maximum} in a row.`;\n for (let index = first; index < last;) {\n const line = lines[index]!;\n let end = index + 1;\n if (blank(line) && !inBlock[index])\n while (\n end < last &&\n blank(lines[end]!) &&\n !inBlock[end] &&\n trimmed(lines[end]!) === trimmed(line)\n )\n end++;\n if (end - index > maximum)\n remove(lines[index + maximum]!.start, lines[end - 1]!.next, message);\n index = end;\n }\n if (last < lines.length)\n remove(\n lines[last]!.start,\n source.length,\n \"Remove the blank lines at the end of the document.\",\n );\n return findings;\n },\n};\n\n/** Nodes whose source between the lines of their text is ordinary prose. */\nconst prose = new Set([\n ...containers,\n \"paragraph\",\n \"heading\",\n \"thematicBreak\",\n \"table\",\n \"tableRow\",\n \"tableCell\",\n \"text\",\n \"emphasis\",\n \"strong\",\n \"delete\",\n]);\nconst trailingSpace: Rule = {\n description: \"Remove spaces and tabs at the end of lines outside code and HTML.\",\n kind: \"style\",\n phase: \"document\",\n schema: schema({ hardBreak: { enum: [\"keep\", \"backslash\"] } }),\n check({ document, options }) {\n const { source } = document;\n if (!/[ \\t](?:\\r|\\n|$)/.test(source)) return [];\n const backslash = options.hardBreak === \"backslash\";\n const forge = document.dialect === \"forgejo\" || document.dialect === \"gitea\";\n /** Source in which blank space at the end of a line is content. */\n const kept: [number, number][] = [];\n /**\n * Hard line breaks, with the paragraph or heading each one is in, and\n * whether that block starts like an alert's or callout's marker, `[!`.\n */\n const breaks: { start: number; end: number; block: [number, number]; marker: boolean }[] = [];\n const links: [number, number][] = [];\n let block: [number, number] = [0, 0];\n let marker = false;\n walk(document.tree, (node, _, parent) => {\n if (!located(node)) {\n // A plugin's node without a position keeps whatever its parent spans.\n if (parent && located(parent)) kept.push(range(parent));\n return;\n }\n const [start, end] = range(node);\n if (node.type === \"paragraph\" || node.type === \"heading\") {\n block = [start, end];\n const written = source.slice(start, end);\n marker =\n node.type === \"paragraph\"\n ? startsWithMarker(written, node, /^\\[!/)\n : written.startsWith(\"[!\");\n }\n if (node.type === \"link\") links.push([start, end]);\n if (node.type === \"break\") breaks.push({ start, end, block, marker });\n else if (node.type === \"link\" || node.type === \"linkReference\") {\n // The link text is prose; a title or label that spans lines is not.\n let at = start;\n for (const child of node.children) {\n if (!located(child)) continue;\n kept.push([at, range(child)[0]]);\n at = range(child)[1];\n }\n kept.push([at, end]);\n } else if (node.type === \"code\") {\n const fence = codeFence(source, node);\n // A fence line ends in syntax, unless an info string's text runs to its end.\n const from = fence && !node.meta ? lineEnd(source, start) : start;\n kept.push([from, fence?.close ? lineStart(source, fence.close[0]) : end]);\n } else if (!prose.has(node.type)) kept.push([start, end]);\n });\n const ranges = merged(kept);\n let next = 0;\n let following = 0;\n let link = 0;\n /**\n * Whether a backslash in place of the blank space of a hard line break,\n * which starts at `start`, would mean the same. One after another\n * backslash would be escaped. A literal autolink such as `www.example.com`\n * runs on to the next blank space, so it would take the backslash in. A\n * paragraph that starts like `[label]:` could become a link reference\n * definition with the backslash as its destination, and the title line of\n * an alert or callout, also one written as `\\[!NOTE]`, would end with it.\n * On Forgejo and Gitea, a backslash inside `\\(...\\)` math would be part of\n * the formula.\n */\n const backslashSafe = (start: number, paragraph: [number, number], marker: boolean) => {\n if (source[start - 1] === \"\\\\\") return false;\n let word = start;\n while (word > paragraph[0] && !/[ \\t\\r\\n]/.test(source[word - 1]!)) word--;\n while (link < links.length && links[link]![1] <= word) link++;\n if (link < links.length && links[link]![0] < start) return false;\n const before = source.slice(paragraph[0], start);\n if (/^\\[[^]*\\]:/.test(before) || (marker && !/[\\r\\n]/.test(before))) return false;\n return !(forge && source.slice(...paragraph).includes(\"\\\\(\"));\n };\n const findings: Finding[] = [];\n for (const line of physicalLines(source)) {\n const space = /[ \\t]+$/.exec(source.slice(line.start, line.end));\n if (!space) continue;\n const start = line.start + space.index;\n const end = line.end;\n while (next < ranges.length && ranges[next]![1] <= start) next++;\n if (next < ranges.length && ranges[next]![0] < end) continue;\n // Breaks are in document order, as lines are.\n while (following < breaks.length && breaks[following]!.end <= start) following++;\n const hard = breaks[following]?.start !== undefined && breaks[following]!.start < end;\n if (!hard) {\n findings.push({\n start,\n end,\n message: \"Remove the spaces and tabs at the end of the line.\",\n edit: { start, end, text: \"\" },\n });\n continue;\n }\n const brk = breaks[following]!;\n if (!backslash || brk.start !== start || !backslashSafe(start, brk.block, brk.marker))\n continue;\n findings.push({\n start,\n end,\n message: \"Write the hard line break as a backslash.\",\n edit: { start, end, text: \"\\\\\" },\n });\n }\n return findings;\n },\n};\n\nexport const blockRules: Record<string, Rule> = {\n \"style/blank-lines\": blankLines,\n \"style/code-fence\": codeFenceRule,\n \"style/thematic-break\": thematicBreak,\n \"style/trailing-space\": trailingSpace,\n};\n"]}
1
+ {"version":3,"file":"blocks.js","sourceRoot":"","sources":["../../src/rules/blocks.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,cAAc,CAAC;AAEvC,OAAO,EACL,kBAAkB,EAClB,KAAK,EACL,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM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KAAK,GAAG,GAAG,CAAC;YACtF,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,QAAQ,CAAC,IAAI,CAAC;oBACZ,KAAK;oBACL,GAAG;oBACH,OAAO,EAAE,oDAAoD;oBAC7D,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE;iBAC/B,CAAC,CAAC;gBACH,SAAS;YACX,CAAC;YACD,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAE,CAAC;YAC/B,IAAI,CAAC,SAAS,IAAI,GAAG,CAAC,KAAK,KAAK,KAAK,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC;gBACnF,SAAS;YACX,QAAQ,CAAC,IAAI,CAAC;gBACZ,KAAK;gBACL,GAAG;gBACH,OAAO,EAAE,2CAA2C;gBACpD,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE;aACjC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAyB;IAC9C,mBAAmB,EAAE,UAAU;IAC/B,kBAAkB,EAAE,aAAa;IACjC,sBAAsB,EAAE,aAAa;IACrC,sBAAsB,EAAE,aAAa;CACtC,CAAC","sourcesContent":["import type { Code, Heading, Nodes } from \"mdast\";\nimport stringWidth from \"string-width\";\nimport type { Document, Edit, Finding, Rule } from \"../core/types.js\";\nimport {\n frontMatterReading,\n range,\n startsWithMarker,\n unclosedFrontMatter,\n} from \"../syntax/parse.js\";\nimport { walk } from \"../syntax/walk.js\";\n\n/** A JSON Schema for an options object with these properties and no others. */\nfunction schema(properties: Record<string, unknown>) {\n return { type: \"object\", properties, additionalProperties: false };\n}\n/** Any CommonMark line ending, including a lone carriage return. */\nconst lineBreak = /\\r\\n|\\r|\\n/;\nfunction lineStart(source: string, at: number): number {\n while (at > 0 && source[at - 1] !== \"\\n\" && source[at - 1] !== \"\\r\") at--;\n return at;\n}\nfunction lineEnd(source: string, at: number): number {\n while (at < source.length && source[at] !== \"\\n\" && source[at] !== \"\\r\") at++;\n return at;\n}\n/** A physical line: where it starts, where its content ends, and where the next line starts. */\ninterface Line {\n start: number;\n end: number;\n next: number;\n}\nfunction physicalLines(source: string): Line[] {\n const lines: Line[] = [];\n let start = 0;\n for (const match of source.matchAll(/\\r\\n|\\r|\\n/g)) {\n lines.push({ start, end: match.index, next: match.index + match[0].length });\n start = match.index + match[0].length;\n }\n if (start < source.length) lines.push({ start, end: source.length, next: source.length });\n return lines;\n}\n/** Whether the parser gave a node, perhaps one of a plugin's syntax, a source position. */\nfunction located(node: Nodes): boolean {\n return node.position?.start.offset !== undefined && node.position.end.offset !== undefined;\n}\n/** Blocks whose lines hold other blocks, and blank lines between them. */\nconst containers = new Set([\"root\", \"blockquote\", \"list\", \"listItem\", \"footnoteDefinition\"]);\n/** Sort ranges and merge those that overlap or touch. */\nfunction merged(ranges: [number, number][]): [number, number][] {\n const result: [number, number][] = [];\n for (const [start, end] of ranges.filter(([a, b]) => a < b).sort((x, y) => x[0] - y[0])) {\n const last = result.at(-1);\n if (last && start <= last[1]) last[1] = Math.max(last[1], end);\n else result.push([start, end]);\n }\n return result;\n}\n\n/**\n * HTML blocks that end only at an end marker, by what starts them, with the\n * markers that end them, in lowercase, and the offset from which they are\n * searched: CommonMark's kinds 1 to 5. The other kinds end at a blank line.\n * These are CommonMark's markers, not HTML's: a comment's block ends only at\n * `-->`, not at `--!>`.\n */\nconst htmlEnds: [RegExp, string[], number][] = [\n [\n /^<(?:pre|script|style|textarea)(?:[\\t\\n\\r >]|$)/i,\n [\"</pre>\", \"</script>\", \"</style>\", \"</textarea>\"],\n 1,\n ],\n [/^<!--/, [\"-->\"], 2],\n [/^<\\?/, [\"?>\"], 1],\n [/^<!\\[CDATA\\[/, [\"]]>\"], 9],\n [/^<![A-Za-z]/, [\">\"], 2],\n];\n/**\n * Whether a block is an HTML block of a kind that ends only at its end marker,\n * or an Obsidian comment, and lacks that marker. Such a block runs to the end\n * of its container and takes in every line ending and blank line up to there.\n */\nfunction unclosed(node: Nodes): boolean {\n if (node.type === \"obsidianComment\") return node.value.indexOf(\"%%\", 2) < 0;\n if (node.type !== \"html\") return false;\n // The value keeps the block's indentation.\n const value = node.value.replace(/^[ \\t]+/, \"\");\n for (const [opening, ends, from] of htmlEnds) {\n if (!opening.test(value)) continue;\n const rest = value.slice(from).toLowerCase();\n return !ends.some((end) => rest.includes(end));\n }\n return false;\n}\n/**\n * Whether a line added directly below `node`, at its own level, would become\n * part of an HTML block or Obsidian comment that `node` ends with and that has\n * no end marker. The parser lets such an HTML block run on through the blank\n * lines of a list item or footnote, and through a final line ending, but a\n * block quote ends it. An Obsidian comment runs on to the end of the document,\n * whatever contains it.\n */\nexport function takesLines(node: Nodes): boolean {\n let quoted = false;\n while (containers.has(node.type) && \"children\" in node && node.children.length) {\n if (node.type === \"blockquote\") quoted = true;\n node = node.children.at(-1)!;\n }\n return unclosed(node) && (node.type === \"obsidianComment\" || !quoted);\n}\n/**\n * Whether a line ending added at the end of the document would change its\n * last block. Besides the blocks of `takesLines`, the parser counts a last\n * line of blank space in a code or math block that has no closing fence only\n * when a line ending follows it.\n */\nexport function takesFinalLineEnding(document: Document): boolean {\n if (takesLines(document.tree)) return true;\n if (!/(?:^|[\\r\\n])[ \\t]+$/.test(document.source)) return false;\n const last = lastBlock(document.tree);\n if ((last.type !== \"code\" && last.type !== \"math\") || !located(last)) return false;\n const fence = codeFence(document.source, last);\n return fence !== undefined && !fence.close;\n}\n\n/**\n * Whether `style/heading` writes headings of levels 1 and 2 underlined: with\n * `setext`, or with `consistent` when the document's first heading is.\n */\nexport function underlinedHeadings(document: Document, style: unknown): boolean {\n if (style !== \"consistent\") return style === \"setext\";\n let first: Heading | undefined;\n walk(document.tree, \"heading\", (node) => {\n if (!first && located(node)) first = node;\n });\n return first !== undefined && /[\\r\\n]/.test(document.source.slice(...range(first)));\n}\n/**\n * The start of a line that would not begin a paragraph after a blank line: a\n * list item, heading, block quote, thematic break, fence, HTML, math, or\n * Obsidian comment, a link reference definition, or a table row, which `---`\n * below it could make a table.\n */\nconst notParagraph =\n /^(?:[-+*](?:[ \\t]|$)|\\d{1,9}[.)](?:[ \\t]|$)|#{1,6}(?:[ \\t]|$)|>|([-*_])[ \\t]*(?:\\1[ \\t]*){2,}$|`{3,}|~{3,}|<|\\$\\$|%%|\\[[^]*\\]:)|\\|/;\n/**\n * The edit that writes the `#` heading `node`, of level 1 or 2, underlined\n * with `===` or `---`, or undefined where its text could not stand on a line\n * of its own as the same heading. Only headings at the start of a line of the\n * document itself, below a blank line or at the start, are underlined:\n * directly below text, the heading's line would continue a paragraph. On\n * Forgejo and Gitea, a heading with a `{` keeps its form, because their\n * attribute blocks depend on it.\n */\nexport function underlineEdit(document: Document, node: Heading): Edit | undefined {\n const { source } = document;\n const first = node.children[0];\n const last = node.children.at(-1);\n if (node.depth > 2 || !first || !last || !located(first) || !located(last)) return undefined;\n const [start] = range(node);\n if (lineStart(source, start) !== start) return undefined;\n if (start > 0) {\n const above = lineStart(source, start - (source.startsWith(\"\\r\\n\", start - 2) ? 2 : 1));\n if (!/^[ \\t]*$/.test(source.slice(above, lineEnd(source, above)))) return undefined;\n }\n const text = source.slice(range(first)[0], range(last)[1]);\n if (notParagraph.test(text) || text.endsWith(\"\\\\\")) return undefined;\n if ((document.dialect === \"forgejo\" || document.dialect === \"gitea\") && text.includes(\"{\"))\n return undefined;\n // Forgejo and Gitea open a definition or display math with these.\n if (/^(?::[ \\t]|\\\\\\[)/.test(text)) return undefined;\n const newline = /\\r\\n|\\r|\\n/.exec(source)?.[0] ?? \"\\n\";\n // Below a first line of `---` that opens no front matter, an underline of\n // `---` alone would close it (issue #278).\n const shortest = node.depth === 2 && unclosedFrontMatter(source) === \"---\" ? 4 : 3;\n const underline = (node.depth === 1 ? \"=\" : \"-\").repeat(Math.max(shortest, stringWidth(text)));\n return { start, end: lineEnd(source, start), text: `${text}${newline}${underline}` };\n}\n\n/** The fences of a fenced code or math block: the marker runs, as source ranges. */\ninterface Fence {\n marker: \"`\" | \"~\" | \"$\";\n open: [number, number];\n /** Absent when the block runs to the end of its container without a closing fence. */\n close?: [number, number];\n}\n/** The fences of a code or math block, or undefined for an indented code block. */\nfunction codeFence(\n source: string,\n node: Code | Extract<Nodes, { type: \"math\" }>,\n): Fence | undefined {\n const [start, end] = range(node);\n // A fenced block starts at its fence; an indented one at its indentation.\n const opening = /^(?:`{3,}|~{3,}|\\${2,})/.exec(source.slice(start, lineEnd(source, start)));\n if (!opening) return undefined;\n const marker = opening[0][0] as Fence[\"marker\"];\n const fence: Fence = { marker, open: [start, start + opening[0].length] };\n // The block's lines are the opening fence, the content, and the closing\n // fence if there is one. An empty value is no line or one blank line, and a\n // closing fence is never blank.\n const lines = source.slice(start, end).split(lineBreak);\n const last = lines.at(-1)!;\n const closing = new RegExp(\n `(?:${marker === \"$\" ? \"\\\\$\" : marker}){${opening[0].length},}(?=[ \\\\t]*$)`,\n ).exec(last);\n const content = node.value === \"\" ? undefined : node.value.split(lineBreak).length;\n if (closing && lines.length > 1 && (content === undefined || lines.length === content + 2)) {\n const at = end - last.length + closing.index;\n fence.close = [at, at + closing[0].length];\n }\n return fence;\n}\n\nconst codeFenceRule: Rule = {\n description: \"Write code fences with one marker and the length their content needs.\",\n kind: \"style\",\n phase: \"block\",\n schema: schema({ marker: { enum: [\"```\", \"~~~\", \"consistent\"] } }),\n check({ document, options }) {\n const { source } = document;\n const fences: { node: Code; fence: Fence }[] = [];\n walk(document.tree, \"code\", (node) => {\n const fence = located(node) ? codeFence(source, node) : undefined;\n if (fence) fences.push({ node, fence });\n });\n // `consistent` takes the marker of the first fence in the document.\n const marker =\n options.marker === \"~~~\"\n ? \"~\"\n : options.marker === \"consistent\"\n ? (fences[0]?.fence.marker ?? \"`\")\n : \"`\";\n const findings: Finding[] = [];\n for (const { node, fence } of fences) {\n // The info string of a backtick fence cannot contain a backtick.\n if (\n marker === \"`\" &&\n source.slice(fence.open[1], lineEnd(source, fence.open[1])).includes(\"`\")\n )\n continue;\n // A content line of the marker alone, at any indentation, could close a\n // fence that is not longer than it.\n let longest = 0;\n for (const line of node.value.split(lineBreak)) {\n const run = /^[ \\t]*(`+|~+)[ \\t]*$/.exec(line)?.[1];\n if (run?.[0] === marker) longest = Math.max(longest, run.length);\n }\n const text = marker.repeat(Math.max(3, longest + 1));\n for (const [start, end] of fence.close ? [fence.open, fence.close] : [fence.open])\n if (source.slice(start, end) !== text)\n findings.push({\n start,\n end,\n message: `Use ${text} for the code fence.`,\n edit: { start, end, text },\n });\n }\n return findings;\n },\n};\n\n/** The innermost last block of a container, where its text ends. */\nfunction lastBlock(node: Nodes): Nodes {\n while (containers.has(node.type) && \"children\" in node && node.children.length)\n node = node.children.at(-1)!;\n return node;\n}\nconst thematicBreak: Rule = {\n description: \"Write thematic breaks with one marker.\",\n kind: \"style\",\n phase: \"block\",\n schema: schema({ marker: { enum: [\"---\", \"***\", \"___\", \"consistent\"] } }),\n check({ document, options }) {\n const { source } = document;\n let marker = typeof options.marker === \"string\" ? options.marker : \"---\";\n // `consistent` takes the character of the first thematic break in the document.\n if (marker === \"consistent\") {\n let first: string | undefined;\n walk(document.tree, \"thematicBreak\", (node) => {\n if (first === undefined && located(node)) first = source[range(node)[0]];\n });\n marker = (first ?? \"-\").repeat(3);\n }\n const findings: Finding[] = [];\n walk(document.tree, \"thematicBreak\", (node, index, parent) => {\n if (!located(node)) return;\n const [start, last] = range(node);\n // The break's range includes blank space after its markers.\n const end = start + source.slice(start, last).replace(/[ \\t]+$/, \"\").length;\n if (source.slice(start, end) === marker) return;\n // At the start of the document, a break written `---` would open front\n // matter if a later line closed it, as a line of `---` alone does, also\n // one that this rule writes. A first-line `---` that the parser reads as a\n // break and site generators as front matter stays (issue #295).\n if (\n start === 0 &&\n (marker === \"---\" || (source.startsWith(\"---\") && frontMatterReading(document.tree)))\n )\n return;\n // Below a first line of `---` that opens no front matter, a line of `---`\n // alone would close it (issue #278).\n if (\n marker === \"---\" &&\n lineStart(source, start) === start &&\n unclosedFrontMatter(source) === \"---\"\n )\n return;\n // On the line of list items whose markers are the new marker's character,\n // the items and the break would become one thematic break, as `- ---`,\n // `1. - ---`, and `* ***` are.\n const items = new RegExp(`[ \\\\t${marker[0] === \"-\" ? \"\\\\-\" : marker[0]}]*$`);\n const prefix = source.slice(lineStart(source, start), start);\n if (items.exec(prefix)![0].includes(marker[0]!)) return;\n if (marker === \"---\") {\n // Directly below a paragraph or a link reference definition, `---`\n // would underline it as a heading.\n const above = index && parent ? lastBlock(parent.children[index - 1]!) : undefined;\n if (\n above &&\n (above.type === \"paragraph\" || above.type === \"definition\") &&\n above.position?.end.line === node.position!.start.line - 1\n )\n return;\n }\n findings.push({\n start,\n end,\n message: `Write the thematic break as ${marker}.`,\n edit: { start, end, text: marker },\n });\n });\n return findings;\n },\n};\n\n/** Where blank lines are content, or their number counts, as source ranges. */\nfunction contentBlocks(document: Document): [number, number][] {\n const blocks: [number, number][] = [];\n walk(document.tree, (node, _, parent) => {\n if (!located(node)) return;\n if (parent && containers.has(parent.type) && !containers.has(node.type))\n blocks.push(range(node));\n // In a block quote, a list, list item, or footnote can extend over the\n // blank lines below its last block. The parser then reads a list as loose,\n // or a list item as tight, by how many there are.\n const last =\n node.type === \"list\" || node.type === \"listItem\" || node.type === \"footnoteDefinition\"\n ? node.children.at(-1)\n : undefined;\n if (last && located(last) && range(last)[1] < range(node)[1])\n blocks.push([range(last)[1], range(node)[1]]);\n });\n return merged(blocks);\n}\nconst blankLines: Rule = {\n description: \"Limit blank lines in a row and remove those around the document.\",\n kind: \"style\",\n phase: \"document\",\n // Fewer than one blank line would join the blocks that it separates.\n schema: schema({ maximum: { type: \"integer\", minimum: 1 } }),\n check({ document, options }) {\n const { source } = document;\n const maximum = typeof options.maximum === \"number\" ? options.maximum : 1;\n const lines = physicalLines(source);\n const text = (line: Line) => source.slice(line.start, line.end);\n const empty = (line: Line) => /^[ \\t]*$/.test(text(line));\n // A line of blank space and block quote markers is blank inside its quotes.\n const blank = (line: Line) => /^[ \\t>]*$/.test(text(line));\n const blocks = contentBlocks(document);\n let block = 0;\n /** Whether a line lies inside a block that began above it; asked in document order. */\n const inside = (line: Line) => {\n while (block < blocks.length && blocks[block]![1] < line.end) block++;\n return block < blocks.length && blocks[block]![0] < line.start;\n };\n const findings: Finding[] = [];\n const remove = (from: number, to: number, message: string) =>\n findings.push({ start: from, end: to, message, edit: { start: from, end: to, text: \"\" } });\n let first = 0;\n while (first < lines.length && empty(lines[first]!)) first++;\n if (first === lines.length) {\n if (source) remove(0, source.length, \"Remove the blank lines.\");\n return findings;\n }\n let last = lines.length;\n // A block without its end, such as an unclosed fence, takes in the blank lines at the end.\n const inBlock = lines.map((line) => blank(line) && inside(line));\n while (empty(lines[last - 1]!) && !inBlock[last - 1]) last--;\n // Below blank lines, `---` or `+++` on the first line would open front matter.\n if (first > 0 && !/^(?:-{3}|\\+{3})/.test(text(lines[first]!)))\n remove(0, lines[first]!.start, \"Remove the blank lines at the start of the document.\");\n // Blank lines in a row with the same block quote markers and indentation\n // are one separation, however many there are.\n const trimmed = (line: Line) => text(line).replace(/[ \\t]+$/, \"\");\n const message =\n maximum === 1\n ? \"Remove the repeated blank line.\"\n : `Remove the blank lines beyond ${maximum} in a row.`;\n for (let index = first; index < last;) {\n const line = lines[index]!;\n let end = index + 1;\n if (blank(line) && !inBlock[index])\n while (\n end < last &&\n blank(lines[end]!) &&\n !inBlock[end] &&\n trimmed(lines[end]!) === trimmed(line)\n )\n end++;\n if (end - index > maximum)\n remove(lines[index + maximum]!.start, lines[end - 1]!.next, message);\n index = end;\n }\n if (last < lines.length)\n remove(\n lines[last]!.start,\n source.length,\n \"Remove the blank lines at the end of the document.\",\n );\n return findings;\n },\n};\n\n/** Nodes whose source between the lines of their text is ordinary prose. */\nconst prose = new Set([\n ...containers,\n \"paragraph\",\n \"heading\",\n \"thematicBreak\",\n \"table\",\n \"tableRow\",\n \"tableCell\",\n \"text\",\n \"emphasis\",\n \"strong\",\n \"delete\",\n]);\nconst trailingSpace: Rule = {\n description: \"Remove spaces and tabs at the end of lines outside code and HTML.\",\n kind: \"style\",\n phase: \"document\",\n schema: schema({ hardBreak: { enum: [\"keep\", \"backslash\"] } }),\n check({ document, options }) {\n const { source } = document;\n if (!/[ \\t](?:\\r|\\n|$)/.test(source)) return [];\n const backslash = options.hardBreak === \"backslash\";\n const forge = document.dialect === \"forgejo\" || document.dialect === \"gitea\";\n /** Source in which blank space at the end of a line is content. */\n const kept: [number, number][] = [];\n /**\n * Hard line breaks, with the paragraph or heading each one is in, and\n * whether that block starts like an alert's or callout's marker, `[!`.\n */\n const breaks: { start: number; end: number; block: [number, number]; marker: boolean }[] = [];\n const links: [number, number][] = [];\n let block: [number, number] = [0, 0];\n let marker = false;\n walk(document.tree, (node, _, parent) => {\n if (!located(node)) {\n // A plugin's node without a position keeps whatever its parent spans.\n if (parent && located(parent)) kept.push(range(parent));\n return;\n }\n const [start, end] = range(node);\n if (node.type === \"paragraph\" || node.type === \"heading\") {\n block = [start, end];\n const written = source.slice(start, end);\n marker =\n node.type === \"paragraph\"\n ? startsWithMarker(written, node, /^\\[!/)\n : written.startsWith(\"[!\");\n }\n if (node.type === \"link\") links.push([start, end]);\n if (node.type === \"break\") breaks.push({ start, end, block, marker });\n else if (node.type === \"link\" || node.type === \"linkReference\") {\n // The link text is prose; a title or label that spans lines is not.\n let at = start;\n for (const child of node.children) {\n if (!located(child)) continue;\n kept.push([at, range(child)[0]]);\n at = range(child)[1];\n }\n kept.push([at, end]);\n } else if (node.type === \"code\") {\n const fence = codeFence(source, node);\n // A fence line ends in syntax, unless an info string's text runs to its end.\n const from = fence && !node.meta ? lineEnd(source, start) : start;\n kept.push([from, fence?.close ? lineStart(source, fence.close[0]) : end]);\n } else if (!prose.has(node.type)) kept.push([start, end]);\n });\n const ranges = merged(kept);\n let next = 0;\n let following = 0;\n let link = 0;\n /**\n * Whether a backslash in place of the blank space of a hard line break,\n * which starts at `start`, would mean the same. One after another\n * backslash would be escaped. A literal autolink such as `www.example.com`\n * runs on to the next blank space, so it would take the backslash in. A\n * paragraph that starts like `[label]:` could become a link reference\n * definition with the backslash as its destination, and the title line of\n * an alert or callout, also one written as `\\[!NOTE]`, would end with it.\n * On Forgejo and Gitea, a backslash inside `\\(...\\)` math would be part of\n * the formula.\n */\n const backslashSafe = (start: number, paragraph: [number, number], marker: boolean) => {\n if (source[start - 1] === \"\\\\\") return false;\n let word = start;\n while (word > paragraph[0] && !/[ \\t\\r\\n]/.test(source[word - 1]!)) word--;\n while (link < links.length && links[link]![1] <= word) link++;\n if (link < links.length && links[link]![0] < start) return false;\n const before = source.slice(paragraph[0], start);\n if (/^\\[[^]*\\]:/.test(before) || (marker && !/[\\r\\n]/.test(before))) return false;\n return !(forge && source.slice(...paragraph).includes(\"\\\\(\"));\n };\n const findings: Finding[] = [];\n for (const line of physicalLines(source)) {\n const space = /[ \\t]+$/.exec(source.slice(line.start, line.end));\n if (!space) continue;\n const start = line.start + space.index;\n const end = line.end;\n while (next < ranges.length && ranges[next]![1] <= start) next++;\n if (next < ranges.length && ranges[next]![0] < end) continue;\n // Breaks are in document order, as lines are.\n while (following < breaks.length && breaks[following]!.end <= start) following++;\n const hard = breaks[following]?.start !== undefined && breaks[following]!.start < end;\n if (!hard) {\n findings.push({\n start,\n end,\n message: \"Remove the spaces and tabs at the end of the line.\",\n edit: { start, end, text: \"\" },\n });\n continue;\n }\n const brk = breaks[following]!;\n if (!backslash || brk.start !== start || !backslashSafe(start, brk.block, brk.marker))\n continue;\n findings.push({\n start,\n end,\n message: \"Write the hard line break as a backslash.\",\n edit: { start, end, text: \"\\\\\" },\n });\n }\n return findings;\n },\n};\n\nexport const blockRules: Record<string, Rule> = {\n \"style/blank-lines\": blankLines,\n \"style/code-fence\": codeFenceRule,\n \"style/thematic-break\": thematicBreak,\n \"style/trailing-space\": trailingSpace,\n};\n"]}