@mark1russell7/ste-lint 0.0.0-bootstrap.0 → 0.1.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.
- package/README.md +224 -1
- package/dist/.tsbuildinfo +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +9 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +103 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +251 -0
- package/dist/config.js.map +1 -0
- package/dist/dictionary.d.ts +74 -0
- package/dist/dictionary.d.ts.map +1 -0
- package/dist/dictionary.js +169 -0
- package/dist/dictionary.js.map +1 -0
- package/dist/files.d.ts +35 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +181 -0
- package/dist/files.js.map +1 -0
- package/dist/format.d.ts +21 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +61 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/lexicon.d.ts +33 -0
- package/dist/lexicon.d.ts.map +1 -0
- package/dist/lexicon.js +71 -0
- package/dist/lexicon.js.map +1 -0
- package/dist/lint.d.ts +28 -0
- package/dist/lint.d.ts.map +1 -0
- package/dist/lint.js +132 -0
- package/dist/lint.js.map +1 -0
- package/dist/rules/about-quantity.d.ts +3 -0
- package/dist/rules/about-quantity.d.ts.map +1 -0
- package/dist/rules/about-quantity.js +34 -0
- package/dist/rules/about-quantity.js.map +1 -0
- package/dist/rules/index.d.ts +8 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +35 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/ing-verb.d.ts +9 -0
- package/dist/rules/ing-verb.d.ts.map +1 -0
- package/dist/rules/ing-verb.js +60 -0
- package/dist/rules/ing-verb.js.map +1 -0
- package/dist/rules/latin-abbreviation.d.ts +3 -0
- package/dist/rules/latin-abbreviation.d.ts.map +1 -0
- package/dist/rules/latin-abbreviation.js +48 -0
- package/dist/rules/latin-abbreviation.js.map +1 -0
- package/dist/rules/missing-subject.d.ts +16 -0
- package/dist/rules/missing-subject.d.ts.map +1 -0
- package/dist/rules/missing-subject.js +138 -0
- package/dist/rules/missing-subject.js.map +1 -0
- package/dist/rules/modal-verb.d.ts +3 -0
- package/dist/rules/modal-verb.d.ts.map +1 -0
- package/dist/rules/modal-verb.js +72 -0
- package/dist/rules/modal-verb.js.map +1 -0
- package/dist/rules/noun-cluster.d.ts +17 -0
- package/dist/rules/noun-cluster.d.ts.map +1 -0
- package/dist/rules/noun-cluster.js +83 -0
- package/dist/rules/noun-cluster.js.map +1 -0
- package/dist/rules/paragraph-length.d.ts +3 -0
- package/dist/rules/paragraph-length.d.ts.map +1 -0
- package/dist/rules/paragraph-length.js +19 -0
- package/dist/rules/paragraph-length.js.map +1 -0
- package/dist/rules/passive-instruction.d.ts +15 -0
- package/dist/rules/passive-instruction.d.ts.map +1 -0
- package/dist/rules/passive-instruction.js +38 -0
- package/dist/rules/passive-instruction.js.map +1 -0
- package/dist/rules/pronouns.d.ts +4 -0
- package/dist/rules/pronouns.d.ts.map +1 -0
- package/dist/rules/pronouns.js +57 -0
- package/dist/rules/pronouns.js.map +1 -0
- package/dist/rules/rule.d.ts +46 -0
- package/dist/rules/rule.d.ts.map +1 -0
- package/dist/rules/rule.js +31 -0
- package/dist/rules/rule.js.map +1 -0
- package/dist/rules/semicolon.d.ts +3 -0
- package/dist/rules/semicolon.d.ts.map +1 -0
- package/dist/rules/semicolon.js +20 -0
- package/dist/rules/semicolon.js.map +1 -0
- package/dist/rules/sentence-length.d.ts +3 -0
- package/dist/rules/sentence-length.d.ts.map +1 -0
- package/dist/rules/sentence-length.js +31 -0
- package/dist/rules/sentence-length.js.map +1 -0
- package/dist/rules/unknown-word.d.ts +9 -0
- package/dist/rules/unknown-word.d.ts.map +1 -0
- package/dist/rules/unknown-word.js +49 -0
- package/dist/rules/unknown-word.js.map +1 -0
- package/dist/rules/word-list-matcher.d.ts +25 -0
- package/dist/rules/word-list-matcher.d.ts.map +1 -0
- package/dist/rules/word-list-matcher.js +60 -0
- package/dist/rules/word-list-matcher.js.map +1 -0
- package/dist/rules/word-list.d.ts +3 -0
- package/dist/rules/word-list.d.ts.map +1 -0
- package/dist/rules/word-list.js +26 -0
- package/dist/rules/word-list.js.map +1 -0
- package/dist/run-cli.d.ts +27 -0
- package/dist/run-cli.d.ts.map +1 -0
- package/dist/run-cli.js +176 -0
- package/dist/run-cli.js.map +1 -0
- package/dist/source/blocks.d.ts +55 -0
- package/dist/source/blocks.d.ts.map +1 -0
- package/dist/source/blocks.js +464 -0
- package/dist/source/blocks.js.map +1 -0
- package/dist/source/inline.d.ts +42 -0
- package/dist/source/inline.d.ts.map +1 -0
- package/dist/source/inline.js +396 -0
- package/dist/source/inline.js.map +1 -0
- package/dist/source/jsx.d.ts +18 -0
- package/dist/source/jsx.d.ts.map +1 -0
- package/dist/source/jsx.js +137 -0
- package/dist/source/jsx.js.map +1 -0
- package/dist/source/lines.d.ts +34 -0
- package/dist/source/lines.d.ts.map +1 -0
- package/dist/source/lines.js +83 -0
- package/dist/source/lines.js.map +1 -0
- package/dist/source/markdown.d.ts +23 -0
- package/dist/source/markdown.d.ts.map +1 -0
- package/dist/source/markdown.js +42 -0
- package/dist/source/markdown.js.map +1 -0
- package/dist/source/suppressions.d.ts +38 -0
- package/dist/source/suppressions.d.ts.map +1 -0
- package/dist/source/suppressions.js +69 -0
- package/dist/source/suppressions.js.map +1 -0
- package/dist/source/tsdoc.d.ts +40 -0
- package/dist/source/tsdoc.d.ts.map +1 -0
- package/dist/source/tsdoc.js +176 -0
- package/dist/source/tsdoc.js.map +1 -0
- package/dist/text/grammar.d.ts +91 -0
- package/dist/text/grammar.d.ts.map +1 -0
- package/dist/text/grammar.js +289 -0
- package/dist/text/grammar.js.map +1 -0
- package/dist/text/phrases.d.ts +30 -0
- package/dist/text/phrases.d.ts.map +1 -0
- package/dist/text/phrases.js +65 -0
- package/dist/text/phrases.js.map +1 -0
- package/dist/text/sentences.d.ts +45 -0
- package/dist/text/sentences.d.ts.map +1 -0
- package/dist/text/sentences.js +141 -0
- package/dist/text/sentences.js.map +1 -0
- package/dist/text/tokens.d.ts +35 -0
- package/dist/text/tokens.d.ts.map +1 -0
- package/dist/text/tokens.js +113 -0
- package/dist/text/tokens.js.map +1 -0
- package/dist/text/words.d.ts +58 -0
- package/dist/text/words.d.ts.map +1 -0
- package/dist/text/words.js +159 -0
- package/dist/text/words.js.map +1 -0
- package/dist/types.d.ts +18 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +20 -0
- package/dist/types.js.map +1 -0
- package/dist/units.d.ts +47 -0
- package/dist/units.d.ts.map +1 -0
- package/dist/units.js +42 -0
- package/dist/units.js.map +1 -0
- package/dist/word-list.d.ts +34 -0
- package/dist/word-list.d.ts.map +1 -0
- package/dist/word-list.js +90 -0
- package/dist/word-list.js.map +1 -0
- package/package.json +41 -4
- package/src/cli.ts +9 -0
- package/src/config.test.ts +188 -0
- package/src/config.ts +318 -0
- package/src/dictionary.test.ts +82 -0
- package/src/dictionary.ts +177 -0
- package/src/files.test.ts +107 -0
- package/src/files.ts +191 -0
- package/src/format.ts +78 -0
- package/src/index.test.ts +28 -0
- package/src/index.ts +34 -0
- package/src/lexicon.ts +92 -0
- package/src/lint.test.ts +182 -0
- package/src/lint.ts +135 -0
- package/src/rules/about-quantity.ts +33 -0
- package/src/rules/index.ts +40 -0
- package/src/rules/ing-verb.test.ts +48 -0
- package/src/rules/ing-verb.ts +54 -0
- package/src/rules/latin-abbreviation.ts +46 -0
- package/src/rules/missing-subject.test.ts +53 -0
- package/src/rules/missing-subject.ts +129 -0
- package/src/rules/modal-verb.test.ts +45 -0
- package/src/rules/modal-verb.ts +72 -0
- package/src/rules/noun-cluster.test.ts +49 -0
- package/src/rules/noun-cluster.ts +82 -0
- package/src/rules/paragraph-length.test.ts +30 -0
- package/src/rules/paragraph-length.ts +19 -0
- package/src/rules/passive-instruction.test.ts +38 -0
- package/src/rules/passive-instruction.ts +37 -0
- package/src/rules/pronouns.test.ts +38 -0
- package/src/rules/pronouns.ts +54 -0
- package/src/rules/punctuation.test.ts +59 -0
- package/src/rules/rule.ts +73 -0
- package/src/rules/semicolon.ts +19 -0
- package/src/rules/sentence-length.test.ts +52 -0
- package/src/rules/sentence-length.ts +32 -0
- package/src/rules/unknown-word.test.ts +81 -0
- package/src/rules/unknown-word.ts +43 -0
- package/src/rules/word-list-matcher.ts +68 -0
- package/src/rules/word-list.test.ts +110 -0
- package/src/rules/word-list.ts +25 -0
- package/src/run-cli.test.ts +189 -0
- package/src/run-cli.ts +193 -0
- package/src/source/blocks.ts +534 -0
- package/src/source/inline.test.ts +92 -0
- package/src/source/inline.ts +416 -0
- package/src/source/jsx.test.ts +46 -0
- package/src/source/jsx.ts +147 -0
- package/src/source/lines.test.ts +51 -0
- package/src/source/lines.ts +91 -0
- package/src/source/markdown.test.ts +210 -0
- package/src/source/markdown.ts +49 -0
- package/src/source/suppressions.ts +79 -0
- package/src/source/tsdoc.test.ts +137 -0
- package/src/source/tsdoc.ts +189 -0
- package/src/text/grammar.ts +304 -0
- package/src/text/phrases.ts +72 -0
- package/src/text/sentences.ts +148 -0
- package/src/text/text.test.ts +262 -0
- package/src/text/tokens.ts +135 -0
- package/src/text/words.ts +183 -0
- package/src/types.ts +39 -0
- package/src/units.ts +86 -0
- package/src/word-list.ts +128 -0
- package/ste.config.schema.json +87 -0
package/dist/run-cli.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The command-line interface. `runCli` does not use `process` directly, so
|
|
3
|
+
* the tests can give it arguments, an environment and output functions.
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { relative, resolve, sep } from "node:path";
|
|
7
|
+
import { ConfigError, DICTIONARY_ENV, loadConfig } from "./config.js";
|
|
8
|
+
import { DictionaryError, loadDictionary } from "./dictionary.js";
|
|
9
|
+
import { findFiles } from "./files.js";
|
|
10
|
+
import { formatJson, formatText, summarize } from "./format.js";
|
|
11
|
+
import { buildLexicon } from "./lexicon.js";
|
|
12
|
+
import { fileKind, Linter } from "./lint.js";
|
|
13
|
+
/** An incorrect command line. */
|
|
14
|
+
export class UsageError extends Error {
|
|
15
|
+
name = "UsageError";
|
|
16
|
+
}
|
|
17
|
+
export const USAGE = `Usage: ste-lint [options] [patterns...]
|
|
18
|
+
|
|
19
|
+
ste-lint examines the prose in Markdown files, MDX files and TypeScript doc
|
|
20
|
+
comments. It finds text that does not obey the writing rules of ASD-STE100
|
|
21
|
+
Simplified Technical English. The tool is an automated approximation of
|
|
22
|
+
these rules. It does not certify that a text obeys the standard.
|
|
23
|
+
|
|
24
|
+
Without patterns, ste-lint uses the "include" patterns of ste.config.json,
|
|
25
|
+
or the default patterns. Patterns are relative to the working directory.
|
|
26
|
+
|
|
27
|
+
Options:
|
|
28
|
+
--format <text|json> The output format. The default is "text".
|
|
29
|
+
--max-warnings <n> Exit with code 1 when there are more than n warnings.
|
|
30
|
+
--config <path> Use this configuration file.
|
|
31
|
+
-h, --help Show this help.
|
|
32
|
+
|
|
33
|
+
Exit codes:
|
|
34
|
+
0 No errors, and not more warnings than the maximum.
|
|
35
|
+
1 One or more errors, or more warnings than the maximum.
|
|
36
|
+
2 An incorrect command line or configuration, or no files.
|
|
37
|
+
|
|
38
|
+
Environment:
|
|
39
|
+
${DICTIONARY_ENV} The path of a local dictionary file. This path has
|
|
40
|
+
priority over "dictionaryPath" in ste.config.json.
|
|
41
|
+
`;
|
|
42
|
+
function optionValue(argv, index, name) {
|
|
43
|
+
const value = argv[index + 1];
|
|
44
|
+
if (value === undefined || value.startsWith("--"))
|
|
45
|
+
throw new UsageError(`The option ${name} needs a value.`);
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
/** This function reads the command-line arguments. */
|
|
49
|
+
export function parseArgs(argv) {
|
|
50
|
+
const patterns = [];
|
|
51
|
+
let format = "text";
|
|
52
|
+
let maxWarnings = null;
|
|
53
|
+
let configPath = null;
|
|
54
|
+
let help = false;
|
|
55
|
+
for (let i = 0; i < argv.length; i++) {
|
|
56
|
+
const argument = argv[i];
|
|
57
|
+
const [name, inline] = argument.startsWith("--") && argument.includes("=") ? [argument.slice(0, argument.indexOf("=")), argument.slice(argument.indexOf("=") + 1)] : [argument, undefined];
|
|
58
|
+
const value = () => {
|
|
59
|
+
if (inline !== undefined)
|
|
60
|
+
return inline;
|
|
61
|
+
const next = optionValue(argv, i, name);
|
|
62
|
+
i++;
|
|
63
|
+
return next;
|
|
64
|
+
};
|
|
65
|
+
switch (name) {
|
|
66
|
+
case "-h":
|
|
67
|
+
case "--help":
|
|
68
|
+
help = true;
|
|
69
|
+
break;
|
|
70
|
+
case "--format": {
|
|
71
|
+
const text = value();
|
|
72
|
+
if (text !== "text" && text !== "json")
|
|
73
|
+
throw new UsageError(`The format must be "text" or "json", not "${text}".`);
|
|
74
|
+
format = text;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
case "--max-warnings": {
|
|
78
|
+
const text = value();
|
|
79
|
+
const count = Number(text);
|
|
80
|
+
if (!/^\d+$/.test(text) || !Number.isSafeInteger(count))
|
|
81
|
+
throw new UsageError(`--max-warnings must be an integer of 0 or more, not "${text}".`);
|
|
82
|
+
maxWarnings = count;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
case "--config":
|
|
86
|
+
configPath = value();
|
|
87
|
+
break;
|
|
88
|
+
default:
|
|
89
|
+
if (argument.startsWith("-") && argument !== "-")
|
|
90
|
+
throw new UsageError(`"${argument}" is not a known option. Use --help to show the options.`);
|
|
91
|
+
patterns.push(argument);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return { patterns, format, maxWarnings, configPath, help };
|
|
95
|
+
}
|
|
96
|
+
function displayPath(path, cwd) {
|
|
97
|
+
const shown = relative(cwd, path);
|
|
98
|
+
return (shown.length > 0 && !shown.startsWith("..") ? shown : path).split(sep).join("/");
|
|
99
|
+
}
|
|
100
|
+
function loadOptionalDictionary(config, io) {
|
|
101
|
+
if (config.dictionaryPath === null)
|
|
102
|
+
return null;
|
|
103
|
+
if (!existsSync(config.dictionaryPath)) {
|
|
104
|
+
const from = config.dictionarySource === "env" ? DICTIONARY_ENV : "dictionaryPath";
|
|
105
|
+
io.stderr(`ste-lint: the dictionary file ${config.dictionaryPath} (from ${from}) does not exist. The unknown-word rule is off.\n`);
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
return loadDictionary(config.dictionaryPath);
|
|
109
|
+
}
|
|
110
|
+
/** This function starts the linter with command-line arguments. The result is the exit code. */
|
|
111
|
+
export function runCli(argv, io) {
|
|
112
|
+
let options;
|
|
113
|
+
try {
|
|
114
|
+
options = parseArgs(argv);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
io.stderr(`ste-lint: ${error.message}\n`);
|
|
118
|
+
return 2;
|
|
119
|
+
}
|
|
120
|
+
if (options.help) {
|
|
121
|
+
io.stdout(USAGE);
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
let config;
|
|
125
|
+
let dictionary;
|
|
126
|
+
try {
|
|
127
|
+
config = loadConfig({ cwd: io.cwd, env: io.env, ...(options.configPath === null ? {} : { configPath: options.configPath }) });
|
|
128
|
+
dictionary = loadOptionalDictionary(config, io);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
if (error instanceof ConfigError || error instanceof DictionaryError) {
|
|
132
|
+
io.stderr(`ste-lint: ${error.message}\n`);
|
|
133
|
+
return 2;
|
|
134
|
+
}
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
const explicit = options.patterns.length > 0;
|
|
138
|
+
let files;
|
|
139
|
+
try {
|
|
140
|
+
// The patterns of the command line are relative to the working directory. The ignore patterns are relative to the configuration.
|
|
141
|
+
files = (explicit
|
|
142
|
+
? findFiles({ root: io.cwd, include: options.patterns, ignore: config.ignore, ignoreRoot: config.root })
|
|
143
|
+
: findFiles({ root: config.root, include: config.include, ignore: config.ignore })).filter((file) => fileKind(file) !== null);
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
// For example, a directory that the user cannot read (EACCES)
|
|
147
|
+
io.stderr(`ste-lint: cannot read the files: ${error.message}\n`);
|
|
148
|
+
return 2;
|
|
149
|
+
}
|
|
150
|
+
if (files.length === 0) {
|
|
151
|
+
io.stderr(explicit ? "ste-lint: no files match the patterns.\n" : "ste-lint: no files to examine.\n");
|
|
152
|
+
return explicit ? 2 : 0;
|
|
153
|
+
}
|
|
154
|
+
const linter = new Linter(config, buildLexicon(config, dictionary));
|
|
155
|
+
const findings = [];
|
|
156
|
+
let failed = false;
|
|
157
|
+
for (const file of files) {
|
|
158
|
+
try {
|
|
159
|
+
findings.push(...linter.lintFile(file, displayPath(file, resolve(io.cwd))));
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
io.stderr(`ste-lint: cannot examine ${file}: ${error.message}\n`);
|
|
163
|
+
failed = true;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const summary = summarize(findings, files.length);
|
|
167
|
+
io.stdout(options.format === "json" ? formatJson(findings, summary) : formatText(findings, summary));
|
|
168
|
+
const tooManyWarnings = options.maxWarnings !== null && summary.warnings > options.maxWarnings;
|
|
169
|
+
if (tooManyWarnings && options.format === "text") {
|
|
170
|
+
io.stderr(`ste-lint: ${summary.warnings} warnings. The maximum is ${options.maxWarnings}.\n`);
|
|
171
|
+
}
|
|
172
|
+
if (failed)
|
|
173
|
+
return 2;
|
|
174
|
+
return summary.errors > 0 || tooManyWarnings ? 1 : 0;
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=run-cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-cli.js","sourceRoot":"","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part of Markdown, GFM and MDX that has prose in it.
|
|
3
|
+
*
|
|
4
|
+
* The parser keeps paragraphs, headings, list items, block quotes and table
|
|
5
|
+
* cells. It removes fenced and indented code, HTML blocks, JSX tags, MDX
|
|
6
|
+
* import and export lines, MDX expressions, link reference definitions and
|
|
7
|
+
* thematic breaks. The TSDoc extractor uses the same parser for the text in
|
|
8
|
+
* a doc comment.
|
|
9
|
+
*
|
|
10
|
+
* The parser does not build a full CommonMark tree. It knows only the
|
|
11
|
+
* structure that the lint rules use. That is where a block starts and
|
|
12
|
+
* stops, and if the block is a heading, a table cell or text in a list item.
|
|
13
|
+
*/
|
|
14
|
+
import { type Line } from "./lines.js";
|
|
15
|
+
export type ListContext = {
|
|
16
|
+
readonly ordered: boolean;
|
|
17
|
+
};
|
|
18
|
+
/** A block of prose that the lint rules examine. */
|
|
19
|
+
export type ProseBlock = {
|
|
20
|
+
readonly kind: "paragraph" | "heading" | "table-cell";
|
|
21
|
+
/** The text lines of the block, without Markdown block syntax. */
|
|
22
|
+
readonly lines: readonly Line[];
|
|
23
|
+
/** The innermost list that contains the block, or null. */
|
|
24
|
+
readonly list: ListContext | null;
|
|
25
|
+
readonly quote: boolean;
|
|
26
|
+
/** 1 to 6 for a heading, 0 for other blocks. */
|
|
27
|
+
readonly headingDepth: number;
|
|
28
|
+
/** True for the cells of a table header row. */
|
|
29
|
+
readonly tableHeader: boolean;
|
|
30
|
+
};
|
|
31
|
+
export type DirectiveCommand = "disable" | "enable" | "disable-next";
|
|
32
|
+
/** A `ste-disable`, `ste-enable` or `ste-disable-next` comment. */
|
|
33
|
+
export type Directive = {
|
|
34
|
+
readonly kind: "directive";
|
|
35
|
+
readonly command: DirectiveCommand;
|
|
36
|
+
/** The rule IDs. An empty list means all rules. */
|
|
37
|
+
readonly rules: readonly string[];
|
|
38
|
+
readonly offset: number;
|
|
39
|
+
};
|
|
40
|
+
export type Block = ProseBlock | Directive;
|
|
41
|
+
export type BlockOptions = {
|
|
42
|
+
/** Parse JSX tags, ESM lines and `{...}` expressions as MDX does. */
|
|
43
|
+
readonly mdx: boolean;
|
|
44
|
+
};
|
|
45
|
+
/** This function parses `lines` into prose blocks and directive comments. */
|
|
46
|
+
export declare function parseBlocks(lines: readonly Line[], options: BlockOptions): Block[];
|
|
47
|
+
/** The directive in the text of a comment, or null. */
|
|
48
|
+
export declare function parseDirective(commentText: string, offset: number): Directive | null;
|
|
49
|
+
/** True for a GFM table delimiter row, for example `| --- | :-: |`. */
|
|
50
|
+
export declare function isDelimiterRow(text: string): boolean;
|
|
51
|
+
/** This function divides a table row into cells. A `|` in a code span or after `\` does not divide cells. */
|
|
52
|
+
export declare function splitCells(row: Line): Line[];
|
|
53
|
+
/** The index of the next run of exactly `length` backticks at or after `from`, or -1. */
|
|
54
|
+
export declare function findBacktickRun(text: string, from: number, length: number): number;
|
|
55
|
+
//# sourceMappingURL=blocks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../src/source/blocks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAgD,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAErF,MAAM,MAAM,WAAW,GAAG;IACtB,QAAQ,CAAC,OAAO,EAAG,OAAO,CAAC;CAC9B,CAAC;AAEF,oDAAoD;AACpD,MAAM,MAAM,UAAU,GAAG;IACrB,QAAQ,CAAC,IAAI,EAAG,WAAW,GAAG,SAAS,GAAG,YAAY,CAAC;IACvD,kEAAkE;IAClE,QAAQ,CAAC,KAAK,EAAG,SAAS,IAAI,EAAE,CAAC;IACjC,2DAA2D;IAC3D,QAAQ,CAAC,IAAI,EAAG,WAAW,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAG,OAAO,CAAC;IACzB,gDAAgD;IAChD,QAAQ,CAAC,YAAY,EAAG,MAAM,CAAC;IAC/B,gDAAgD;IAChD,QAAQ,CAAC,WAAW,EAAG,OAA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