@alexlit/lint-kit 127.2.0 → 127.3.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/package.json +1 -1
- package/packages/config-markdownlint/node_modules/markdownlint/CHANGELOG.md +457 -0
- package/packages/config-markdownlint/node_modules/markdownlint/CONTRIBUTING.md +93 -0
- package/packages/config-markdownlint/node_modules/markdownlint/LICENSE +21 -0
- package/packages/config-markdownlint/node_modules/markdownlint/README.md +1047 -0
- package/packages/config-markdownlint/node_modules/markdownlint/demo/markdownlint-browser.js +7094 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/CustomRules.md +388 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/Prettier.md +27 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/ReleaseProcess.md +20 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/Rules.md +2528 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md001.md +37 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md003.md +59 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md004.md +49 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md005.md +53 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md007.md +52 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md009.md +51 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md010.md +56 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md011.md +30 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md012.md +38 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md013.md +58 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md014.md +54 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md018.md +27 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md019.md +28 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md020.md +29 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md021.md +31 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md022.md +52 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md023.md +33 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md024.md +44 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md025.md +49 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md026.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md027.md +24 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md028.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md029.md +98 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md030.md +82 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md031.md +50 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md032.md +55 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md033.md +27 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md034.md +55 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md035.md +42 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md036.md +45 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md037.md +37 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md038.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md039.md +21 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md040.md +52 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md041.md +49 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md042.md +32 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md043.md +69 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md044.md +45 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md045.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md046.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md047.md +34 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md048.md +41 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md049.md +35 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md050.md +35 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md051.md +87 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md052.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md053.md +38 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md054.md +100 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md055.md +54 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md056.md +37 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md058.md +48 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/LICENSE +21 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/README.md +46 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/helpers.js +793 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/micromark.cjs +544 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/package.json +26 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/shared.js +10 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/cache.js +70 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/configuration-strict.d.ts +1185 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/configuration.d.ts +8 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/constants.js +15 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.d.ts +488 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.js +1572 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md001.js +31 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md003.js +50 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md004.js +86 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md005.js +72 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md007.js +88 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md009.js +95 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md010.js +78 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md011.js +57 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md012.js +43 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md013.js +105 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md014.js +54 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md018.js +46 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md019-md021.js +80 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md020.js +71 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md022.js +106 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md023.js +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md024.js +48 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md025.js +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md026.js +49 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md027.js +37 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md028.js +42 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md029.js +76 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md030.js +60 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md031.js +63 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md032.js +66 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md033.js +41 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md034.js +100 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md035.js +26 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md036.js +51 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md037.js +94 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md038.js +100 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md039.js +83 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md040.js +37 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md041.js +37 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md042.js +63 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md043.js +73 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md044.js +110 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md045.js +62 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md046.js +34 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md047.js +31 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md048.js +39 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md049-md050.js +103 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md051.js +170 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md052.js +42 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md053.js +62 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md054.js +125 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md055.js +79 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md056.js +56 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md058.js +43 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/rules.js +74 -0
- package/packages/config-markdownlint/node_modules/markdownlint/package.json +105 -0
- package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.jsonc +307 -0
- package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.yaml +275 -0
- package/packages/config-markdownlint/node_modules/markdownlint/schema/ValidatingConfiguration.md +26 -0
- package/packages/config-markdownlint/node_modules/markdownlint/schema/markdownlint-config-schema-strict.json +1819 -0
- package/packages/config-markdownlint/node_modules/markdownlint/schema/markdownlint-config-schema.json +1824 -0
- package/packages/config-markdownlint/node_modules/markdownlint/style/all.json +5 -0
- package/packages/config-markdownlint/node_modules/markdownlint/style/cirosantilli.json +22 -0
- package/packages/config-markdownlint/node_modules/markdownlint/style/prettier.json +27 -0
- package/packages/config-markdownlint/node_modules/markdownlint/style/relaxed.json +12 -0
- package/packages/config-markdownlint/node_modules/markdownlint-micromark/LICENSE +21 -0
- package/packages/config-markdownlint/node_modules/markdownlint-micromark/README.md +10 -0
- package/packages/config-markdownlint/node_modules/markdownlint-micromark/micromark-browser.js +2 -0
- package/packages/config-markdownlint/node_modules/markdownlint-micromark/micromark-html-browser.js +2 -0
- package/packages/config-markdownlint/node_modules/markdownlint-micromark/micromark.cjs +1 -0
- package/packages/config-markdownlint/node_modules/markdownlint-micromark/micromark.d.cts +1751 -0
- package/packages/config-markdownlint/node_modules/markdownlint-micromark/package.json +46 -0
- package/packages/config-markdownlint/package.json +2 -2
|
@@ -0,0 +1,544 @@
|
|
|
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
|
+
const reparseSymbol = Symbol("reparse");
|
|
15
|
+
|
|
16
|
+
/** @typedef {import("markdownlint-micromark").Event} Event */
|
|
17
|
+
/** @typedef {import("markdownlint-micromark").ParseOptions} ParseOptions */
|
|
18
|
+
/** @typedef {import("markdownlint-micromark").TokenType} TokenType */
|
|
19
|
+
/** @typedef {import("../lib/markdownlint.js").MicromarkToken} Token */
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Determines if a Micromark token is within an htmlFlow.
|
|
23
|
+
*
|
|
24
|
+
* @param {Token} token Micromark token.
|
|
25
|
+
* @returns {boolean} True iff the token is within an htmlFlow.
|
|
26
|
+
*/
|
|
27
|
+
function inHtmlFlow(token) {
|
|
28
|
+
return token[reparseSymbol];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Returns whether a token is an htmlFlow type containing an HTML comment.
|
|
33
|
+
*
|
|
34
|
+
* @param {Token} token Micromark token.
|
|
35
|
+
* @returns {boolean} True iff token is htmlFlow containing a comment.
|
|
36
|
+
*/
|
|
37
|
+
function isHtmlFlowComment(token) {
|
|
38
|
+
const { text, type } = token;
|
|
39
|
+
if (
|
|
40
|
+
(type === "htmlFlow") &&
|
|
41
|
+
text.startsWith("<!--") &&
|
|
42
|
+
text.endsWith("-->")
|
|
43
|
+
) {
|
|
44
|
+
const comment = text.slice(4, -3);
|
|
45
|
+
return (
|
|
46
|
+
!comment.startsWith(">") &&
|
|
47
|
+
!comment.startsWith("->") &&
|
|
48
|
+
!comment.endsWith("-")
|
|
49
|
+
// The following condition from the CommonMark specification is commented
|
|
50
|
+
// to avoid parsing HTML comments that include "--" because that is NOT a
|
|
51
|
+
// condition of the HTML specification.
|
|
52
|
+
// https://spec.commonmark.org/0.30/#raw-html
|
|
53
|
+
// https://html.spec.whatwg.org/multipage/syntax.html#comments
|
|
54
|
+
// && !comment.includes("--")
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Parses a Markdown document and returns Micromark events.
|
|
62
|
+
*
|
|
63
|
+
* @param {string} markdown Markdown document.
|
|
64
|
+
* @param {ParseOptions} [micromarkOptions] Options for micromark.
|
|
65
|
+
* @param {boolean} [referencesDefined] Treat references as defined.
|
|
66
|
+
* @returns {Event[]} Micromark events.
|
|
67
|
+
*/
|
|
68
|
+
function getMicromarkEvents(
|
|
69
|
+
markdown,
|
|
70
|
+
micromarkOptions = {},
|
|
71
|
+
referencesDefined = true
|
|
72
|
+
) {
|
|
73
|
+
|
|
74
|
+
// Customize options object to add useful extensions
|
|
75
|
+
micromarkOptions.extensions = micromarkOptions.extensions || [];
|
|
76
|
+
micromarkOptions.extensions.push(
|
|
77
|
+
directive(),
|
|
78
|
+
gfmAutolinkLiteral(),
|
|
79
|
+
gfmFootnote(),
|
|
80
|
+
gfmTable(),
|
|
81
|
+
math()
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
// Use micromark to parse document into Events
|
|
85
|
+
const encoding = undefined;
|
|
86
|
+
const eol = true;
|
|
87
|
+
const parseContext = parse(micromarkOptions);
|
|
88
|
+
if (referencesDefined) {
|
|
89
|
+
// Customize ParseContext to treat all references as defined
|
|
90
|
+
parseContext.defined.includes = (searchElement) => searchElement.length > 0;
|
|
91
|
+
}
|
|
92
|
+
const chunks = preprocess()(markdown, encoding, eol);
|
|
93
|
+
const events = postprocess(parseContext.document().write(chunks));
|
|
94
|
+
return events;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Parses a Markdown document and returns (frozen) tokens.
|
|
99
|
+
*
|
|
100
|
+
* @param {string} markdown Markdown document.
|
|
101
|
+
* @param {ParseOptions} micromarkOptions Options for micromark.
|
|
102
|
+
* @param {boolean} referencesDefined Treat references as defined.
|
|
103
|
+
* @param {number} lineDelta Offset to apply to start/end line.
|
|
104
|
+
* @param {Token} [ancestor] Parent of top-most tokens.
|
|
105
|
+
* @returns {Token[]} Micromark tokens (frozen).
|
|
106
|
+
*/
|
|
107
|
+
function micromarkParseWithOffset(
|
|
108
|
+
markdown,
|
|
109
|
+
micromarkOptions,
|
|
110
|
+
referencesDefined,
|
|
111
|
+
lineDelta,
|
|
112
|
+
ancestor
|
|
113
|
+
) {
|
|
114
|
+
// Use micromark to parse document into Events
|
|
115
|
+
const events = getMicromarkEvents(
|
|
116
|
+
markdown, micromarkOptions, referencesDefined
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
// Create Token objects
|
|
120
|
+
const document = [];
|
|
121
|
+
let flatTokens = [];
|
|
122
|
+
/** @type {Token} */
|
|
123
|
+
const root = {
|
|
124
|
+
"type": "data",
|
|
125
|
+
"startLine": -1,
|
|
126
|
+
"startColumn": -1,
|
|
127
|
+
"endLine": -1,
|
|
128
|
+
"endColumn": -1,
|
|
129
|
+
"text": "ROOT",
|
|
130
|
+
"children": document,
|
|
131
|
+
"parent": null
|
|
132
|
+
};
|
|
133
|
+
const history = [ root ];
|
|
134
|
+
let current = root;
|
|
135
|
+
// eslint-disable-next-line jsdoc/valid-types
|
|
136
|
+
/** @type ParseOptions | null */
|
|
137
|
+
let reparseOptions = null;
|
|
138
|
+
let lines = null;
|
|
139
|
+
let skipHtmlFlowChildren = false;
|
|
140
|
+
for (const event of events) {
|
|
141
|
+
const [ kind, token, context ] = event;
|
|
142
|
+
const { type, start, end } = token;
|
|
143
|
+
const { "column": startColumn, "line": startLine } = start;
|
|
144
|
+
const { "column": endColumn, "line": endLine } = end;
|
|
145
|
+
const text = context.sliceSerialize(token);
|
|
146
|
+
if ((kind === "enter") && !skipHtmlFlowChildren) {
|
|
147
|
+
const previous = current;
|
|
148
|
+
history.push(previous);
|
|
149
|
+
current = {
|
|
150
|
+
type,
|
|
151
|
+
"startLine": startLine + lineDelta,
|
|
152
|
+
startColumn,
|
|
153
|
+
"endLine": endLine + lineDelta,
|
|
154
|
+
endColumn,
|
|
155
|
+
text,
|
|
156
|
+
"children": [],
|
|
157
|
+
"parent": ((previous === root) ? (ancestor || null) : previous)
|
|
158
|
+
};
|
|
159
|
+
if (ancestor) {
|
|
160
|
+
Object.defineProperty(current, reparseSymbol, { "value": true });
|
|
161
|
+
}
|
|
162
|
+
previous.children.push(current);
|
|
163
|
+
flatTokens.push(current);
|
|
164
|
+
if ((current.type === "htmlFlow") && !isHtmlFlowComment(current)) {
|
|
165
|
+
skipHtmlFlowChildren = true;
|
|
166
|
+
if (!reparseOptions || !lines) {
|
|
167
|
+
reparseOptions = {
|
|
168
|
+
...micromarkOptions,
|
|
169
|
+
"extensions": [
|
|
170
|
+
{
|
|
171
|
+
"disable": {
|
|
172
|
+
"null": [ "codeIndented", "htmlFlow" ]
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
]
|
|
176
|
+
};
|
|
177
|
+
lines = markdown.split(newLineRe);
|
|
178
|
+
}
|
|
179
|
+
const reparseMarkdown = lines
|
|
180
|
+
.slice(current.startLine - 1, current.endLine)
|
|
181
|
+
.join("\n");
|
|
182
|
+
const tokens = micromarkParseWithOffset(
|
|
183
|
+
reparseMarkdown,
|
|
184
|
+
reparseOptions,
|
|
185
|
+
referencesDefined,
|
|
186
|
+
current.startLine - 1,
|
|
187
|
+
current
|
|
188
|
+
);
|
|
189
|
+
current.children = tokens;
|
|
190
|
+
// Avoid stack overflow of Array.push(...spread)
|
|
191
|
+
// eslint-disable-next-line unicorn/prefer-spread
|
|
192
|
+
flatTokens = flatTokens.concat(tokens[flatTokensSymbol]);
|
|
193
|
+
}
|
|
194
|
+
} else if (kind === "exit") {
|
|
195
|
+
if (type === "htmlFlow") {
|
|
196
|
+
skipHtmlFlowChildren = false;
|
|
197
|
+
}
|
|
198
|
+
if (!skipHtmlFlowChildren) {
|
|
199
|
+
Object.freeze(current.children);
|
|
200
|
+
Object.freeze(current);
|
|
201
|
+
// @ts-ignore
|
|
202
|
+
current = history.pop();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Return document
|
|
208
|
+
Object.defineProperty(document, flatTokensSymbol, { "value": flatTokens });
|
|
209
|
+
Object.freeze(document);
|
|
210
|
+
return document;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Parses a Markdown document and returns (frozen) tokens.
|
|
215
|
+
*
|
|
216
|
+
* @param {string} markdown Markdown document.
|
|
217
|
+
* @param {ParseOptions} [micromarkOptions] Options for micromark.
|
|
218
|
+
* @param {boolean} [referencesDefined] Treat references as defined.
|
|
219
|
+
* @returns {Token[]} Micromark tokens (frozen).
|
|
220
|
+
*/
|
|
221
|
+
function micromarkParse(
|
|
222
|
+
markdown,
|
|
223
|
+
micromarkOptions = {},
|
|
224
|
+
referencesDefined = true
|
|
225
|
+
) {
|
|
226
|
+
return micromarkParseWithOffset(
|
|
227
|
+
markdown,
|
|
228
|
+
micromarkOptions,
|
|
229
|
+
referencesDefined,
|
|
230
|
+
0
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Adds a range of numbers to a set.
|
|
236
|
+
*
|
|
237
|
+
* @param {Set<number>} set Set of numbers.
|
|
238
|
+
* @param {number} start Starting number.
|
|
239
|
+
* @param {number} end Ending number.
|
|
240
|
+
* @returns {void}
|
|
241
|
+
*/
|
|
242
|
+
function addRangeToSet(set, start, end) {
|
|
243
|
+
for (let i = start; i <= end; i++) {
|
|
244
|
+
set.add(i);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* @callback AllowedPredicate
|
|
250
|
+
* @param {Token} token Micromark token.
|
|
251
|
+
* @returns {boolean} True iff allowed.
|
|
252
|
+
*/
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* @callback TransformPredicate
|
|
256
|
+
* @param {Token} token Micromark token.
|
|
257
|
+
* @returns {Token[]} Child tokens.
|
|
258
|
+
*/
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Filter a list of Micromark tokens by predicate.
|
|
262
|
+
*
|
|
263
|
+
* @param {Token[]} tokens Micromark tokens.
|
|
264
|
+
* @param {AllowedPredicate} [allowed] Allowed token predicate.
|
|
265
|
+
* @param {TransformPredicate} [transformChildren] Transform predicate.
|
|
266
|
+
* @returns {Token[]} Filtered tokens.
|
|
267
|
+
*/
|
|
268
|
+
function filterByPredicate(tokens, allowed, transformChildren) {
|
|
269
|
+
allowed = allowed || (() => true);
|
|
270
|
+
const result = [];
|
|
271
|
+
const queue = [
|
|
272
|
+
{
|
|
273
|
+
"array": tokens,
|
|
274
|
+
"index": 0
|
|
275
|
+
}
|
|
276
|
+
];
|
|
277
|
+
while (queue.length > 0) {
|
|
278
|
+
const current = queue[queue.length - 1];
|
|
279
|
+
const { array, index } = current;
|
|
280
|
+
if (index < array.length) {
|
|
281
|
+
const token = array[current.index++];
|
|
282
|
+
if (allowed(token)) {
|
|
283
|
+
result.push(token);
|
|
284
|
+
}
|
|
285
|
+
const { children } = token;
|
|
286
|
+
if (children.length > 0) {
|
|
287
|
+
const transformed =
|
|
288
|
+
transformChildren ? transformChildren(token) : children;
|
|
289
|
+
queue.push(
|
|
290
|
+
{
|
|
291
|
+
"array": transformed,
|
|
292
|
+
"index": 0
|
|
293
|
+
}
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
} else {
|
|
297
|
+
queue.pop();
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return result;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Filter a list of Micromark tokens by type.
|
|
305
|
+
*
|
|
306
|
+
* @param {Token[]} tokens Micromark tokens.
|
|
307
|
+
* @param {TokenType[]} types Types to allow.
|
|
308
|
+
* @param {boolean} [htmlFlow] Whether to include htmlFlow content.
|
|
309
|
+
* @returns {Token[]} Filtered tokens.
|
|
310
|
+
*/
|
|
311
|
+
function filterByTypes(tokens, types, htmlFlow) {
|
|
312
|
+
const predicate = (token) =>
|
|
313
|
+
(htmlFlow || !inHtmlFlow(token)) && types.includes(token.type);
|
|
314
|
+
const flatTokens = tokens[flatTokensSymbol];
|
|
315
|
+
if (flatTokens) {
|
|
316
|
+
return flatTokens.filter(predicate);
|
|
317
|
+
}
|
|
318
|
+
return filterByPredicate(tokens, predicate);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Gets a list of nested Micromark token descendants by type path.
|
|
323
|
+
*
|
|
324
|
+
* @param {Token|Token[]} parent Micromark token parent or parents.
|
|
325
|
+
* @param {TokenType[]} typePath Micromark token type path.
|
|
326
|
+
* @returns {Token[]} Micromark token descendants.
|
|
327
|
+
*/
|
|
328
|
+
function getDescendantsByType(parent, typePath) {
|
|
329
|
+
let tokens = Array.isArray(parent) ? parent : [ parent ];
|
|
330
|
+
for (const type of typePath) {
|
|
331
|
+
tokens = tokens.flatMap((t) => t.children).filter((t) => t.type === type);
|
|
332
|
+
}
|
|
333
|
+
return tokens;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// eslint-disable-next-line jsdoc/valid-types
|
|
337
|
+
/** @typedef {readonly string[]} ReadonlyStringArray */
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Gets the line/column/length exclusions for a Micromark token.
|
|
341
|
+
*
|
|
342
|
+
* @param {ReadonlyStringArray} lines File/string lines.
|
|
343
|
+
* @param {Token} token Micromark token.
|
|
344
|
+
* @returns {number[][]} Exclusions (line number, start column, length).
|
|
345
|
+
*/
|
|
346
|
+
function getExclusionsForToken(lines, token) {
|
|
347
|
+
const exclusions = [];
|
|
348
|
+
const { endColumn, endLine, startColumn, startLine } = token;
|
|
349
|
+
for (let lineNumber = startLine; lineNumber <= endLine; lineNumber++) {
|
|
350
|
+
const start = (lineNumber === startLine) ? startColumn : 1;
|
|
351
|
+
const end = (lineNumber === endLine) ? endColumn : lines[lineNumber - 1].length;
|
|
352
|
+
exclusions.push([
|
|
353
|
+
lineNumber,
|
|
354
|
+
start,
|
|
355
|
+
end - start + 1
|
|
356
|
+
]);
|
|
357
|
+
}
|
|
358
|
+
return exclusions;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Gets the heading level of a Micromark heading tokan.
|
|
363
|
+
*
|
|
364
|
+
* @param {Token} heading Micromark heading token.
|
|
365
|
+
* @returns {number} Heading level.
|
|
366
|
+
*/
|
|
367
|
+
function getHeadingLevel(heading) {
|
|
368
|
+
const headingSequence = filterByTypes(
|
|
369
|
+
heading.children,
|
|
370
|
+
[ "atxHeadingSequence", "setextHeadingLineSequence" ]
|
|
371
|
+
);
|
|
372
|
+
let level = 1;
|
|
373
|
+
const { text } = headingSequence[0];
|
|
374
|
+
if (text[0] === "#") {
|
|
375
|
+
level = Math.min(text.length, 6);
|
|
376
|
+
} else if (text[0] === "-") {
|
|
377
|
+
level = 2;
|
|
378
|
+
}
|
|
379
|
+
return level;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Gets the heading style of a Micromark heading tokan.
|
|
384
|
+
*
|
|
385
|
+
* @param {Token} heading Micromark heading token.
|
|
386
|
+
* @returns {"atx" | "atx_closed" | "setext"} Heading style.
|
|
387
|
+
*/
|
|
388
|
+
function getHeadingStyle(heading) {
|
|
389
|
+
if (heading.type === "setextHeading") {
|
|
390
|
+
return "setext";
|
|
391
|
+
}
|
|
392
|
+
const atxHeadingSequenceLength = filterByTypes(
|
|
393
|
+
heading.children,
|
|
394
|
+
[ "atxHeadingSequence" ]
|
|
395
|
+
).length;
|
|
396
|
+
if (atxHeadingSequenceLength === 1) {
|
|
397
|
+
return "atx";
|
|
398
|
+
}
|
|
399
|
+
return "atx_closed";
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Gets the heading text of a Micromark heading token.
|
|
404
|
+
*
|
|
405
|
+
* @param {Token} heading Micromark heading token.
|
|
406
|
+
* @returns {string} Heading text.
|
|
407
|
+
*/
|
|
408
|
+
function getHeadingText(heading) {
|
|
409
|
+
const headingTexts = filterByTypes(
|
|
410
|
+
heading.children,
|
|
411
|
+
[ "atxHeadingText", "setextHeadingText" ]
|
|
412
|
+
);
|
|
413
|
+
return headingTexts[0]?.text.replace(/[\r\n]+/g, " ") || "";
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* HTML tag information.
|
|
418
|
+
*
|
|
419
|
+
* @typedef {Object} HtmlTagInfo
|
|
420
|
+
* @property {boolean} close True iff close tag.
|
|
421
|
+
* @property {string} name Tag name.
|
|
422
|
+
*/
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Gets information about the tag in an HTML token.
|
|
426
|
+
*
|
|
427
|
+
* @param {Token} token Micromark token.
|
|
428
|
+
* @returns {HtmlTagInfo | null} HTML tag information.
|
|
429
|
+
*/
|
|
430
|
+
function getHtmlTagInfo(token) {
|
|
431
|
+
const htmlTagNameRe = /^<([^!>][^/\s>]*)/;
|
|
432
|
+
if (token.type === "htmlText") {
|
|
433
|
+
const match = htmlTagNameRe.exec(token.text);
|
|
434
|
+
if (match) {
|
|
435
|
+
const name = match[1];
|
|
436
|
+
const close = name.startsWith("/");
|
|
437
|
+
return {
|
|
438
|
+
close,
|
|
439
|
+
"name": close ? name.slice(1) : name
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Gets the nearest parent of the specified type for a Micromark token.
|
|
448
|
+
*
|
|
449
|
+
* @param {Token} token Micromark token.
|
|
450
|
+
* @param {TokenType[]} types Types to allow.
|
|
451
|
+
* @returns {Token | null} Parent token.
|
|
452
|
+
*/
|
|
453
|
+
function getTokenParentOfType(token, types) {
|
|
454
|
+
/** @type {Token | null} */
|
|
455
|
+
let current = token;
|
|
456
|
+
while ((current = current.parent) && !types.includes(current.type)) {
|
|
457
|
+
// Empty
|
|
458
|
+
}
|
|
459
|
+
return current;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Get the text of the first match from a list of Micromark tokens by type.
|
|
464
|
+
*
|
|
465
|
+
* @param {Token[]} tokens Micromark tokens.
|
|
466
|
+
* @param {TokenType} type Type to match.
|
|
467
|
+
* @returns {string | null} Text of token.
|
|
468
|
+
*/
|
|
469
|
+
function getTokenTextByType(tokens, type) {
|
|
470
|
+
const filtered = tokens.filter((token) => token.type === type);
|
|
471
|
+
return (filtered.length > 0) ? filtered[0].text : null;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Determines a list of Micromark tokens matches and returns a subset.
|
|
476
|
+
*
|
|
477
|
+
* @param {Token[]} tokens Micromark tokens.
|
|
478
|
+
* @param {TokenType[]} matchTypes Types to match.
|
|
479
|
+
* @param {TokenType[]} [resultTypes] Types to return.
|
|
480
|
+
* @returns {Token[] | null} Matching tokens.
|
|
481
|
+
*/
|
|
482
|
+
function matchAndGetTokensByType(tokens, matchTypes, resultTypes) {
|
|
483
|
+
if (tokens.length !== matchTypes.length) {
|
|
484
|
+
return null;
|
|
485
|
+
}
|
|
486
|
+
resultTypes = resultTypes || matchTypes;
|
|
487
|
+
const result = [];
|
|
488
|
+
// eslint-disable-next-line unicorn/no-for-loop
|
|
489
|
+
for (let i = 0; i < matchTypes.length; i++) {
|
|
490
|
+
if (tokens[i].type !== matchTypes[i]) {
|
|
491
|
+
return null;
|
|
492
|
+
} else if (resultTypes.includes(matchTypes[i])) {
|
|
493
|
+
result.push(tokens[i]);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return result;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Returns the specified token iff it is of the desired type.
|
|
501
|
+
*
|
|
502
|
+
* @param {Token} token Micromark token candidate.
|
|
503
|
+
* @param {TokenType} type Desired type.
|
|
504
|
+
* @returns {Token | null} Token instance.
|
|
505
|
+
*/
|
|
506
|
+
function tokenIfType(token, type) {
|
|
507
|
+
return (token && (token.type === type)) ? token : null;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Set containing token types that do not contain content.
|
|
512
|
+
*
|
|
513
|
+
* @type {Set<TokenType>}
|
|
514
|
+
*/
|
|
515
|
+
const nonContentTokens = new Set([
|
|
516
|
+
"blockQuoteMarker",
|
|
517
|
+
"blockQuotePrefix",
|
|
518
|
+
"blockQuotePrefixWhitespace",
|
|
519
|
+
"lineEnding",
|
|
520
|
+
"lineEndingBlank",
|
|
521
|
+
"linePrefix",
|
|
522
|
+
"listItemIndent"
|
|
523
|
+
]);
|
|
524
|
+
|
|
525
|
+
module.exports = {
|
|
526
|
+
"parse": micromarkParse,
|
|
527
|
+
addRangeToSet,
|
|
528
|
+
filterByPredicate,
|
|
529
|
+
filterByTypes,
|
|
530
|
+
getDescendantsByType,
|
|
531
|
+
getExclusionsForToken,
|
|
532
|
+
getHeadingLevel,
|
|
533
|
+
getHeadingStyle,
|
|
534
|
+
getHeadingText,
|
|
535
|
+
getHtmlTagInfo,
|
|
536
|
+
getMicromarkEvents,
|
|
537
|
+
getTokenParentOfType,
|
|
538
|
+
getTokenTextByType,
|
|
539
|
+
inHtmlFlow,
|
|
540
|
+
isHtmlFlowComment,
|
|
541
|
+
matchAndGetTokensByType,
|
|
542
|
+
nonContentTokens,
|
|
543
|
+
tokenIfType
|
|
544
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "markdownlint-rule-helpers",
|
|
3
|
+
"version": "0.26.0",
|
|
4
|
+
"description": "A collection of markdownlint helper functions for custom rules",
|
|
5
|
+
"main": "./helpers.js",
|
|
6
|
+
"exports": "./helpers.js",
|
|
7
|
+
"author": "David Anson (https://dlaa.me/)",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"homepage": "https://github.com/DavidAnson/markdownlint",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/DavidAnson/markdownlint.git"
|
|
13
|
+
},
|
|
14
|
+
"bugs": "https://github.com/DavidAnson/markdownlint/issues",
|
|
15
|
+
"funding": "https://github.com/sponsors/DavidAnson",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=18"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"markdownlint-micromark": "0.1.2"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"markdownlint",
|
|
24
|
+
"markdownlint-rule"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
// Regular expression for matching common newline characters
|
|
6
|
+
// See NEWLINES_RE in markdown-it/lib/rules_core/normalize.js
|
|
7
|
+
module.exports.newLineRe = /\r\n?|\n/g;
|
|
8
|
+
|
|
9
|
+
// Regular expression for matching next lines
|
|
10
|
+
module.exports.nextLinesRe = /[\r\n][\s\S]*$/;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const helpers = require("../helpers");
|
|
6
|
+
const { filterByTypes } = require("../helpers/micromark.cjs");
|
|
7
|
+
|
|
8
|
+
/** @type {Map<string, object>} */
|
|
9
|
+
const map = new Map();
|
|
10
|
+
// eslint-disable-next-line no-undef-init
|
|
11
|
+
let params = undefined;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Initializes (resets) the cache.
|
|
15
|
+
*
|
|
16
|
+
* @param {import("./markdownlint").RuleParams} [p] Rule parameters object.
|
|
17
|
+
* @returns {void}
|
|
18
|
+
*/
|
|
19
|
+
function initialize(p) {
|
|
20
|
+
map.clear();
|
|
21
|
+
params = p;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Gets a cached object value - computes it and caches it.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} name Cache object name.
|
|
28
|
+
* @param {Function} getValue Getter for object value.
|
|
29
|
+
* @returns {Object} Object value.
|
|
30
|
+
*/
|
|
31
|
+
function getCached(name, getValue) {
|
|
32
|
+
if (map.has(name)) {
|
|
33
|
+
return map.get(name);
|
|
34
|
+
}
|
|
35
|
+
const value = getValue();
|
|
36
|
+
map.set(name, value);
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Filters a list of Micromark tokens by type and caches the result.
|
|
42
|
+
*
|
|
43
|
+
* @param {import("./markdownlint").MicromarkTokenType[]} types Types to allow.
|
|
44
|
+
* @param {boolean} [htmlFlow] Whether to include htmlFlow content.
|
|
45
|
+
* @returns {import("./markdownlint").MicromarkToken[]} Filtered tokens.
|
|
46
|
+
*/
|
|
47
|
+
function filterByTypesCached(types, htmlFlow) {
|
|
48
|
+
return getCached(
|
|
49
|
+
types.join("|"),
|
|
50
|
+
() => filterByTypes(params.parsers.micromark.tokens, types, htmlFlow)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Gets a reference link and image data object.
|
|
56
|
+
*
|
|
57
|
+
* @returns {Object} Reference link and image data object.
|
|
58
|
+
*/
|
|
59
|
+
function getReferenceLinkImageData() {
|
|
60
|
+
return getCached(
|
|
61
|
+
getReferenceLinkImageData.name,
|
|
62
|
+
() => helpers.getReferenceLinkImageData(params.parsers.micromark.tokens)
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = {
|
|
67
|
+
initialize,
|
|
68
|
+
filterByTypesCached,
|
|
69
|
+
getReferenceLinkImageData
|
|
70
|
+
};
|