markdownlint 0.30.0 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/demo/markdownlint-browser.js +448 -363
- package/doc/Rules.md +13 -6
- package/doc/md052.md +13 -6
- package/helpers/helpers.js +67 -9
- package/helpers/micromark.cjs +94 -66
- package/helpers/package.json +1 -1
- package/lib/constants.js +1 -1
- package/lib/markdownlint.d.ts +6 -2
- package/lib/markdownlint.js +16 -6
- package/lib/md032.js +9 -4
- package/lib/md033.js +3 -2
- package/lib/md037.js +41 -48
- package/lib/md043.js +42 -40
- package/lib/md044.js +15 -41
- package/lib/md049-md050.js +6 -3
- package/lib/md051.js +51 -22
- package/lib/md052.js +7 -3
- package/package.json +10 -10
- package/schema/.markdownlint.jsonc +4 -1
- package/schema/.markdownlint.yaml +3 -1
- package/schema/markdownlint-config-schema.json +13 -2
package/doc/Rules.md
CHANGED
|
@@ -2216,6 +2216,10 @@ Tags: `images`, `links`
|
|
|
2216
2216
|
|
|
2217
2217
|
Aliases: `reference-links-images`
|
|
2218
2218
|
|
|
2219
|
+
Parameters:
|
|
2220
|
+
|
|
2221
|
+
- `shortcut_syntax`: Include shortcut syntax (`boolean`, default `false`)
|
|
2222
|
+
|
|
2219
2223
|
Links and images in Markdown can provide the link destination or image source
|
|
2220
2224
|
at the time of use or can define it elsewhere and use a label for reference.
|
|
2221
2225
|
The reference format is convenient for keeping paragraph text clutter-free
|
|
@@ -2236,13 +2240,16 @@ Shortcut: ![image]
|
|
|
2236
2240
|
[image]: https://example.com/image
|
|
2237
2241
|
```
|
|
2238
2242
|
|
|
2239
|
-
A link or image renders correctly when
|
|
2240
|
-
|
|
2241
|
-
of undefined labels for "full" and "collapsed" reference syntax
|
|
2243
|
+
A link or image renders correctly when the corresponding label is defined, but
|
|
2244
|
+
displays as text with brackets when the label is not present. By default, this
|
|
2245
|
+
rule warns of undefined labels for "full" and "collapsed" reference syntax but
|
|
2246
|
+
not for "shortcut" syntax because it is ambiguous.
|
|
2242
2247
|
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2248
|
+
The text `[example]` could be a shortcut link or the text "example" in brackets,
|
|
2249
|
+
so "shortcut" syntax is ignored by default. To include "shortcut" syntax, set
|
|
2250
|
+
the `include_shortcut` parameter to `true`. Note that doing so produces warnings
|
|
2251
|
+
for *all* text in the document that *could* be a shortcut. If bracketed text is
|
|
2252
|
+
intentional, brackets can be escaped with the `\` character: `\[example\]`.
|
|
2246
2253
|
|
|
2247
2254
|
<a name="md053"></a>
|
|
2248
2255
|
|
package/doc/md052.md
CHANGED
|
@@ -4,6 +4,10 @@ Tags: `images`, `links`
|
|
|
4
4
|
|
|
5
5
|
Aliases: `reference-links-images`
|
|
6
6
|
|
|
7
|
+
Parameters:
|
|
8
|
+
|
|
9
|
+
- `shortcut_syntax`: Include shortcut syntax (`boolean`, default `false`)
|
|
10
|
+
|
|
7
11
|
Links and images in Markdown can provide the link destination or image source
|
|
8
12
|
at the time of use or can define it elsewhere and use a label for reference.
|
|
9
13
|
The reference format is convenient for keeping paragraph text clutter-free
|
|
@@ -24,10 +28,13 @@ Shortcut: ![image]
|
|
|
24
28
|
[image]: https://example.com/image
|
|
25
29
|
```
|
|
26
30
|
|
|
27
|
-
A link or image renders correctly when
|
|
28
|
-
|
|
29
|
-
of undefined labels for "full" and "collapsed" reference syntax
|
|
31
|
+
A link or image renders correctly when the corresponding label is defined, but
|
|
32
|
+
displays as text with brackets when the label is not present. By default, this
|
|
33
|
+
rule warns of undefined labels for "full" and "collapsed" reference syntax but
|
|
34
|
+
not for "shortcut" syntax because it is ambiguous.
|
|
30
35
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
The text `[example]` could be a shortcut link or the text "example" in brackets,
|
|
37
|
+
so "shortcut" syntax is ignored by default. To include "shortcut" syntax, set
|
|
38
|
+
the `include_shortcut` parameter to `true`. Note that doing so produces warnings
|
|
39
|
+
for *all* text in the document that *could* be a shortcut. If bracketed text is
|
|
40
|
+
intentional, brackets can be escaped with the `\` character: `\[example\]`.
|
package/helpers/helpers.js
CHANGED
|
@@ -322,12 +322,18 @@ module.exports.unorderedListStyleFor = function unorderedListStyleFor(token) {
|
|
|
322
322
|
}
|
|
323
323
|
};
|
|
324
324
|
|
|
325
|
+
/**
|
|
326
|
+
* @callback TokenCallback
|
|
327
|
+
* @param {MarkdownItToken} token Current token.
|
|
328
|
+
* @returns {void}
|
|
329
|
+
*/
|
|
330
|
+
|
|
325
331
|
/**
|
|
326
332
|
* Calls the provided function for each matching token.
|
|
327
333
|
*
|
|
328
334
|
* @param {Object} params RuleParams instance.
|
|
329
335
|
* @param {string} type Token type identifier.
|
|
330
|
-
* @param {
|
|
336
|
+
* @param {TokenCallback} handler Callback function.
|
|
331
337
|
* @returns {void}
|
|
332
338
|
*/
|
|
333
339
|
function filterTokens(params, type, handler) {
|
|
@@ -339,8 +345,17 @@ function filterTokens(params, type, handler) {
|
|
|
339
345
|
}
|
|
340
346
|
module.exports.filterTokens = filterTokens;
|
|
341
347
|
|
|
342
|
-
|
|
343
|
-
|
|
348
|
+
/**
|
|
349
|
+
* @typedef {Array} LineMetadata
|
|
350
|
+
*/
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Gets a line metadata array.
|
|
354
|
+
*
|
|
355
|
+
* @param {Object} params RuleParams instance.
|
|
356
|
+
* @returns {LineMetadata} Line metadata.
|
|
357
|
+
*/
|
|
358
|
+
function getLineMetadata(params) {
|
|
344
359
|
const lineMetadata = params.lines.map(
|
|
345
360
|
(line, index) => [ line, index, false, 0, false, false, false ]
|
|
346
361
|
);
|
|
@@ -372,18 +387,32 @@ module.exports.getLineMetadata = function getLineMetadata(params) {
|
|
|
372
387
|
lineMetadata[token.map[0]][6] = true;
|
|
373
388
|
});
|
|
374
389
|
return lineMetadata;
|
|
375
|
-
}
|
|
390
|
+
}
|
|
391
|
+
module.exports.getLineMetadata = getLineMetadata;
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* @callback EachLineCallback
|
|
395
|
+
* @param {string} line Line content.
|
|
396
|
+
* @param {number} lineIndex Line index (0-based).
|
|
397
|
+
* @param {boolean} inCode Iff in a code block.
|
|
398
|
+
* @param {number} onFence + if open, - if closed, 0 otherwise.
|
|
399
|
+
* @param {boolean} inTable Iff in a table.
|
|
400
|
+
* @param {boolean} inItem Iff in a list item.
|
|
401
|
+
* @param {boolean} inBreak Iff in semantic break.
|
|
402
|
+
* @returns {void}
|
|
403
|
+
*/
|
|
376
404
|
|
|
377
405
|
/**
|
|
378
406
|
* Calls the provided function for each line.
|
|
379
407
|
*
|
|
380
|
-
* @param {
|
|
381
|
-
* @param {
|
|
382
|
-
* inTable, inItem, inBreak).
|
|
408
|
+
* @param {LineMetadata} lineMetadata Line metadata object.
|
|
409
|
+
* @param {EachLineCallback} handler Function taking (line, lineIndex, inCode,
|
|
410
|
+
* onFence, inTable, inItem, inBreak).
|
|
383
411
|
* @returns {void}
|
|
384
412
|
*/
|
|
385
413
|
function forEachLine(lineMetadata, handler) {
|
|
386
414
|
for (const metadata of lineMetadata) {
|
|
415
|
+
// @ts-ignore
|
|
387
416
|
handler(...metadata);
|
|
388
417
|
}
|
|
389
418
|
}
|
|
@@ -454,12 +483,21 @@ module.exports.forEachHeading = function forEachHeading(params, handler) {
|
|
|
454
483
|
}
|
|
455
484
|
};
|
|
456
485
|
|
|
486
|
+
/**
|
|
487
|
+
* @callback InlineCodeSpanCallback
|
|
488
|
+
* @param {string} code Code content.
|
|
489
|
+
* @param {number} lineIndex Line index (0-based).
|
|
490
|
+
* @param {number} columnIndex Column index (0-based).
|
|
491
|
+
* @param {number} ticks Count of backticks.
|
|
492
|
+
* @returns {void}
|
|
493
|
+
*/
|
|
494
|
+
|
|
457
495
|
/**
|
|
458
496
|
* Calls the provided function for each inline code span's content.
|
|
459
497
|
*
|
|
460
498
|
* @param {string} input Markdown content.
|
|
461
|
-
* @param {
|
|
462
|
-
* columnIndex, ticks).
|
|
499
|
+
* @param {InlineCodeSpanCallback} handler Callback function taking (code,
|
|
500
|
+
* lineIndex, columnIndex, ticks).
|
|
463
501
|
* @returns {void}
|
|
464
502
|
*/
|
|
465
503
|
function forEachInlineCodeSpan(input, handler) {
|
|
@@ -945,3 +983,23 @@ function expandTildePath(file, os) {
|
|
|
945
983
|
return homedir ? file.replace(/^~($|\/|\\)/, `${homedir}$1`) : file;
|
|
946
984
|
}
|
|
947
985
|
module.exports.expandTildePath = expandTildePath;
|
|
986
|
+
|
|
987
|
+
// Copied from markdownlint.js to avoid TypeScript compiler import() issue.
|
|
988
|
+
/**
|
|
989
|
+
* @typedef {Object} MarkdownItToken
|
|
990
|
+
* @property {string[][]} attrs HTML attributes.
|
|
991
|
+
* @property {boolean} block Block-level token.
|
|
992
|
+
* @property {MarkdownItToken[]} children Child nodes.
|
|
993
|
+
* @property {string} content Tag contents.
|
|
994
|
+
* @property {boolean} hidden Ignore element.
|
|
995
|
+
* @property {string} info Fence info.
|
|
996
|
+
* @property {number} level Nesting level.
|
|
997
|
+
* @property {number[]} map Beginning/ending line numbers.
|
|
998
|
+
* @property {string} markup Markup text.
|
|
999
|
+
* @property {Object} meta Arbitrary data.
|
|
1000
|
+
* @property {number} nesting Level change.
|
|
1001
|
+
* @property {string} tag HTML tag name.
|
|
1002
|
+
* @property {string} type Token type.
|
|
1003
|
+
* @property {number} lineNumber Line number (1-based).
|
|
1004
|
+
* @property {string} line Line content.
|
|
1005
|
+
*/
|
package/helpers/micromark.cjs
CHANGED
|
@@ -10,6 +10,8 @@ const {
|
|
|
10
10
|
} = require("markdownlint-micromark");
|
|
11
11
|
const { newLineRe } = require("./shared.js");
|
|
12
12
|
|
|
13
|
+
const flatTokensSymbol = Symbol("flat-tokens");
|
|
14
|
+
|
|
13
15
|
/**
|
|
14
16
|
* Markdown token.
|
|
15
17
|
*
|
|
@@ -21,9 +23,32 @@ const { newLineRe } = require("./shared.js");
|
|
|
21
23
|
* @property {number} endColumn End column (1-based).
|
|
22
24
|
* @property {string} text Token text.
|
|
23
25
|
* @property {Token[]} children Child tokens.
|
|
24
|
-
* @property {Token[]} [htmlFlowChildren] Child tokens for htmlFlow.
|
|
25
26
|
*/
|
|
26
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Returns whether a token is an htmlFlow type containing an HTML comment.
|
|
30
|
+
*
|
|
31
|
+
* @param {Token} token Micromark token.
|
|
32
|
+
* @returns {boolean} True iff token is htmlFlow containing a comment.
|
|
33
|
+
*/
|
|
34
|
+
function isHtmlFlowComment(token) {
|
|
35
|
+
const { text, type } = token;
|
|
36
|
+
if (
|
|
37
|
+
(type === "htmlFlow") &&
|
|
38
|
+
text.startsWith("<!--") &&
|
|
39
|
+
text.endsWith("-->")
|
|
40
|
+
) {
|
|
41
|
+
const comment = text.slice(4, -3);
|
|
42
|
+
return (
|
|
43
|
+
!comment.startsWith(">") &&
|
|
44
|
+
!comment.startsWith("->") &&
|
|
45
|
+
!comment.endsWith("-") &&
|
|
46
|
+
!comment.includes("--")
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
|
|
27
52
|
/**
|
|
28
53
|
* Parses a Markdown document and returns Micromark events.
|
|
29
54
|
*
|
|
@@ -82,19 +107,21 @@ function micromarkParseWithOffset(
|
|
|
82
107
|
|
|
83
108
|
// Create Token objects
|
|
84
109
|
const document = [];
|
|
110
|
+
let flatTokens = [];
|
|
85
111
|
let current = {
|
|
86
112
|
"children": document
|
|
87
113
|
};
|
|
88
114
|
const history = [ current ];
|
|
89
115
|
let reparseOptions = null;
|
|
90
116
|
let lines = null;
|
|
117
|
+
let skipHtmlFlowChildren = false;
|
|
91
118
|
for (const event of events) {
|
|
92
119
|
const [ kind, token, context ] = event;
|
|
93
120
|
const { type, start, end } = token;
|
|
94
121
|
const { "column": startColumn, "line": startLine } = start;
|
|
95
122
|
const { "column": endColumn, "line": endLine } = end;
|
|
96
123
|
const text = context.sliceSerialize(token);
|
|
97
|
-
if (kind === "enter") {
|
|
124
|
+
if ((kind === "enter") && !skipHtmlFlowChildren) {
|
|
98
125
|
const previous = current;
|
|
99
126
|
history.push(previous);
|
|
100
127
|
current = {
|
|
@@ -106,7 +133,11 @@ function micromarkParseWithOffset(
|
|
|
106
133
|
text,
|
|
107
134
|
"children": []
|
|
108
135
|
};
|
|
109
|
-
|
|
136
|
+
previous.children.push(current);
|
|
137
|
+
flatTokens.push(current);
|
|
138
|
+
// @ts-ignore
|
|
139
|
+
if ((current.type === "htmlFlow") && !isHtmlFlowComment(current)) {
|
|
140
|
+
skipHtmlFlowChildren = true;
|
|
110
141
|
if (!reparseOptions || !lines) {
|
|
111
142
|
reparseOptions = {
|
|
112
143
|
...micromarkOptions,
|
|
@@ -123,23 +154,32 @@ function micromarkParseWithOffset(
|
|
|
123
154
|
const reparseMarkdown = lines
|
|
124
155
|
.slice(current.startLine - 1, current.endLine)
|
|
125
156
|
.join("\n");
|
|
126
|
-
|
|
157
|
+
const tokens = micromarkParseWithOffset(
|
|
127
158
|
reparseMarkdown,
|
|
128
159
|
reparseOptions,
|
|
129
160
|
referencesDefined,
|
|
130
161
|
current.startLine - 1
|
|
131
162
|
);
|
|
163
|
+
current.children = tokens;
|
|
164
|
+
// Avoid stack overflow of Array.push(...spread)
|
|
165
|
+
// eslint-disable-next-line unicorn/prefer-spread
|
|
166
|
+
flatTokens = flatTokens.concat(tokens[flatTokensSymbol]);
|
|
132
167
|
}
|
|
133
|
-
previous.children.push(current);
|
|
134
168
|
} else if (kind === "exit") {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
169
|
+
if (type === "htmlFlow") {
|
|
170
|
+
skipHtmlFlowChildren = false;
|
|
171
|
+
}
|
|
172
|
+
if (!skipHtmlFlowChildren) {
|
|
173
|
+
Object.freeze(current.children);
|
|
174
|
+
Object.freeze(current);
|
|
175
|
+
// @ts-ignore
|
|
176
|
+
current = history.pop();
|
|
177
|
+
}
|
|
139
178
|
}
|
|
140
179
|
}
|
|
141
180
|
|
|
142
181
|
// Return document
|
|
182
|
+
Object.defineProperty(document, flatTokensSymbol, { "value": flatTokens });
|
|
143
183
|
Object.freeze(document);
|
|
144
184
|
return document;
|
|
145
185
|
}
|
|
@@ -166,83 +206,73 @@ function micromarkParse(
|
|
|
166
206
|
}
|
|
167
207
|
|
|
168
208
|
/**
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* @
|
|
172
|
-
* @param {Function} allowed Allowed token predicate.
|
|
173
|
-
* @param {Function} [transformChildren] Transform children predicate.
|
|
174
|
-
* @returns {Token[]} Filtered tokens.
|
|
209
|
+
* @callback AllowedPredicate
|
|
210
|
+
* @param {Token} token Micromark token.
|
|
211
|
+
* @returns {boolean} True iff allowed.
|
|
175
212
|
*/
|
|
176
|
-
function filterByPredicate(tokens, allowed, transformChildren) {
|
|
177
|
-
const result = [];
|
|
178
|
-
const pending = [ ...tokens ];
|
|
179
|
-
let token = null;
|
|
180
|
-
while ((token = pending.shift())) {
|
|
181
|
-
if (allowed(token)) {
|
|
182
|
-
result.push(token);
|
|
183
|
-
}
|
|
184
|
-
if (token.children.length > 0) {
|
|
185
|
-
const transformed =
|
|
186
|
-
transformChildren ? transformChildren(token) : token.children;
|
|
187
|
-
pending.unshift(...transformed);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return result;
|
|
191
|
-
}
|
|
192
213
|
|
|
193
214
|
/**
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* @
|
|
197
|
-
* @param {string[]} allowed Types to allow.
|
|
198
|
-
* @returns {Token[]} Filtered tokens.
|
|
215
|
+
* @callback TransformPredicate
|
|
216
|
+
* @param {Token} token Micromark token.
|
|
217
|
+
* @returns {Token[]} Child tokens.
|
|
199
218
|
*/
|
|
200
|
-
function filterByTypes(tokens, allowed) {
|
|
201
|
-
return filterByPredicate(
|
|
202
|
-
tokens,
|
|
203
|
-
(token) => allowed.includes(token.type)
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
219
|
|
|
207
220
|
/**
|
|
208
|
-
* Filter a list of Micromark tokens
|
|
221
|
+
* Filter a list of Micromark tokens by predicate.
|
|
209
222
|
*
|
|
210
223
|
* @param {Token[]} tokens Micromark tokens.
|
|
224
|
+
* @param {AllowedPredicate} allowed Allowed token predicate.
|
|
225
|
+
* @param {TransformPredicate} [transformChildren] Transform predicate.
|
|
211
226
|
* @returns {Token[]} Filtered tokens.
|
|
212
227
|
*/
|
|
213
|
-
function
|
|
228
|
+
function filterByPredicate(tokens, allowed, transformChildren) {
|
|
214
229
|
const result = [];
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
230
|
+
const queue = [
|
|
231
|
+
{
|
|
232
|
+
"array": tokens,
|
|
233
|
+
"index": 0
|
|
234
|
+
}
|
|
235
|
+
];
|
|
236
|
+
while (queue.length > 0) {
|
|
237
|
+
const current = queue[queue.length - 1];
|
|
238
|
+
const { array, index } = current;
|
|
239
|
+
if (index < array.length) {
|
|
240
|
+
const token = array[current.index++];
|
|
241
|
+
if (allowed(token)) {
|
|
220
242
|
result.push(token);
|
|
221
|
-
} else {
|
|
222
|
-
// token.type === "htmlFlow"
|
|
223
|
-
// @ts-ignore
|
|
224
|
-
pending.push(token.htmlFlowChildren);
|
|
225
243
|
}
|
|
244
|
+
const { children } = token;
|
|
245
|
+
if (children.length > 0) {
|
|
246
|
+
const transformed =
|
|
247
|
+
transformChildren ? transformChildren(token) : children;
|
|
248
|
+
queue.push(
|
|
249
|
+
{
|
|
250
|
+
"array": transformed,
|
|
251
|
+
"index": 0
|
|
252
|
+
}
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
} else {
|
|
256
|
+
queue.pop();
|
|
226
257
|
}
|
|
227
258
|
}
|
|
228
259
|
return result;
|
|
229
260
|
}
|
|
230
261
|
|
|
231
262
|
/**
|
|
232
|
-
*
|
|
263
|
+
* Filter a list of Micromark tokens by type.
|
|
233
264
|
*
|
|
234
|
-
* @param {Token}
|
|
235
|
-
* @
|
|
265
|
+
* @param {Token[]} tokens Micromark tokens.
|
|
266
|
+
* @param {string[]} allowed Types to allow.
|
|
267
|
+
* @returns {Token[]} Filtered tokens.
|
|
236
268
|
*/
|
|
237
|
-
function
|
|
238
|
-
const
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
result.push(token);
|
|
243
|
-
pending.unshift(...token.children);
|
|
269
|
+
function filterByTypes(tokens, allowed) {
|
|
270
|
+
const predicate = (token) => allowed.includes(token.type);
|
|
271
|
+
const flatTokens = tokens[flatTokensSymbol];
|
|
272
|
+
if (flatTokens) {
|
|
273
|
+
return flatTokens.filter(predicate);
|
|
244
274
|
}
|
|
245
|
-
return
|
|
275
|
+
return filterByPredicate(tokens, predicate);
|
|
246
276
|
}
|
|
247
277
|
|
|
248
278
|
/**
|
|
@@ -338,10 +368,8 @@ function tokenIfType(token, type) {
|
|
|
338
368
|
|
|
339
369
|
module.exports = {
|
|
340
370
|
"parse": micromarkParse,
|
|
341
|
-
filterByHtmlTokens,
|
|
342
371
|
filterByPredicate,
|
|
343
372
|
filterByTypes,
|
|
344
|
-
flattenedChildren,
|
|
345
373
|
getHeadingLevel,
|
|
346
374
|
getHtmlTagInfo,
|
|
347
375
|
getMicromarkEvents,
|
package/helpers/package.json
CHANGED
package/lib/constants.js
CHANGED
package/lib/markdownlint.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export = markdownlint;
|
|
|
8
8
|
*/
|
|
9
9
|
declare function markdownlint(options: Options | null, callback: LintCallback): void;
|
|
10
10
|
declare namespace markdownlint {
|
|
11
|
-
export { markdownlintSync as sync, readConfig, readConfigSync, getVersion, promises, RuleFunction, RuleParams, MarkdownItToken, RuleOnError, RuleOnErrorInfo, RuleOnErrorFixInfo, Rule, Options, Plugin, ToStringCallback, LintResults, LintError, FixInfo, LintCallback, Configuration, RuleConfiguration, ConfigurationParser, ReadConfigCallback, ResolveConfigExtendsCallback };
|
|
11
|
+
export { markdownlintSync as sync, readConfig, readConfigSync, getVersion, promises, RuleFunction, RuleParams, MarkdownItToken, RuleOnError, RuleOnErrorInfo, RuleOnErrorFixInfo, Rule, Options, Plugin, ToStringCallback, LintResults, LintError, FixInfo, LintContentCallback, LintCallback, Configuration, RuleConfiguration, ConfigurationParser, ReadConfigCallback, ResolveConfigExtendsCallback };
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Configuration options.
|
|
@@ -64,7 +64,7 @@ type Options = {
|
|
|
64
64
|
/**
|
|
65
65
|
* Called with the result of the lint function.
|
|
66
66
|
*/
|
|
67
|
-
type LintCallback = (
|
|
67
|
+
type LintCallback = (error: Error | null, results?: LintResults) => void;
|
|
68
68
|
/**
|
|
69
69
|
* Lint specified Markdown files synchronously.
|
|
70
70
|
*
|
|
@@ -353,6 +353,10 @@ type FixInfo = {
|
|
|
353
353
|
*/
|
|
354
354
|
insertText?: string;
|
|
355
355
|
};
|
|
356
|
+
/**
|
|
357
|
+
* Called with the result of linting a string or document.
|
|
358
|
+
*/
|
|
359
|
+
type LintContentCallback = (error: Error | null, result?: LintError[]) => void;
|
|
356
360
|
/**
|
|
357
361
|
* Configuration object for linting rules. For a detailed schema, see
|
|
358
362
|
* {@link ../schema/markdownlint-config-schema.json}.
|
package/lib/markdownlint.js
CHANGED
|
@@ -520,7 +520,7 @@ function getEnabledRulesPerLineNumber(
|
|
|
520
520
|
* @param {boolean} handleRuleFailures Whether to handle exceptions in rules.
|
|
521
521
|
* @param {boolean} noInlineConfig Whether to allow inline configuration.
|
|
522
522
|
* @param {number} resultVersion Version of the LintResults object to return.
|
|
523
|
-
* @param {
|
|
523
|
+
* @param {LintContentCallback} callback Callback (err, result) function.
|
|
524
524
|
* @returns {void}
|
|
525
525
|
*/
|
|
526
526
|
function lintContent(
|
|
@@ -809,7 +809,7 @@ function lintContent(
|
|
|
809
809
|
* @param {number} resultVersion Version of the LintResults object to return.
|
|
810
810
|
* @param {Object} fs File system implementation.
|
|
811
811
|
* @param {boolean} synchronous Whether to execute synchronously.
|
|
812
|
-
* @param {
|
|
812
|
+
* @param {LintContentCallback} callback Callback (err, result) function.
|
|
813
813
|
* @returns {void}
|
|
814
814
|
*/
|
|
815
815
|
function lintFile(
|
|
@@ -859,7 +859,7 @@ function lintFile(
|
|
|
859
859
|
*
|
|
860
860
|
* @param {Options | null} options Options object.
|
|
861
861
|
* @param {boolean} synchronous Whether to execute synchronously.
|
|
862
|
-
* @param {
|
|
862
|
+
* @param {LintCallback} callback Callback (err, result) function.
|
|
863
863
|
* @returns {void}
|
|
864
864
|
*/
|
|
865
865
|
function lintInput(options, synchronous, callback) {
|
|
@@ -1022,7 +1022,7 @@ function markdownlintPromise(options) {
|
|
|
1022
1022
|
* @returns {LintResults} Results object.
|
|
1023
1023
|
*/
|
|
1024
1024
|
function markdownlintSync(options) {
|
|
1025
|
-
let results =
|
|
1025
|
+
let results = null;
|
|
1026
1026
|
lintInput(options, true, function callback(error, res) {
|
|
1027
1027
|
if (error) {
|
|
1028
1028
|
throw error;
|
|
@@ -1176,6 +1176,7 @@ function readConfig(file, parsers, fs, callback) {
|
|
|
1176
1176
|
}
|
|
1177
1177
|
// Read file
|
|
1178
1178
|
file = helpers.expandTildePath(file, require("node:os"));
|
|
1179
|
+
// eslint-disable-next-line n/prefer-promises/fs
|
|
1179
1180
|
fs.readFile(file, "utf8", (err, content) => {
|
|
1180
1181
|
if (err) {
|
|
1181
1182
|
// @ts-ignore
|
|
@@ -1416,12 +1417,21 @@ module.exports = markdownlint;
|
|
|
1416
1417
|
* @property {string} [insertText] Text to insert (after deleting).
|
|
1417
1418
|
*/
|
|
1418
1419
|
|
|
1420
|
+
/**
|
|
1421
|
+
* Called with the result of linting a string or document.
|
|
1422
|
+
*
|
|
1423
|
+
* @callback LintContentCallback
|
|
1424
|
+
* @param {Error | null} error Error iff failed.
|
|
1425
|
+
* @param {LintError[]} [result] Result iff successful.
|
|
1426
|
+
* @returns {void}
|
|
1427
|
+
*/
|
|
1428
|
+
|
|
1419
1429
|
/**
|
|
1420
1430
|
* Called with the result of the lint function.
|
|
1421
1431
|
*
|
|
1422
1432
|
* @callback LintCallback
|
|
1423
|
-
* @param {Error | null}
|
|
1424
|
-
* @param {LintResults} [results] Lint results.
|
|
1433
|
+
* @param {Error | null} error Error object iff failed.
|
|
1434
|
+
* @param {LintResults} [results] Lint results iff succeeded.
|
|
1425
1435
|
* @returns {void}
|
|
1426
1436
|
*/
|
|
1427
1437
|
|
package/lib/md032.js
CHANGED
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
const { addErrorContext, blockquotePrefixRe, isBlankLine } =
|
|
6
6
|
require("../helpers");
|
|
7
|
-
const { filterByPredicate
|
|
8
|
-
require("../helpers/micromark.cjs");
|
|
7
|
+
const { filterByPredicate } = require("../helpers/micromark.cjs");
|
|
9
8
|
|
|
10
9
|
const nonContentTokens = new Set([
|
|
11
10
|
"blockQuoteMarker",
|
|
@@ -47,7 +46,9 @@ module.exports = {
|
|
|
47
46
|
const topLevelLists = filterByPredicate(
|
|
48
47
|
parsers.micromark.tokens,
|
|
49
48
|
isList,
|
|
50
|
-
(token) => (
|
|
49
|
+
(token) => (
|
|
50
|
+
(isList(token) || (token.type === "htmlFlow")) ? [] : token.children
|
|
51
|
+
)
|
|
51
52
|
);
|
|
52
53
|
for (const list of topLevelLists) {
|
|
53
54
|
|
|
@@ -59,7 +60,11 @@ module.exports = {
|
|
|
59
60
|
|
|
60
61
|
// Find the "visual" end of the list
|
|
61
62
|
let endLine = list.endLine;
|
|
62
|
-
|
|
63
|
+
const flattenedChildren = filterByPredicate(
|
|
64
|
+
list.children,
|
|
65
|
+
() => true
|
|
66
|
+
);
|
|
67
|
+
for (const child of flattenedChildren.reverse()) {
|
|
63
68
|
if (!nonContentTokens.has(child.type)) {
|
|
64
69
|
endLine = child.endLine;
|
|
65
70
|
break;
|
package/lib/md033.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const { addError } = require("../helpers");
|
|
6
|
-
const {
|
|
6
|
+
const { filterByTypes, getHtmlTagInfo } =
|
|
7
7
|
require("../helpers/micromark.cjs");
|
|
8
8
|
|
|
9
9
|
const nextLinesRe = /[\r\n][\s\S]*$/;
|
|
@@ -16,7 +16,8 @@ module.exports = {
|
|
|
16
16
|
let allowedElements = params.config.allowed_elements;
|
|
17
17
|
allowedElements = Array.isArray(allowedElements) ? allowedElements : [];
|
|
18
18
|
allowedElements = allowedElements.map((element) => element.toLowerCase());
|
|
19
|
-
|
|
19
|
+
const { tokens } = params.parsers.micromark;
|
|
20
|
+
for (const token of filterByTypes(tokens, [ "htmlText" ])) {
|
|
20
21
|
const htmlTagInfo = getHtmlTagInfo(token);
|
|
21
22
|
if (
|
|
22
23
|
htmlTagInfo &&
|