markdownlint 0.41.0 → 0.42.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 +24 -0
- package/CONTRIBUTING.md +62 -77
- package/README.md +7 -7
- package/doc/CustomRules.md +6 -4
- package/doc/Rules.md +87 -36
- package/doc/md010.md +0 -1
- package/doc/md024.md +1 -1
- package/doc/md029.md +11 -1
- package/doc/md043.md +47 -9
- package/doc/md051.md +19 -19
- package/doc/md055.md +6 -3
- package/doc/md060.md +3 -2
- package/helpers/README.md +2 -2
- package/helpers/helpers.cjs +23 -7
- package/helpers/micromark-helpers.cjs +8 -12
- package/helpers/package.json +1 -5
- package/helpers/shared.cjs +1 -1
- package/lib/cache.mjs +1 -0
- package/lib/configuration-strict.d.ts +124 -112
- package/lib/constants.mjs +1 -1
- package/lib/defer-require.cjs +1 -0
- package/lib/exports.d.mts +29 -1
- package/lib/markdownit.cjs +8 -1
- package/lib/markdownlint.d.mts +337 -195
- package/lib/markdownlint.mjs +83 -87
- package/lib/md004.mjs +1 -0
- package/lib/md005.mjs +1 -1
- package/lib/md007.mjs +2 -2
- package/lib/md009.mjs +2 -3
- package/lib/md010.mjs +1 -1
- package/lib/md011.mjs +10 -7
- package/lib/md012.mjs +1 -1
- package/lib/md013.mjs +13 -9
- package/lib/md018.mjs +1 -1
- package/lib/md019-md021.mjs +1 -0
- package/lib/md020.mjs +1 -1
- package/lib/md022.mjs +6 -6
- package/lib/md024.mjs +1 -1
- package/lib/md025.mjs +1 -1
- package/lib/md027.mjs +1 -1
- package/lib/md028.mjs +1 -2
- package/lib/md029.mjs +34 -23
- package/lib/md030.mjs +4 -4
- package/lib/md031.mjs +1 -1
- package/lib/md032.mjs +5 -4
- package/lib/md033.mjs +1 -1
- package/lib/md034.mjs +1 -1
- package/lib/md037.mjs +1 -2
- package/lib/md039.mjs +5 -1
- package/lib/md041.mjs +1 -1
- package/lib/md043.mjs +98 -44
- package/lib/md044.mjs +2 -2
- package/lib/md048.mjs +1 -3
- package/lib/md051.mjs +3 -3
- package/lib/md055.mjs +11 -1
- package/lib/md056.mjs +1 -1
- package/lib/md058.mjs +1 -1
- package/lib/md060.mjs +24 -4
- package/lib/micromark-parse.mjs +3 -2
- package/lib/resolve-module.cjs +3 -2
- package/lib/resolve-module.d.cts +15 -10
- package/package.json +33 -34
- package/schema/.markdownlint.jsonc +54 -54
- package/schema/.markdownlint.yaml +76 -76
- package/schema/markdownlint-config-schema-strict.json +126 -118
- package/schema/markdownlint-config-schema.json +126 -118
package/doc/md043.md
CHANGED
|
@@ -6,7 +6,7 @@ Aliases: `required-headings`
|
|
|
6
6
|
|
|
7
7
|
Parameters:
|
|
8
8
|
|
|
9
|
-
- `headings`: List of headings (`string[]`, default `
|
|
9
|
+
- `headings`: List of headings (`string[]|null`, default `null`)
|
|
10
10
|
- `match_case`: Match case of headings (`boolean`, default `false`)
|
|
11
11
|
|
|
12
12
|
This rule is triggered when the headings in a file do not match the array of
|
|
@@ -37,13 +37,15 @@ To allow optional headings as with the following structure:
|
|
|
37
37
|
# Heading
|
|
38
38
|
## Item
|
|
39
39
|
### Detail (optional)
|
|
40
|
+
### Example (optional)
|
|
40
41
|
## Foot
|
|
41
42
|
### Notes (optional)
|
|
42
43
|
```
|
|
43
44
|
|
|
44
|
-
Use the special value
|
|
45
|
-
special value
|
|
46
|
-
`headings`
|
|
45
|
+
Use the special value `*` meaning "zero or more unspecified headings", the
|
|
46
|
+
special value `+` meaning "one or more unspecified headings", or the special
|
|
47
|
+
value `?` meaning "exactly one unspecified heading" and set the `headings`
|
|
48
|
+
parameter to something like:
|
|
47
49
|
|
|
48
50
|
```json
|
|
49
51
|
[
|
|
@@ -51,28 +53,64 @@ special value `"+"` meaning "one or more unspecified headings" and set the
|
|
|
51
53
|
"## Item",
|
|
52
54
|
"*",
|
|
53
55
|
"## Foot",
|
|
54
|
-
"
|
|
56
|
+
"+"
|
|
55
57
|
]
|
|
56
58
|
```
|
|
57
59
|
|
|
58
|
-
To
|
|
60
|
+
To require a heading with a specific level and text matching a specific pattern
|
|
61
|
+
(for example, a one-word project name):
|
|
59
62
|
|
|
60
63
|
```markdown
|
|
61
|
-
# Project
|
|
64
|
+
# Project
|
|
62
65
|
## Description
|
|
63
66
|
## Examples
|
|
64
67
|
```
|
|
65
68
|
|
|
66
|
-
|
|
69
|
+
Replace the `#` prefix character(s) with `%` and specify a regular expression;
|
|
70
|
+
the following example requires a level 1 heading with a single word made up of
|
|
71
|
+
at least 4 letters:
|
|
67
72
|
|
|
68
73
|
```json
|
|
69
74
|
[
|
|
70
|
-
"
|
|
75
|
+
"% [a-zA-Z]{4,}",
|
|
71
76
|
"## Description",
|
|
72
77
|
"## Examples"
|
|
73
78
|
]
|
|
74
79
|
```
|
|
75
80
|
|
|
81
|
+
To handle repeating heading sections (common in `CHANGELOG` files) such as the
|
|
82
|
+
following:
|
|
83
|
+
|
|
84
|
+
```markdown
|
|
85
|
+
# Changelog
|
|
86
|
+
## 1.0.0
|
|
87
|
+
### Fixes
|
|
88
|
+
### Features
|
|
89
|
+
## 2.0.0
|
|
90
|
+
### Fixes
|
|
91
|
+
### Features
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Use the special value `^` meaning "if the next heading does not match, loop
|
|
95
|
+
back to the previous matching marker":
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
[
|
|
99
|
+
"# Changelog",
|
|
100
|
+
"^",
|
|
101
|
+
"%% ^\\d+\\.\\d+\\.\\d+$",
|
|
102
|
+
"### Fixes",
|
|
103
|
+
"### Features",
|
|
104
|
+
"^"
|
|
105
|
+
]
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The simple form shown above is enough for most scenarios; if multiple loops are
|
|
109
|
+
needed, matching pairs of `^^`, `^^^`, etc. can be used in conjunction. The
|
|
110
|
+
prefix `%` and the special value `?` are supported with loops, but `*` and `+`
|
|
111
|
+
are not and will result in undefined behavior. To avoid infinite looping, a
|
|
112
|
+
violation is reported if the rule loops more than 1,000 times.
|
|
113
|
+
|
|
76
114
|
When an error is detected, this rule outputs the line number of the first
|
|
77
115
|
problematic heading (otherwise, it outputs the last line number of the file).
|
|
78
116
|
|
package/doc/md051.md
CHANGED
|
@@ -13,7 +13,7 @@ Parameters:
|
|
|
13
13
|
Fixable: Some violations can be fixed by tooling
|
|
14
14
|
|
|
15
15
|
This rule is triggered when a link fragment does not match any of the fragments
|
|
16
|
-
that are automatically generated for headings in
|
|
16
|
+
that are automatically generated by GitHub for headings in the document:
|
|
17
17
|
|
|
18
18
|
```markdown
|
|
19
19
|
# Heading Name
|
|
@@ -31,8 +31,9 @@ generated name (see below):
|
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
For consistency, this rule requires fragments to exactly match the [GitHub
|
|
34
|
-
|
|
35
|
-
lowercase. Therefore, the following
|
|
34
|
+
algorithm for section links][github-section-links] which (among other things)
|
|
35
|
+
converts letters to lowercase. Therefore, the following is reported as a
|
|
36
|
+
violation:
|
|
36
37
|
|
|
37
38
|
```markdown
|
|
38
39
|
# Heading Name
|
|
@@ -44,9 +45,9 @@ To ignore case when comparing fragments with heading names, the `ignore_case`
|
|
|
44
45
|
parameter can be set to `true`. In this configuration, the previous example is
|
|
45
46
|
not reported as a violation.
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
Some platforms allow the syntax `{#named-anchor}` to be used within a heading to
|
|
49
|
+
provide a specific name (consisting of only lower-case letters, numbers, `-`,
|
|
50
|
+
and `_`); that is allowed by this rule:
|
|
50
51
|
|
|
51
52
|
```markdown
|
|
52
53
|
# Heading Name {#custom-name}
|
|
@@ -63,8 +64,8 @@ attribute can be used to define a fragment:
|
|
|
63
64
|
[Link](#bookmark)
|
|
64
65
|
```
|
|
65
66
|
|
|
66
|
-
|
|
67
|
-
control over the text of the fragment identifier.
|
|
67
|
+
Using an `a` tag can be useful in scenarios where a heading is not appropriate
|
|
68
|
+
or for control over the text of the fragment identifier.
|
|
68
69
|
|
|
69
70
|
[HTML links to `#top` scroll to the top of a document][html-top-fragment]. This
|
|
70
71
|
rule allows that syntax (using lower-case for consistency):
|
|
@@ -73,16 +74,15 @@ rule allows that syntax (using lower-case for consistency):
|
|
|
73
74
|
[Link](#top)
|
|
74
75
|
```
|
|
75
76
|
|
|
76
|
-
This rule
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
For example, this link to line 20:
|
|
77
|
+
This rule supports the fragment syntax used by GitHub to highlight [specific
|
|
78
|
+
lines/sections of a document][github-linking-to-content]. For example, this link
|
|
79
|
+
to line 20:
|
|
80
80
|
|
|
81
81
|
```markdown
|
|
82
82
|
[Link](#L20)
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-
And this link to content starting within line 19 running
|
|
85
|
+
And this link to content starting within line 19 running partly through line 21:
|
|
86
86
|
|
|
87
87
|
```markdown
|
|
88
88
|
[Link](#L19C5-L21C11)
|
|
@@ -91,8 +91,8 @@ And this link to content starting within line 19 running into line 21:
|
|
|
91
91
|
Some Markdown generators dynamically create and insert headings when building
|
|
92
92
|
documents, for example by combining a fixed prefix like `figure-` and an
|
|
93
93
|
incrementing numeric counter. To ignore such generated fragments, set the
|
|
94
|
-
`ignored_pattern` [regular expression][RegEx] parameter to a pattern
|
|
95
|
-
|
|
94
|
+
`ignored_pattern` [regular expression][RegEx] parameter to a suitable pattern
|
|
95
|
+
(e.g., `^figure-`).
|
|
96
96
|
|
|
97
97
|
Rationale: [GitHub section links][github-section-links] are created
|
|
98
98
|
automatically for every heading when Markdown content is displayed on GitHub.
|
|
@@ -101,17 +101,17 @@ However, section links change if headings are renamed or removed. This rule
|
|
|
101
101
|
helps identify broken section links within a document.
|
|
102
102
|
|
|
103
103
|
Note: Section links are **not** part of the CommonMark specification; this rule
|
|
104
|
-
enforces the
|
|
104
|
+
enforces the GitHub algorithm. Basically:
|
|
105
105
|
|
|
106
106
|
1. Convert text to lowercase
|
|
107
107
|
2. Remove punctuation characters
|
|
108
108
|
3. Convert spaces to dashes
|
|
109
|
-
4.
|
|
110
|
-
5.
|
|
109
|
+
4. Remove HTML comments
|
|
110
|
+
5. Append dash+incrementing integer if needed for uniqueness
|
|
111
|
+
6. [URI-encode][encodeURIComponent] the result
|
|
111
112
|
|
|
112
113
|
[encodeURIComponent]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
|
|
113
114
|
[github-section-links]: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#section-links
|
|
114
|
-
[github-heading-algorithm]: https://github.com/gjtorikian/html-pipeline/blob/f13a1534cb650ba17af400d1acd3a22c28004c09/lib/html/pipeline/toc_filter.rb
|
|
115
115
|
[github-linking-to-content]: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-a-permanent-link-to-a-code-snippet#linking-to-markdown
|
|
116
116
|
[html-top-fragment]: https://html.spec.whatwg.org/multipage/browsing-the-web.html#scrolling-to-a-fragment
|
|
117
117
|
[RegEx]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions
|
package/doc/md055.md
CHANGED
|
@@ -8,15 +8,18 @@ Parameters:
|
|
|
8
8
|
|
|
9
9
|
- `style`: Table pipe style (`string`, default `consistent`, values
|
|
10
10
|
`consistent` / `leading_and_trailing` / `leading_only` /
|
|
11
|
-
`no_leading_or_trailing` / `trailing_only`)
|
|
11
|
+
`no_leading_or_trailing` / `per_table` / `trailing_only`)
|
|
12
12
|
|
|
13
13
|
This rule is triggered when a [GitHub Flavored Markdown table][gfm-table-055]
|
|
14
|
-
is inconsistent
|
|
14
|
+
is inconsistent with its use of leading and trailing pipe characters (`|`).
|
|
15
15
|
|
|
16
16
|
By default (`consistent` style), the header row of the first table in a document
|
|
17
17
|
is used to determine the style that is enforced for every table in the document.
|
|
18
18
|
A specific style can be used instead (`leading_and_trailing`, `leading_only`,
|
|
19
|
-
`no_leading_or_trailing`, `trailing_only`)
|
|
19
|
+
`no_leading_or_trailing`, `trailing_only`) to require all tables in a document
|
|
20
|
+
have the same approach. The style `per_table` can be used to require the rows of
|
|
21
|
+
each table use the same approach (based on its header row) while allowing tables
|
|
22
|
+
in a document to differ from each other.
|
|
20
23
|
|
|
21
24
|
This table's header row has leading and trailing pipes, but its delimiter row is
|
|
22
25
|
missing the trailing pipe and its first row of cells is missing the leading
|
package/doc/md060.md
CHANGED
|
@@ -35,7 +35,8 @@ The `aligned` style ignores cell content, so the following is also valid:
|
|
|
35
35
|
| N | No |
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
Style `compact` avoids extra padding with a single space
|
|
38
|
+
Style `compact` avoids extra padding with a single space before and after cell
|
|
39
|
+
content (or just a single space for cells without content):
|
|
39
40
|
|
|
40
41
|
```markdown
|
|
41
42
|
| Character | Meaning |
|
|
@@ -44,7 +45,7 @@ Style `compact` avoids extra padding with a single space around cell content:
|
|
|
44
45
|
| N | No |
|
|
45
46
|
```
|
|
46
47
|
|
|
47
|
-
Style `tight` uses no padding at all for
|
|
48
|
+
Style `tight` uses no padding at all (for cells with or without content):
|
|
48
49
|
|
|
49
50
|
```markdown
|
|
50
51
|
|Character|Meaning|
|
package/helpers/README.md
CHANGED
|
@@ -22,8 +22,8 @@ be useful to custom rule authors and may avoid duplicating code.
|
|
|
22
22
|
*None* - The entire body of code is tested to 100% coverage by the core
|
|
23
23
|
`markdownlint` project, so there are no additional tests here.
|
|
24
24
|
|
|
25
|
-
[custom-rules]: https://github.com/DavidAnson/markdownlint/blob/v0.
|
|
25
|
+
[custom-rules]: https://github.com/DavidAnson/markdownlint/blob/v0.42.0/doc/CustomRules.md
|
|
26
26
|
[jsdoc]: https://wikipedia.org/wiki/JSDoc
|
|
27
27
|
[markdown]: https://wikipedia.org/wiki/Markdown
|
|
28
28
|
[markdownlint]: https://github.com/DavidAnson/markdownlint
|
|
29
|
-
[rules]: https://github.com/DavidAnson/markdownlint/blob/v0.
|
|
29
|
+
[rules]: https://github.com/DavidAnson/markdownlint/blob/v0.42.0/doc/Rules.md
|
package/helpers/helpers.cjs
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const micromark = require("./micromark-helpers.cjs");
|
|
6
|
-
|
|
7
6
|
const { newlineRe, nextLinesRe } = require("./shared.cjs");
|
|
8
7
|
|
|
9
8
|
module.exports.newLineRe = newlineRe;
|
|
@@ -13,13 +12,14 @@ module.exports.nextLinesRe = nextLinesRe;
|
|
|
13
12
|
/** @typedef {import("../lib/exports.mjs").RuleOnErrorFixInfo} RuleOnErrorFixInfo */
|
|
14
13
|
/** @typedef {import("../lib/exports.mjs").MicromarkToken} MicromarkToken */
|
|
15
14
|
// eslint-disable-next-line jsdoc/valid-types
|
|
16
|
-
/** @typedef {import("micromark-extension-gfm-footnote", { with: { "resolution-mode": "import" } })} */
|
|
15
|
+
/** @typedef {typeof import("micromark-extension-gfm-footnote", { with: { "resolution-mode": "import" } })} _ambient_ */
|
|
17
16
|
// eslint-disable-next-line jsdoc/valid-types
|
|
18
|
-
/** @typedef {import("../lib/micromark-types.d.mts", { with: { "resolution-mode": "import" } })} */
|
|
17
|
+
/** @typedef {typeof import("../lib/micromark-types.d.mts", { with: { "resolution-mode": "import" } })} _ambient_2_ */
|
|
19
18
|
|
|
20
19
|
// Regular expression for matching common front matter (YAML and TOML)
|
|
21
|
-
//
|
|
20
|
+
// Potential for regular expression denial of service is mitigated at point-of-use via "re2js" package
|
|
22
21
|
module.exports.frontMatterRe =
|
|
22
|
+
// eslint-disable-next-line redos/no-vulnerable, unicorn/prefer-unicode-code-point-escapes
|
|
23
23
|
/((^---[^\S\r\n\u2028\u2029]*$[\s\S]+?^---\s*)|(^\+\+\+[^\S\r\n\u2028\u2029]*$[\s\S]+?^(\+\+\+|\.\.\.)\s*)|(^\{[^\S\r\n\u2028\u2029]*$[\s\S]+?^\}\s*))(\r\n|\r|\n|$)/m;
|
|
24
24
|
|
|
25
25
|
// Regular expression for matching the start of inline disable/enable comments
|
|
@@ -42,6 +42,17 @@ module.exports.allPunctuation = allPunctuation;
|
|
|
42
42
|
// All punctuation characters without question mark (normal and full-width)
|
|
43
43
|
module.exports.allPunctuationNoQuestion = allPunctuation.replace(/[??]/gu, "");
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Returns true iff the input is a Boolean.
|
|
47
|
+
*
|
|
48
|
+
* @param {Object} obj Object of unknown type.
|
|
49
|
+
* @returns {boolean} True iff obj is a Boolean.
|
|
50
|
+
*/
|
|
51
|
+
function isBoolean(obj) {
|
|
52
|
+
return typeof obj === "boolean";
|
|
53
|
+
}
|
|
54
|
+
module.exports.isBoolean = isBoolean;
|
|
55
|
+
|
|
45
56
|
/**
|
|
46
57
|
* Returns true iff the input is a Number.
|
|
47
58
|
*
|
|
@@ -177,7 +188,8 @@ const safeCommentCharacter = ".";
|
|
|
177
188
|
const startsWithPipeRe = /^ *\|/;
|
|
178
189
|
const notCrLfRe = /[^\r\n]/g;
|
|
179
190
|
const notSpaceCrLfRe = /[^ \r\n]/g;
|
|
180
|
-
const trailingSpaceRe = / +[\r\n]/g;
|
|
191
|
+
const trailingSpaceRe = /(?<=^|[^ ]) +[\r\n]/g;
|
|
192
|
+
// eslint-disable-next-line unicorn/no-unsafe-string-replacement
|
|
181
193
|
const replaceTrailingSpace = (/** @type {string} */ s) => s.replace(notCrLfRe, safeCommentCharacter);
|
|
182
194
|
module.exports.clearHtmlCommentText = function clearHtmlCommentText(/** @type {string} */ text) {
|
|
183
195
|
let i = 0;
|
|
@@ -207,7 +219,9 @@ module.exports.clearHtmlCommentText = function clearHtmlCommentText(/** @type {s
|
|
|
207
219
|
// If a valid block/inline comment...
|
|
208
220
|
if (isValid) {
|
|
209
221
|
const clearedContent = content
|
|
222
|
+
// eslint-disable-next-line unicorn/no-unsafe-string-replacement
|
|
210
223
|
.replace(notSpaceCrLfRe, safeCommentCharacter)
|
|
224
|
+
// eslint-disable-next-line unicorn/no-unsafe-string-replacement
|
|
211
225
|
.replace(trailingSpaceRe, replaceTrailingSpace);
|
|
212
226
|
text =
|
|
213
227
|
text.slice(0, i + htmlCommentBegin.length) +
|
|
@@ -222,6 +236,7 @@ module.exports.clearHtmlCommentText = function clearHtmlCommentText(/** @type {s
|
|
|
222
236
|
|
|
223
237
|
// Escapes a string for use in a RegExp
|
|
224
238
|
module.exports.escapeForRegExp = function escapeForRegExp(/** @type {string} */ str) {
|
|
239
|
+
// eslint-disable-next-line unicorn/prefer-regexp-escape
|
|
225
240
|
return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
226
241
|
};
|
|
227
242
|
|
|
@@ -552,6 +567,7 @@ module.exports.getPreferredLineEnding = getPreferredLineEnding;
|
|
|
552
567
|
*/
|
|
553
568
|
function expandTildePath(file, os) {
|
|
554
569
|
const homedir = os && os.homedir && os.homedir();
|
|
570
|
+
// eslint-disable-next-line unicorn/no-unsafe-string-replacement
|
|
555
571
|
return homedir ? file.replace(/^~($|\/|\\)/, `${homedir}$1`) : file;
|
|
556
572
|
}
|
|
557
573
|
module.exports.expandTildePath = expandTildePath;
|
|
@@ -630,8 +646,8 @@ function convertLintErrorsVersion2To0(errors) {
|
|
|
630
646
|
function copyAndTransformResults(results, transform) {
|
|
631
647
|
/** @type {Object.<string, LintErrors>} */
|
|
632
648
|
const newResults = {};
|
|
633
|
-
for (const key of Object.
|
|
634
|
-
const arr =
|
|
649
|
+
for (const [ key, value ] of Object.entries(results)) {
|
|
650
|
+
const arr = value.map((r) => ({ ...r }));
|
|
635
651
|
newResults[key] = transform(arr);
|
|
636
652
|
}
|
|
637
653
|
// @ts-ignore
|
|
@@ -8,7 +8,7 @@ const { flatTokensSymbol, htmlFlowSymbol, newlineRe } = require("./shared.cjs");
|
|
|
8
8
|
/** @typedef {import("micromark-util-types", { with: { "resolution-mode": "import" } }).TokenType} TokenType */
|
|
9
9
|
/** @typedef {import("../lib/exports.mjs").MicromarkToken} Token */
|
|
10
10
|
// eslint-disable-next-line jsdoc/valid-types
|
|
11
|
-
/** @typedef {import("../lib/micromark-types.d.mts", { with: { "resolution-mode": "import" } })} */
|
|
11
|
+
/** @typedef {typeof import("../lib/micromark-types.d.mts", { with: { "resolution-mode": "import" } })} _ambient_ */
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Determines if a Micromark token is within an htmlFlow type.
|
|
@@ -17,8 +17,7 @@ const { flatTokensSymbol, htmlFlowSymbol, newlineRe } = require("./shared.cjs");
|
|
|
17
17
|
* @returns {boolean} True iff the token is within an htmlFlow type.
|
|
18
18
|
*/
|
|
19
19
|
function inHtmlFlow(token) {
|
|
20
|
-
|
|
21
|
-
return Boolean(token[htmlFlowSymbol]);
|
|
20
|
+
return Object.hasOwn(token, htmlFlowSymbol);
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
/**
|
|
@@ -132,10 +131,9 @@ function filterByTypes(tokens, types, htmlFlow) {
|
|
|
132
131
|
const flatTokens =
|
|
133
132
|
// @ts-ignore
|
|
134
133
|
tokens[flatTokensSymbol];
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return filterByPredicate(tokens, predicate);
|
|
134
|
+
return flatTokens ?
|
|
135
|
+
flatTokens.filter(predicate) :
|
|
136
|
+
filterByPredicate(tokens, predicate);
|
|
139
137
|
}
|
|
140
138
|
|
|
141
139
|
/**
|
|
@@ -206,10 +204,7 @@ function getHeadingStyle(heading) {
|
|
|
206
204
|
const atxHeadingSequenceLength = heading.children.filter(
|
|
207
205
|
(child) => child.type === "atxHeadingSequence"
|
|
208
206
|
).length;
|
|
209
|
-
|
|
210
|
-
return "atx";
|
|
211
|
-
}
|
|
212
|
-
return "atx_closed";
|
|
207
|
+
return (atxHeadingSequenceLength === 1) ? "atx" : "atx_closed";
|
|
213
208
|
}
|
|
214
209
|
|
|
215
210
|
/**
|
|
@@ -223,7 +218,8 @@ function getHeadingText(heading) {
|
|
|
223
218
|
.flatMap((descendant) => descendant.children.filter((child) => child.type !== "htmlText"))
|
|
224
219
|
.map((data) => data.text)
|
|
225
220
|
.join("")
|
|
226
|
-
.replace(newlineRe, " ")
|
|
221
|
+
.replace(newlineRe, " ")
|
|
222
|
+
.trim();
|
|
227
223
|
}
|
|
228
224
|
|
|
229
225
|
/**
|
package/helpers/package.json
CHANGED
|
@@ -10,11 +10,7 @@
|
|
|
10
10
|
"author": "David Anson (https://dlaa.me/)",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"homepage": "https://github.com/DavidAnson/markdownlint",
|
|
13
|
-
"repository":
|
|
14
|
-
"type": "git",
|
|
15
|
-
"url": "git+https://github.com/DavidAnson/markdownlint.git"
|
|
16
|
-
},
|
|
17
|
-
"bugs": "https://github.com/DavidAnson/markdownlint/issues",
|
|
13
|
+
"repository": "github:DavidAnson/markdownlint",
|
|
18
14
|
"funding": "https://github.com/sponsors/DavidAnson",
|
|
19
15
|
"engines": {
|
|
20
16
|
"node": ">=22"
|
package/helpers/shared.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
|
-
// Symbol for
|
|
5
|
+
// Symbol for identifying the flat tokens array from micromark parse
|
|
6
6
|
module.exports.flatTokensSymbol = Symbol("flat-tokens");
|
|
7
7
|
|
|
8
8
|
// Symbol for identifying the htmlFlow token from micromark parse
|