markdownlint 0.34.0 → 0.36.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 +21 -0
- package/README.md +97 -45
- package/demo/markdownlint-browser.js +2186 -2164
- package/doc/CustomRules.md +66 -255
- package/doc/Rules.md +102 -29
- package/doc/md003.md +2 -2
- package/doc/md004.md +4 -3
- package/doc/md034.md +5 -0
- package/doc/md035.md +3 -8
- package/doc/md044.md +10 -0
- package/doc/md046.md +2 -2
- package/doc/md048.md +3 -2
- package/doc/md049.md +4 -3
- package/doc/md050.md +4 -4
- package/doc/md051.md +11 -3
- package/doc/md055.md +3 -2
- package/doc/md058.md +48 -0
- package/helpers/README.md +2 -45
- package/helpers/helpers.js +115 -607
- package/helpers/micromark-helpers.cjs +296 -0
- package/helpers/micromark-parse.cjs +313 -0
- package/helpers/package.json +5 -2
- package/helpers/shared.js +6 -0
- package/helpers/test.cjs +28 -0
- package/lib/cache.js +62 -13
- package/lib/configuration-strict.d.ts +1199 -0
- package/lib/configuration.d.ts +3 -1173
- package/lib/constants.js +3 -2
- package/lib/markdownit.cjs +172 -0
- package/lib/markdownlint.d.ts +103 -56
- package/lib/markdownlint.js +180 -120
- package/lib/md001.js +15 -9
- package/lib/md003.js +14 -9
- package/lib/md004.js +55 -48
- package/lib/md005.js +4 -13
- package/lib/md007.js +7 -11
- package/lib/md009.js +50 -44
- package/lib/md010.js +52 -33
- package/lib/md011.js +32 -23
- package/lib/md012.js +17 -9
- package/lib/md013.js +44 -38
- package/lib/md014.js +31 -38
- package/lib/md018.js +17 -9
- package/lib/md019-md021.js +80 -0
- package/lib/md020.js +14 -8
- package/lib/md022.js +13 -29
- package/lib/md023.js +22 -23
- package/lib/md024.js +12 -9
- package/lib/md025.js +15 -10
- package/lib/md026.js +2 -7
- package/lib/md027.js +7 -12
- package/lib/md028.js +3 -8
- package/lib/md029.js +40 -34
- package/lib/md030.js +4 -10
- package/lib/md031.js +45 -23
- package/lib/md032.js +33 -31
- package/lib/md033.js +3 -8
- package/lib/md034.js +21 -34
- package/lib/md035.js +2 -7
- package/lib/md036.js +19 -24
- package/lib/md037.js +3 -8
- package/lib/md038.js +11 -22
- package/lib/md039.js +64 -54
- package/lib/md040.js +13 -20
- package/lib/md041.js +5 -5
- package/lib/md042.js +44 -38
- package/lib/md043.js +20 -14
- package/lib/md044.js +34 -36
- package/lib/md045.js +5 -10
- package/lib/md046.js +2 -8
- package/lib/md048.js +30 -23
- package/lib/md049-md050.js +22 -12
- package/lib/md051.js +20 -28
- package/lib/md052.js +2 -2
- package/lib/md053.js +7 -6
- package/lib/md054.js +16 -23
- package/lib/md055.js +41 -49
- package/lib/md056.js +32 -33
- package/lib/md058.js +58 -0
- package/lib/rules.js +11 -4
- package/package.json +23 -20
- package/schema/.markdownlint.jsonc +58 -52
- package/schema/.markdownlint.yaml +56 -51
- package/schema/ValidatingConfiguration.md +6 -8
- package/schema/markdownlint-config-schema-strict.json +1841 -0
- package/schema/markdownlint-config-schema.json +141 -109
- package/style/prettier.json +1 -0
- package/helpers/micromark.cjs +0 -445
- package/lib/md019.js +0 -42
- package/lib/md021.js +0 -65
package/style/prettier.json
CHANGED
package/helpers/micromark.cjs
DELETED
|
@@ -1,445 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
"use strict";
|
|
4
|
-
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
const {
|
|
7
|
-
directive, gfmAutolinkLiteral, gfmFootnote, gfmTable, math,
|
|
8
|
-
parse, postprocess, preprocess
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
} = require("markdownlint-micromark");
|
|
11
|
-
const { newLineRe } = require("./shared.js");
|
|
12
|
-
|
|
13
|
-
const flatTokensSymbol = Symbol("flat-tokens");
|
|
14
|
-
|
|
15
|
-
/** @typedef {import("markdownlint-micromark").Event} Event */
|
|
16
|
-
/** @typedef {import("markdownlint-micromark").ParseOptions} ParseOptions */
|
|
17
|
-
/** @typedef {import("markdownlint-micromark").TokenType} TokenType */
|
|
18
|
-
/** @typedef {import("../lib/markdownlint.js").MicromarkToken} Token */
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Returns whether a token is an htmlFlow type containing an HTML comment.
|
|
22
|
-
*
|
|
23
|
-
* @param {Token} token Micromark token.
|
|
24
|
-
* @returns {boolean} True iff token is htmlFlow containing a comment.
|
|
25
|
-
*/
|
|
26
|
-
function isHtmlFlowComment(token) {
|
|
27
|
-
const { text, type } = token;
|
|
28
|
-
if (
|
|
29
|
-
(type === "htmlFlow") &&
|
|
30
|
-
text.startsWith("<!--") &&
|
|
31
|
-
text.endsWith("-->")
|
|
32
|
-
) {
|
|
33
|
-
const comment = text.slice(4, -3);
|
|
34
|
-
return (
|
|
35
|
-
!comment.startsWith(">") &&
|
|
36
|
-
!comment.startsWith("->") &&
|
|
37
|
-
!comment.endsWith("-")
|
|
38
|
-
// The following condition from the CommonMark specification is commented
|
|
39
|
-
// to avoid parsing HTML comments that include "--" because that is NOT a
|
|
40
|
-
// condition of the HTML specification.
|
|
41
|
-
// https://spec.commonmark.org/0.30/#raw-html
|
|
42
|
-
// https://html.spec.whatwg.org/multipage/syntax.html#comments
|
|
43
|
-
// && !comment.includes("--")
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Parses a Markdown document and returns Micromark events.
|
|
51
|
-
*
|
|
52
|
-
* @param {string} markdown Markdown document.
|
|
53
|
-
* @param {ParseOptions} [micromarkOptions] Options for micromark.
|
|
54
|
-
* @param {boolean} [referencesDefined] Treat references as defined.
|
|
55
|
-
* @returns {Event[]} Micromark events.
|
|
56
|
-
*/
|
|
57
|
-
function getMicromarkEvents(
|
|
58
|
-
markdown,
|
|
59
|
-
micromarkOptions = {},
|
|
60
|
-
referencesDefined = true
|
|
61
|
-
) {
|
|
62
|
-
|
|
63
|
-
// Customize options object to add useful extensions
|
|
64
|
-
micromarkOptions.extensions = micromarkOptions.extensions || [];
|
|
65
|
-
micromarkOptions.extensions.push(
|
|
66
|
-
directive(),
|
|
67
|
-
gfmAutolinkLiteral(),
|
|
68
|
-
gfmFootnote(),
|
|
69
|
-
gfmTable(),
|
|
70
|
-
math()
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
// Use micromark to parse document into Events
|
|
74
|
-
const encoding = undefined;
|
|
75
|
-
const eol = true;
|
|
76
|
-
const parseContext = parse(micromarkOptions);
|
|
77
|
-
if (referencesDefined) {
|
|
78
|
-
// Customize ParseContext to treat all references as defined
|
|
79
|
-
parseContext.defined.includes = (searchElement) => searchElement.length > 0;
|
|
80
|
-
}
|
|
81
|
-
const chunks = preprocess()(markdown, encoding, eol);
|
|
82
|
-
const events = postprocess(parseContext.document().write(chunks));
|
|
83
|
-
return events;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Parses a Markdown document and returns (frozen) tokens.
|
|
88
|
-
*
|
|
89
|
-
* @param {string} markdown Markdown document.
|
|
90
|
-
* @param {ParseOptions} micromarkOptions Options for micromark.
|
|
91
|
-
* @param {boolean} referencesDefined Treat references as defined.
|
|
92
|
-
* @param {number} lineDelta Offset to apply to start/end line.
|
|
93
|
-
* @param {Token} [ancestor] Parent of top-most tokens.
|
|
94
|
-
* @returns {Token[]} Micromark tokens (frozen).
|
|
95
|
-
*/
|
|
96
|
-
function micromarkParseWithOffset(
|
|
97
|
-
markdown,
|
|
98
|
-
micromarkOptions,
|
|
99
|
-
referencesDefined,
|
|
100
|
-
lineDelta,
|
|
101
|
-
ancestor
|
|
102
|
-
) {
|
|
103
|
-
// Use micromark to parse document into Events
|
|
104
|
-
const events = getMicromarkEvents(
|
|
105
|
-
markdown, micromarkOptions, referencesDefined
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
// Create Token objects
|
|
109
|
-
const document = [];
|
|
110
|
-
let flatTokens = [];
|
|
111
|
-
/** @type {Token} */
|
|
112
|
-
const root = {
|
|
113
|
-
"type": "data",
|
|
114
|
-
"startLine": -1,
|
|
115
|
-
"startColumn": -1,
|
|
116
|
-
"endLine": -1,
|
|
117
|
-
"endColumn": -1,
|
|
118
|
-
"text": "ROOT",
|
|
119
|
-
"children": document,
|
|
120
|
-
"parent": null
|
|
121
|
-
};
|
|
122
|
-
const history = [ root ];
|
|
123
|
-
let current = root;
|
|
124
|
-
// eslint-disable-next-line jsdoc/valid-types
|
|
125
|
-
/** @type ParseOptions | null */
|
|
126
|
-
let reparseOptions = null;
|
|
127
|
-
let lines = null;
|
|
128
|
-
let skipHtmlFlowChildren = false;
|
|
129
|
-
for (const event of events) {
|
|
130
|
-
const [ kind, token, context ] = event;
|
|
131
|
-
const { type, start, end } = token;
|
|
132
|
-
const { "column": startColumn, "line": startLine } = start;
|
|
133
|
-
const { "column": endColumn, "line": endLine } = end;
|
|
134
|
-
const text = context.sliceSerialize(token);
|
|
135
|
-
if ((kind === "enter") && !skipHtmlFlowChildren) {
|
|
136
|
-
const previous = current;
|
|
137
|
-
history.push(previous);
|
|
138
|
-
current = {
|
|
139
|
-
type,
|
|
140
|
-
"startLine": startLine + lineDelta,
|
|
141
|
-
startColumn,
|
|
142
|
-
"endLine": endLine + lineDelta,
|
|
143
|
-
endColumn,
|
|
144
|
-
text,
|
|
145
|
-
"children": [],
|
|
146
|
-
"parent": ((previous === root) ? (ancestor || null) : previous)
|
|
147
|
-
};
|
|
148
|
-
previous.children.push(current);
|
|
149
|
-
flatTokens.push(current);
|
|
150
|
-
if ((current.type === "htmlFlow") && !isHtmlFlowComment(current)) {
|
|
151
|
-
skipHtmlFlowChildren = true;
|
|
152
|
-
if (!reparseOptions || !lines) {
|
|
153
|
-
reparseOptions = {
|
|
154
|
-
...micromarkOptions,
|
|
155
|
-
"extensions": [
|
|
156
|
-
{
|
|
157
|
-
"disable": {
|
|
158
|
-
"null": [ "codeIndented", "htmlFlow" ]
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
]
|
|
162
|
-
};
|
|
163
|
-
lines = markdown.split(newLineRe);
|
|
164
|
-
}
|
|
165
|
-
const reparseMarkdown = lines
|
|
166
|
-
.slice(current.startLine - 1, current.endLine)
|
|
167
|
-
.join("\n");
|
|
168
|
-
const tokens = micromarkParseWithOffset(
|
|
169
|
-
reparseMarkdown,
|
|
170
|
-
reparseOptions,
|
|
171
|
-
referencesDefined,
|
|
172
|
-
current.startLine - 1,
|
|
173
|
-
current
|
|
174
|
-
);
|
|
175
|
-
current.children = tokens;
|
|
176
|
-
// Avoid stack overflow of Array.push(...spread)
|
|
177
|
-
// eslint-disable-next-line unicorn/prefer-spread
|
|
178
|
-
flatTokens = flatTokens.concat(tokens[flatTokensSymbol]);
|
|
179
|
-
}
|
|
180
|
-
} else if (kind === "exit") {
|
|
181
|
-
if (type === "htmlFlow") {
|
|
182
|
-
skipHtmlFlowChildren = false;
|
|
183
|
-
}
|
|
184
|
-
if (!skipHtmlFlowChildren) {
|
|
185
|
-
Object.freeze(current.children);
|
|
186
|
-
Object.freeze(current);
|
|
187
|
-
// @ts-ignore
|
|
188
|
-
current = history.pop();
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// Return document
|
|
194
|
-
Object.defineProperty(document, flatTokensSymbol, { "value": flatTokens });
|
|
195
|
-
Object.freeze(document);
|
|
196
|
-
return document;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Parses a Markdown document and returns (frozen) tokens.
|
|
201
|
-
*
|
|
202
|
-
* @param {string} markdown Markdown document.
|
|
203
|
-
* @param {ParseOptions} [micromarkOptions] Options for micromark.
|
|
204
|
-
* @param {boolean} [referencesDefined] Treat references as defined.
|
|
205
|
-
* @returns {Token[]} Micromark tokens (frozen).
|
|
206
|
-
*/
|
|
207
|
-
function micromarkParse(
|
|
208
|
-
markdown,
|
|
209
|
-
micromarkOptions = {},
|
|
210
|
-
referencesDefined = true
|
|
211
|
-
) {
|
|
212
|
-
return micromarkParseWithOffset(
|
|
213
|
-
markdown,
|
|
214
|
-
micromarkOptions,
|
|
215
|
-
referencesDefined,
|
|
216
|
-
0
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* @callback AllowedPredicate
|
|
222
|
-
* @param {Token} token Micromark token.
|
|
223
|
-
* @returns {boolean} True iff allowed.
|
|
224
|
-
*/
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* @callback TransformPredicate
|
|
228
|
-
* @param {Token} token Micromark token.
|
|
229
|
-
* @returns {Token[]} Child tokens.
|
|
230
|
-
*/
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Filter a list of Micromark tokens by predicate.
|
|
234
|
-
*
|
|
235
|
-
* @param {Token[]} tokens Micromark tokens.
|
|
236
|
-
* @param {AllowedPredicate} [allowed] Allowed token predicate.
|
|
237
|
-
* @param {TransformPredicate} [transformChildren] Transform predicate.
|
|
238
|
-
* @returns {Token[]} Filtered tokens.
|
|
239
|
-
*/
|
|
240
|
-
function filterByPredicate(tokens, allowed, transformChildren) {
|
|
241
|
-
allowed = allowed || (() => true);
|
|
242
|
-
const result = [];
|
|
243
|
-
const queue = [
|
|
244
|
-
{
|
|
245
|
-
"array": tokens,
|
|
246
|
-
"index": 0
|
|
247
|
-
}
|
|
248
|
-
];
|
|
249
|
-
while (queue.length > 0) {
|
|
250
|
-
const current = queue[queue.length - 1];
|
|
251
|
-
const { array, index } = current;
|
|
252
|
-
if (index < array.length) {
|
|
253
|
-
const token = array[current.index++];
|
|
254
|
-
if (allowed(token)) {
|
|
255
|
-
result.push(token);
|
|
256
|
-
}
|
|
257
|
-
const { children } = token;
|
|
258
|
-
if (children.length > 0) {
|
|
259
|
-
const transformed =
|
|
260
|
-
transformChildren ? transformChildren(token) : children;
|
|
261
|
-
queue.push(
|
|
262
|
-
{
|
|
263
|
-
"array": transformed,
|
|
264
|
-
"index": 0
|
|
265
|
-
}
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
} else {
|
|
269
|
-
queue.pop();
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
return result;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Filter a list of Micromark tokens by type.
|
|
277
|
-
*
|
|
278
|
-
* @param {Token[]} tokens Micromark tokens.
|
|
279
|
-
* @param {TokenType[]} types Types to allow.
|
|
280
|
-
* @returns {Token[]} Filtered tokens.
|
|
281
|
-
*/
|
|
282
|
-
function filterByTypes(tokens, types) {
|
|
283
|
-
const predicate = (token) => types.includes(token.type);
|
|
284
|
-
const flatTokens = tokens[flatTokensSymbol];
|
|
285
|
-
if (flatTokens) {
|
|
286
|
-
return flatTokens.filter(predicate);
|
|
287
|
-
}
|
|
288
|
-
return filterByPredicate(tokens, predicate);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Gets the heading level of a Micromark heading tokan.
|
|
293
|
-
*
|
|
294
|
-
* @param {Token} heading Micromark heading token.
|
|
295
|
-
* @returns {number} Heading level.
|
|
296
|
-
*/
|
|
297
|
-
function getHeadingLevel(heading) {
|
|
298
|
-
const headingSequence = filterByTypes(
|
|
299
|
-
heading.children,
|
|
300
|
-
[ "atxHeadingSequence", "setextHeadingLineSequence" ]
|
|
301
|
-
);
|
|
302
|
-
let level = 1;
|
|
303
|
-
const { text } = headingSequence[0];
|
|
304
|
-
if (text[0] === "#") {
|
|
305
|
-
level = Math.min(text.length, 6);
|
|
306
|
-
} else if (text[0] === "-") {
|
|
307
|
-
level = 2;
|
|
308
|
-
}
|
|
309
|
-
return level;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* HTML tag information.
|
|
314
|
-
*
|
|
315
|
-
* @typedef {Object} HtmlTagInfo
|
|
316
|
-
* @property {boolean} close True iff close tag.
|
|
317
|
-
* @property {string} name Tag name.
|
|
318
|
-
*/
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Gets information about the tag in an HTML token.
|
|
322
|
-
*
|
|
323
|
-
* @param {Token} token Micromark token.
|
|
324
|
-
* @returns {HtmlTagInfo | null} HTML tag information.
|
|
325
|
-
*/
|
|
326
|
-
function getHtmlTagInfo(token) {
|
|
327
|
-
const htmlTagNameRe = /^<([^!>][^/\s>]*)/;
|
|
328
|
-
if (token.type === "htmlText") {
|
|
329
|
-
const match = htmlTagNameRe.exec(token.text);
|
|
330
|
-
if (match) {
|
|
331
|
-
const name = match[1];
|
|
332
|
-
const close = name.startsWith("/");
|
|
333
|
-
return {
|
|
334
|
-
close,
|
|
335
|
-
"name": close ? name.slice(1) : name
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
return null;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* Gets the nearest parent of the specified type for a Micromark token.
|
|
344
|
-
*
|
|
345
|
-
* @param {Token} token Micromark token.
|
|
346
|
-
* @param {TokenType[]} types Types to allow.
|
|
347
|
-
* @returns {Token | null} Parent token.
|
|
348
|
-
*/
|
|
349
|
-
function getTokenParentOfType(token, types) {
|
|
350
|
-
/** @type {Token | null} */
|
|
351
|
-
let current = token;
|
|
352
|
-
while ((current = current.parent) && !types.includes(current.type)) {
|
|
353
|
-
// Empty
|
|
354
|
-
}
|
|
355
|
-
return current;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* Get the text of the first match from a list of Micromark tokens by type.
|
|
360
|
-
*
|
|
361
|
-
* @param {Token[]} tokens Micromark tokens.
|
|
362
|
-
* @param {TokenType} type Type to match.
|
|
363
|
-
* @returns {string | null} Text of token.
|
|
364
|
-
*/
|
|
365
|
-
function getTokenTextByType(tokens, type) {
|
|
366
|
-
const filtered = tokens.filter((token) => token.type === type);
|
|
367
|
-
return (filtered.length > 0) ? filtered[0].text : null;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Determines if a Micromark token has an htmlFlow-type parent.
|
|
372
|
-
*
|
|
373
|
-
* @param {Token} token Micromark token.
|
|
374
|
-
* @returns {boolean} True iff the token has an htmlFlow-type parent.
|
|
375
|
-
*/
|
|
376
|
-
function inHtmlFlow(token) {
|
|
377
|
-
return getTokenParentOfType(token, [ "htmlFlow" ]) !== null;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Determines a list of Micromark tokens matches and returns a subset.
|
|
382
|
-
*
|
|
383
|
-
* @param {Token[]} tokens Micromark tokens.
|
|
384
|
-
* @param {TokenType[]} matchTypes Types to match.
|
|
385
|
-
* @param {TokenType[]} [resultTypes] Types to return.
|
|
386
|
-
* @returns {Token[] | null} Matching tokens.
|
|
387
|
-
*/
|
|
388
|
-
function matchAndGetTokensByType(tokens, matchTypes, resultTypes) {
|
|
389
|
-
if (tokens.length !== matchTypes.length) {
|
|
390
|
-
return null;
|
|
391
|
-
}
|
|
392
|
-
resultTypes = resultTypes || matchTypes;
|
|
393
|
-
const result = [];
|
|
394
|
-
// eslint-disable-next-line unicorn/no-for-loop
|
|
395
|
-
for (let i = 0; i < matchTypes.length; i++) {
|
|
396
|
-
if (tokens[i].type !== matchTypes[i]) {
|
|
397
|
-
return null;
|
|
398
|
-
} else if (resultTypes.includes(matchTypes[i])) {
|
|
399
|
-
result.push(tokens[i]);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
return result;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
/**
|
|
406
|
-
* Returns the specified token iff it is of the desired type.
|
|
407
|
-
*
|
|
408
|
-
* @param {Token} token Micromark token candidate.
|
|
409
|
-
* @param {TokenType} type Desired type.
|
|
410
|
-
* @returns {Token | null} Token instance.
|
|
411
|
-
*/
|
|
412
|
-
function tokenIfType(token, type) {
|
|
413
|
-
return (token && (token.type === type)) ? token : null;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
/**
|
|
417
|
-
* Set containing token types that do not contain content.
|
|
418
|
-
*
|
|
419
|
-
* @type {Set<TokenType>}
|
|
420
|
-
*/
|
|
421
|
-
const nonContentTokens = new Set([
|
|
422
|
-
"blockQuoteMarker",
|
|
423
|
-
"blockQuotePrefix",
|
|
424
|
-
"blockQuotePrefixWhitespace",
|
|
425
|
-
"lineEnding",
|
|
426
|
-
"lineEndingBlank",
|
|
427
|
-
"linePrefix",
|
|
428
|
-
"listItemIndent"
|
|
429
|
-
]);
|
|
430
|
-
|
|
431
|
-
module.exports = {
|
|
432
|
-
"parse": micromarkParse,
|
|
433
|
-
filterByPredicate,
|
|
434
|
-
filterByTypes,
|
|
435
|
-
getHeadingLevel,
|
|
436
|
-
getHtmlTagInfo,
|
|
437
|
-
getMicromarkEvents,
|
|
438
|
-
getTokenParentOfType,
|
|
439
|
-
getTokenTextByType,
|
|
440
|
-
inHtmlFlow,
|
|
441
|
-
isHtmlFlowComment,
|
|
442
|
-
matchAndGetTokensByType,
|
|
443
|
-
nonContentTokens,
|
|
444
|
-
tokenIfType
|
|
445
|
-
};
|
package/lib/md019.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
"use strict";
|
|
4
|
-
|
|
5
|
-
const { addErrorContext, filterTokens, headingStyleFor } =
|
|
6
|
-
require("../helpers");
|
|
7
|
-
|
|
8
|
-
// eslint-disable-next-line jsdoc/valid-types
|
|
9
|
-
/** @type import("./markdownlint").Rule */
|
|
10
|
-
module.exports = {
|
|
11
|
-
"names": [ "MD019", "no-multiple-space-atx" ],
|
|
12
|
-
"description": "Multiple spaces after hash on atx style heading",
|
|
13
|
-
"tags": [ "headings", "atx", "spaces" ],
|
|
14
|
-
"parser": "markdownit",
|
|
15
|
-
"function": function MD019(params, onError) {
|
|
16
|
-
filterTokens(params, "heading_open", (token) => {
|
|
17
|
-
if (headingStyleFor(token) === "atx") {
|
|
18
|
-
const { line, lineNumber } = token;
|
|
19
|
-
const match = /^(#+)([ \t]{2,})\S/.exec(line);
|
|
20
|
-
if (match) {
|
|
21
|
-
const [
|
|
22
|
-
,
|
|
23
|
-
{ "length": hashLength },
|
|
24
|
-
{ "length": spacesLength }
|
|
25
|
-
] = match;
|
|
26
|
-
addErrorContext(
|
|
27
|
-
onError,
|
|
28
|
-
lineNumber,
|
|
29
|
-
line.trim(),
|
|
30
|
-
null,
|
|
31
|
-
null,
|
|
32
|
-
[ 1, hashLength + spacesLength + 1 ],
|
|
33
|
-
{
|
|
34
|
-
"editColumn": hashLength + 1,
|
|
35
|
-
"deleteCount": spacesLength - 1
|
|
36
|
-
}
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
};
|
package/lib/md021.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
"use strict";
|
|
4
|
-
|
|
5
|
-
const { addErrorContext, filterTokens, headingStyleFor } =
|
|
6
|
-
require("../helpers");
|
|
7
|
-
|
|
8
|
-
const closedAtxRe = /^(#+)([ \t]+)([^ \t]|[^ \t].*[^ \t])([ \t]+)(#+)(\s*)$/;
|
|
9
|
-
|
|
10
|
-
// eslint-disable-next-line jsdoc/valid-types
|
|
11
|
-
/** @type import("./markdownlint").Rule */
|
|
12
|
-
module.exports = {
|
|
13
|
-
"names": [ "MD021", "no-multiple-space-closed-atx" ],
|
|
14
|
-
"description": "Multiple spaces inside hashes on closed atx style heading",
|
|
15
|
-
"tags": [ "headings", "atx_closed", "spaces" ],
|
|
16
|
-
"parser": "markdownit",
|
|
17
|
-
"function": function MD021(params, onError) {
|
|
18
|
-
filterTokens(params, "heading_open", (token) => {
|
|
19
|
-
if (headingStyleFor(token) === "atx_closed") {
|
|
20
|
-
const { line, lineNumber } = token;
|
|
21
|
-
const match = closedAtxRe.exec(line);
|
|
22
|
-
if (match) {
|
|
23
|
-
const [
|
|
24
|
-
,
|
|
25
|
-
leftHash,
|
|
26
|
-
{ "length": leftSpaceLength },
|
|
27
|
-
content,
|
|
28
|
-
{ "length": rightSpaceLength },
|
|
29
|
-
rightHash,
|
|
30
|
-
{ "length": trailSpaceLength }
|
|
31
|
-
] = match;
|
|
32
|
-
const left = leftSpaceLength > 1;
|
|
33
|
-
const right = rightSpaceLength > 1;
|
|
34
|
-
if (left || right) {
|
|
35
|
-
const length = line.length;
|
|
36
|
-
const leftHashLength = leftHash.length;
|
|
37
|
-
const rightHashLength = rightHash.length;
|
|
38
|
-
const range = left ?
|
|
39
|
-
[
|
|
40
|
-
1,
|
|
41
|
-
leftHashLength + leftSpaceLength + 1
|
|
42
|
-
] :
|
|
43
|
-
[
|
|
44
|
-
length - trailSpaceLength - rightHashLength - rightSpaceLength,
|
|
45
|
-
rightSpaceLength + rightHashLength + 1
|
|
46
|
-
];
|
|
47
|
-
addErrorContext(
|
|
48
|
-
onError,
|
|
49
|
-
lineNumber,
|
|
50
|
-
line.trim(),
|
|
51
|
-
left,
|
|
52
|
-
right,
|
|
53
|
-
range,
|
|
54
|
-
{
|
|
55
|
-
"editColumn": 1,
|
|
56
|
-
"deleteCount": length,
|
|
57
|
-
"insertText": `${leftHash} ${content} ${rightHash}`
|
|
58
|
-
}
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
};
|