markdownlint 0.37.3 → 0.38.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 +14 -0
- package/CONTRIBUTING.md +2 -3
- package/README.md +39 -21
- package/doc/Rules.md +158 -35
- package/doc/md027.md +8 -0
- package/doc/md038.md +23 -11
- package/doc/md041.md +31 -16
- package/doc/md043.md +22 -4
- package/doc/md045.md +9 -1
- package/doc/md051.md +17 -0
- package/doc/md052.md +12 -0
- package/doc/md053.md +3 -3
- package/doc/md059.md +30 -0
- package/helpers/README.md +2 -2
- package/helpers/helpers.cjs +4 -6
- package/helpers/micromark-helpers.cjs +29 -3
- package/helpers/package.json +1 -1
- package/lib/cache.mjs +19 -5
- package/lib/configuration-strict.d.ts +190 -126
- package/lib/constants.mjs +1 -1
- package/lib/defer-require.cjs +16 -0
- package/lib/exports.d.mts +2 -0
- package/lib/exports.mjs +2 -0
- package/lib/markdownit.cjs +6 -13
- package/lib/markdownlint.d.mts +36 -2
- package/lib/markdownlint.mjs +314 -292
- package/lib/md025.mjs +23 -15
- package/lib/md027.mjs +11 -1
- package/lib/md036.mjs +12 -2
- package/lib/md038.mjs +52 -71
- package/lib/md039.mjs +3 -22
- package/lib/md041.mjs +54 -16
- package/lib/md043.mjs +2 -0
- package/lib/md045.mjs +3 -1
- package/lib/md051.mjs +13 -5
- package/lib/md052.mjs +2 -1
- package/lib/md059.mjs +71 -0
- package/lib/micromark-parse.mjs +14 -3
- package/lib/node-imports-browser.mjs +0 -2
- package/lib/node-imports-node.mjs +0 -3
- package/lib/parse-configuration.mjs +46 -0
- package/lib/resolve-module.cjs +52 -0
- package/lib/resolve-module.d.cts +34 -0
- package/lib/rules.mjs +3 -1
- package/package.json +30 -27
- package/schema/.markdownlint.jsonc +82 -60
- package/schema/.markdownlint.yaml +74 -56
- package/schema/markdownlint-config-schema-strict.json +259 -144
- package/schema/markdownlint-config-schema.json +259 -144
- package/lib/node-imports-browser-module.cjs +0 -7
package/doc/md041.md
CHANGED
|
@@ -6,44 +6,59 @@ Aliases: `first-line-h1`, `first-line-heading`
|
|
|
6
6
|
|
|
7
7
|
Parameters:
|
|
8
8
|
|
|
9
|
+
- `allow_preamble`: Allow content before first heading (`boolean`, default
|
|
10
|
+
`false`)
|
|
9
11
|
- `front_matter_title`: RegExp for matching title in front matter (`string`,
|
|
10
12
|
default `^\s*title\s*[:=]`)
|
|
11
13
|
- `level`: Heading level (`integer`, default `1`)
|
|
12
14
|
|
|
13
15
|
This rule is intended to ensure documents have a title and is triggered when
|
|
14
|
-
the first line in
|
|
16
|
+
the first line in a document is not a top-level ([HTML][HTML] `h1`) heading:
|
|
15
17
|
|
|
16
18
|
```markdown
|
|
17
|
-
This is a
|
|
19
|
+
This is a document without a heading
|
|
18
20
|
```
|
|
19
21
|
|
|
20
|
-
To fix this, add a top-level heading to the beginning of the
|
|
22
|
+
To fix this, add a top-level heading to the beginning of the document:
|
|
21
23
|
|
|
22
24
|
```markdown
|
|
23
|
-
#
|
|
25
|
+
# Document Heading
|
|
24
26
|
|
|
25
|
-
This is a
|
|
27
|
+
This is a document with a top-level heading
|
|
26
28
|
```
|
|
27
29
|
|
|
28
30
|
Because it is common for projects on GitHub to use an image for the heading of
|
|
29
|
-
`README.md` and that is not well-supported by Markdown, HTML headings
|
|
30
|
-
permitted by this rule. For example:
|
|
31
|
+
`README.md` and that pattern is not well-supported by Markdown, HTML headings
|
|
32
|
+
are also permitted by this rule. For example:
|
|
31
33
|
|
|
32
34
|
```markdown
|
|
33
35
|
<h1 align="center"><img src="https://placekitten.com/300/150"/></h1>
|
|
34
36
|
|
|
35
|
-
This is a
|
|
37
|
+
This is a document with a top-level HTML heading
|
|
36
38
|
```
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
In some cases, a document's title heading may be preceded by text like a table
|
|
41
|
+
of contents. This is not ideal for accessibility, but can be allowed by setting
|
|
42
|
+
the `allow_preamble` parameter to `true`.
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
```markdown
|
|
45
|
+
This is a document with preamble text
|
|
46
|
+
|
|
47
|
+
# Document Heading
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
If [YAML][YAML] front matter is present and contains a `title` property
|
|
51
|
+
(commonly used with blog posts), this rule will not report a violation. To use a
|
|
52
|
+
different property name in the front matter, specify the text of a [regular
|
|
53
|
+
expression][RegExp] via the `front_matter_title` parameter. To disable the use
|
|
54
|
+
of front matter by this rule, specify `""` for `front_matter_title`.
|
|
55
|
+
|
|
56
|
+
The `level` parameter can be used to change the top-level heading (ex: to `h2`)
|
|
57
|
+
in cases where an `h1` is added externally.
|
|
47
58
|
|
|
48
59
|
Rationale: The top-level heading often acts as the title of a document. More
|
|
49
60
|
information: <https://cirosantilli.com/markdown-style-guide#top-level-header>.
|
|
61
|
+
|
|
62
|
+
[HTML]: https://en.wikipedia.org/wiki/HTML
|
|
63
|
+
[RegExp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions
|
|
64
|
+
[YAML]: https://en.wikipedia.org/wiki/YAML
|
package/doc/md043.md
CHANGED
|
@@ -16,7 +16,7 @@ structure for a set of files.
|
|
|
16
16
|
To require exactly the following structure:
|
|
17
17
|
|
|
18
18
|
```markdown
|
|
19
|
-
#
|
|
19
|
+
# Heading
|
|
20
20
|
## Item
|
|
21
21
|
### Detail
|
|
22
22
|
```
|
|
@@ -25,7 +25,7 @@ Set the `headings` parameter to:
|
|
|
25
25
|
|
|
26
26
|
```json
|
|
27
27
|
[
|
|
28
|
-
"#
|
|
28
|
+
"# Heading",
|
|
29
29
|
"## Item",
|
|
30
30
|
"### Detail"
|
|
31
31
|
]
|
|
@@ -34,7 +34,7 @@ Set the `headings` parameter to:
|
|
|
34
34
|
To allow optional headings as with the following structure:
|
|
35
35
|
|
|
36
36
|
```markdown
|
|
37
|
-
#
|
|
37
|
+
# Heading
|
|
38
38
|
## Item
|
|
39
39
|
### Detail (optional)
|
|
40
40
|
## Foot
|
|
@@ -47,7 +47,7 @@ special value `"+"` meaning "one or more unspecified headings" and set the
|
|
|
47
47
|
|
|
48
48
|
```json
|
|
49
49
|
[
|
|
50
|
-
"#
|
|
50
|
+
"# Heading",
|
|
51
51
|
"## Item",
|
|
52
52
|
"*",
|
|
53
53
|
"## Foot",
|
|
@@ -55,6 +55,24 @@ special value `"+"` meaning "one or more unspecified headings" and set the
|
|
|
55
55
|
]
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
+
To allow a single required heading to vary as with a project name:
|
|
59
|
+
|
|
60
|
+
```markdown
|
|
61
|
+
# Project Name
|
|
62
|
+
## Description
|
|
63
|
+
## Examples
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Use the special value `"?"` meaning "exactly one unspecified heading":
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
[
|
|
70
|
+
"?",
|
|
71
|
+
"## Description",
|
|
72
|
+
"## Examples"
|
|
73
|
+
]
|
|
74
|
+
```
|
|
75
|
+
|
|
58
76
|
When an error is detected, this rule outputs the line number of the first
|
|
59
77
|
problematic heading (otherwise, it outputs the last line number of the file).
|
|
60
78
|
|
package/doc/md045.md
CHANGED
|
@@ -4,7 +4,7 @@ Tags: `accessibility`, `images`
|
|
|
4
4
|
|
|
5
5
|
Aliases: `no-alt-text`
|
|
6
6
|
|
|
7
|
-
This rule
|
|
7
|
+
This rule reports a violation when an image is missing alternate text (alt text)
|
|
8
8
|
information.
|
|
9
9
|
|
|
10
10
|
Alternate text is commonly specified inline as:
|
|
@@ -29,12 +29,20 @@ Or with HTML as:
|
|
|
29
29
|
<img src="image.jpg" alt="Alternate text" />
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
+
Note: If the [HTML `aria-hidden` attribute][aria-hidden] is used to hide the
|
|
33
|
+
image from assistive technology, this rule does not report a violation:
|
|
34
|
+
|
|
35
|
+
```html
|
|
36
|
+
<img src="image.jpg" aria-hidden="true" />
|
|
37
|
+
```
|
|
38
|
+
|
|
32
39
|
Guidance for writing alternate text is available from the [W3C][w3c],
|
|
33
40
|
[Wikipedia][wikipedia], and [other locations][phase2technology].
|
|
34
41
|
|
|
35
42
|
Rationale: Alternate text is important for accessibility and describes the
|
|
36
43
|
content of an image for people who may not be able to see it.
|
|
37
44
|
|
|
45
|
+
[aria-hidden]: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-hidden
|
|
38
46
|
[phase2technology]: https://www.phase2technology.com/blog/no-more-excuses
|
|
39
47
|
[w3c]: https://www.w3.org/WAI/alt/
|
|
40
48
|
[wikipedia]: https://en.wikipedia.org/wiki/Alt_attribute
|
package/doc/md051.md
CHANGED
|
@@ -7,6 +7,8 @@ Aliases: `link-fragments`
|
|
|
7
7
|
Parameters:
|
|
8
8
|
|
|
9
9
|
- `ignore_case`: Ignore case of fragments (`boolean`, default `false`)
|
|
10
|
+
- `ignored_pattern`: Pattern for ignoring additional fragments (`string`,
|
|
11
|
+
default ``)
|
|
10
12
|
|
|
11
13
|
Fixable: Some violations can be fixed by tooling
|
|
12
14
|
|
|
@@ -64,6 +66,13 @@ attribute can be used to define a fragment:
|
|
|
64
66
|
An `a` tag can be useful in scenarios where a heading is not appropriate or for
|
|
65
67
|
control over the text of the fragment identifier.
|
|
66
68
|
|
|
69
|
+
[HTML links to `#top` scroll to the top of a document][html-top-fragment]. This
|
|
70
|
+
rule allows that syntax (using lower-case for consistency):
|
|
71
|
+
|
|
72
|
+
```markdown
|
|
73
|
+
[Link](#top)
|
|
74
|
+
```
|
|
75
|
+
|
|
67
76
|
This rule also recognizes the custom fragment syntax used by GitHub to highlight
|
|
68
77
|
[specific content in a document][github-linking-to-content].
|
|
69
78
|
|
|
@@ -79,6 +88,12 @@ And this link to content starting within line 19 running into line 21:
|
|
|
79
88
|
[Link](#L19C5-L21C11)
|
|
80
89
|
```
|
|
81
90
|
|
|
91
|
+
Some Markdown generators dynamically create and insert headings when building
|
|
92
|
+
documents, for example by combining a fixed prefix like `figure-` and an
|
|
93
|
+
incrementing numeric counter. To ignore such generated fragments, set the
|
|
94
|
+
`ignored_pattern` [regular expression][RegEx] parameter to a pattern that
|
|
95
|
+
matches (e.g., `^figure-`).
|
|
96
|
+
|
|
82
97
|
Rationale: [GitHub section links][github-section-links] are created
|
|
83
98
|
automatically for every heading when Markdown content is displayed on GitHub.
|
|
84
99
|
This makes it easy to link directly to different sections within a document.
|
|
@@ -93,3 +108,5 @@ append an incrementing integer as needed for uniqueness.
|
|
|
93
108
|
[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
|
|
94
109
|
[github-heading-algorithm]: https://github.com/gjtorikian/html-pipeline/blob/f13a1534cb650ba17af400d1acd3a22c28004c09/lib/html/pipeline/toc_filter.rb
|
|
95
110
|
[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#linking-to-markdown
|
|
111
|
+
[html-top-fragment]: https://html.spec.whatwg.org/multipage/browsing-the-web.html#scrolling-to-a-fragment
|
|
112
|
+
[RegEx]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions
|
package/doc/md052.md
CHANGED
|
@@ -6,6 +6,7 @@ Aliases: `reference-links-images`
|
|
|
6
6
|
|
|
7
7
|
Parameters:
|
|
8
8
|
|
|
9
|
+
- `ignored_labels`: Ignored link labels (`string[]`, default `["x"]`)
|
|
9
10
|
- `shortcut_syntax`: Include shortcut syntax (`boolean`, default `false`)
|
|
10
11
|
|
|
11
12
|
Links and images in Markdown can provide the link destination or image source
|
|
@@ -38,3 +39,14 @@ so "shortcut" syntax is ignored by default. To include "shortcut" syntax, set
|
|
|
38
39
|
the `include_shortcut` parameter to `true`. Note that doing so produces warnings
|
|
39
40
|
for *all* text in the document that *could* be a shortcut. If bracketed text is
|
|
40
41
|
intentional, brackets can be escaped with the `\` character: `\[example\]`.
|
|
42
|
+
|
|
43
|
+
If there are link labels that are deliberately unreferenced, they can be ignored
|
|
44
|
+
by setting the `ignored_labels` parameter to the list of strings to ignore. The
|
|
45
|
+
default value of this parameter ignores the checkbox syntax used by
|
|
46
|
+
[GitHub Flavored Markdown task list items][gfm-tasklist]:
|
|
47
|
+
|
|
48
|
+
```markdown
|
|
49
|
+
- [x] Checked task list item
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
[gfm-tasklist]: https://github.github.com/gfm/#task-list-items-extension-
|
package/doc/md053.md
CHANGED
|
@@ -29,9 +29,9 @@ reference has the corresponding label. The "full", "collapsed", and "shortcut"
|
|
|
29
29
|
formats are all supported.
|
|
30
30
|
|
|
31
31
|
If there are reference definitions that are deliberately unreferenced, they can
|
|
32
|
-
be ignored by setting the `ignored_definitions` parameter
|
|
33
|
-
this parameter ignores the following convention
|
|
34
|
-
Markdown:
|
|
32
|
+
be ignored by setting the `ignored_definitions` parameter to the list of strings
|
|
33
|
+
to ignore. The default value of this parameter ignores the following convention
|
|
34
|
+
for adding non-HTML comments to Markdown:
|
|
35
35
|
|
|
36
36
|
```markdown
|
|
37
37
|
[//]: # (This behaves like a comment)
|
package/doc/md059.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# `MD059` - Link text should be descriptive
|
|
2
|
+
|
|
3
|
+
Tags: `accessibility`, `links`
|
|
4
|
+
|
|
5
|
+
Aliases: `descriptive-link-text`
|
|
6
|
+
|
|
7
|
+
Parameters:
|
|
8
|
+
|
|
9
|
+
- `prohibited_texts`: Prohibited link texts (`string[]`, default `["click
|
|
10
|
+
here","here","link","more"]`)
|
|
11
|
+
|
|
12
|
+
This rule is triggered when a link has generic text like `[click here](...)` or
|
|
13
|
+
`[link](...)`.
|
|
14
|
+
|
|
15
|
+
Link text should be descriptive and communicate the purpose of the link (e.g.,
|
|
16
|
+
`[Download the budget document](...)` or `[CommonMark Specification](...)`).
|
|
17
|
+
This is especially important for screen readers which sometimes present links
|
|
18
|
+
without context.
|
|
19
|
+
|
|
20
|
+
By default, this rule prohibits a small number of common English words/phrases.
|
|
21
|
+
To customize that list of words/phrases, set the `prohibited_texts` parameter to
|
|
22
|
+
an `Array` of `string`s.
|
|
23
|
+
|
|
24
|
+
Note: For languages other than English, use the `prohibited_texts` parameter to
|
|
25
|
+
customize the list for that language. It is *not* a goal for this rule to have
|
|
26
|
+
translations for every language.
|
|
27
|
+
|
|
28
|
+
Note: This rule checks Markdown links; HTML links are ignored.
|
|
29
|
+
|
|
30
|
+
More information: <https://webaim.org/techniques/hypertext/>
|
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.38.0/doc/CustomRules.md
|
|
26
26
|
[jsdoc]: https://en.m.wikipedia.org/wiki/JSDoc
|
|
27
27
|
[markdown]: https://en.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.38.0/doc/Rules.md
|
package/helpers/helpers.cjs
CHANGED
|
@@ -9,11 +9,8 @@ const { newLineRe, nextLinesRe } = require("./shared.cjs");
|
|
|
9
9
|
module.exports.newLineRe = newLineRe;
|
|
10
10
|
module.exports.nextLinesRe = nextLinesRe;
|
|
11
11
|
|
|
12
|
-
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
|
|
13
12
|
/** @typedef {import("../lib/exports.mjs").RuleOnError} RuleOnError */
|
|
14
|
-
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
|
|
15
13
|
/** @typedef {import("../lib/exports.mjs").RuleOnErrorFixInfo} RuleOnErrorFixInfo */
|
|
16
|
-
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
|
|
17
14
|
/** @typedef {import("../lib/exports.mjs").MicromarkToken} MicromarkToken */
|
|
18
15
|
// eslint-disable-next-line jsdoc/valid-types
|
|
19
16
|
/** @typedef {import("micromark-extension-gfm-footnote", { with: { "resolution-mode": "import" } })} */
|
|
@@ -313,7 +310,7 @@ module.exports.addErrorDetailIf = addErrorDetailIf;
|
|
|
313
310
|
*/
|
|
314
311
|
function addErrorContext(
|
|
315
312
|
onError, lineNumber, context, start, end, range, fixInfo) {
|
|
316
|
-
context = ellipsify(context, start, end);
|
|
313
|
+
context = ellipsify(context.replace(newLineRe, "\n"), start, end);
|
|
317
314
|
addError(onError, lineNumber, undefined, context, range, fixInfo);
|
|
318
315
|
}
|
|
319
316
|
module.exports.addErrorContext = addErrorContext;
|
|
@@ -378,6 +375,7 @@ module.exports.frontMatterHasTitle =
|
|
|
378
375
|
*/
|
|
379
376
|
function getReferenceLinkImageData(tokens) {
|
|
380
377
|
const normalizeReference = (s) => s.toLowerCase().trim().replace(/\s+/g, " ");
|
|
378
|
+
const getText = (t) => t?.children.filter((c) => c.type !== "blockQuotePrefix").map((c) => c.text).join("");
|
|
381
379
|
const references = new Map();
|
|
382
380
|
const shortcuts = new Map();
|
|
383
381
|
const addReferenceToDictionary = (token, label, isShortcut) => {
|
|
@@ -449,7 +447,7 @@ function getReferenceLinkImageData(tokens) {
|
|
|
449
447
|
const isFullOrCollapsed = (token.children.length === 2) && !token.children.some((t) => t.type === "resource");
|
|
450
448
|
const [ labelText ] = micromark.getDescendantsByType(token, [ "label", "labelText" ]);
|
|
451
449
|
const [ referenceString ] = micromark.getDescendantsByType(token, [ "reference", "referenceString" ]);
|
|
452
|
-
let label = labelText
|
|
450
|
+
let label = getText(labelText);
|
|
453
451
|
// Identify if footnote
|
|
454
452
|
if (!isShortcut && !isFullOrCollapsed) {
|
|
455
453
|
const [ footnoteCallMarker, footnoteCallString ] = token.children.filter(
|
|
@@ -462,7 +460,7 @@ function getReferenceLinkImageData(tokens) {
|
|
|
462
460
|
}
|
|
463
461
|
// Track link (handle shortcuts separately due to ambiguity in "text [text] text")
|
|
464
462
|
if (isShortcut || isFullOrCollapsed) {
|
|
465
|
-
addReferenceToDictionary(token, referenceString
|
|
463
|
+
addReferenceToDictionary(token, getText(referenceString) || label, isShortcut);
|
|
466
464
|
}
|
|
467
465
|
}
|
|
468
466
|
break;
|
|
@@ -6,8 +6,9 @@ const { flatTokensSymbol, htmlFlowSymbol } = require("./shared.cjs");
|
|
|
6
6
|
|
|
7
7
|
// eslint-disable-next-line jsdoc/valid-types
|
|
8
8
|
/** @typedef {import("micromark-util-types", { with: { "resolution-mode": "import" } }).TokenType} TokenType */
|
|
9
|
-
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
|
|
10
9
|
/** @typedef {import("../lib/exports.mjs").MicromarkToken} Token */
|
|
10
|
+
// eslint-disable-next-line jsdoc/valid-types
|
|
11
|
+
/** @typedef {import("../lib/micromark-types.d.mts", { with: { "resolution-mode": "import" } })} */
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Determines if a Micromark token is within an htmlFlow type.
|
|
@@ -215,8 +216,12 @@ function getHeadingStyle(heading) {
|
|
|
215
216
|
* @returns {string} Heading text.
|
|
216
217
|
*/
|
|
217
218
|
function getHeadingText(heading) {
|
|
218
|
-
const
|
|
219
|
-
|
|
219
|
+
const headingText = getDescendantsByType(heading, [ [ "atxHeadingText", "setextHeadingText" ] ])
|
|
220
|
+
.flatMap((descendant) => descendant.children.filter((child) => child.type !== "htmlText"))
|
|
221
|
+
.map((data) => data.text)
|
|
222
|
+
.join("")
|
|
223
|
+
.replace(/[\r\n]+/g, " ");
|
|
224
|
+
return headingText || "";
|
|
220
225
|
}
|
|
221
226
|
|
|
222
227
|
/**
|
|
@@ -265,6 +270,26 @@ function getParentOfType(token, types) {
|
|
|
265
270
|
return current;
|
|
266
271
|
}
|
|
267
272
|
|
|
273
|
+
const docfxTabSyntaxRe = /^#tab\//;
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Returns whether the specified Micromark token looks like a Docfx tab.
|
|
277
|
+
*
|
|
278
|
+
* @param {Token | null} heading Micromark token.
|
|
279
|
+
* @returns {boolean} True iff the token looks like a Docfx tab.
|
|
280
|
+
*/
|
|
281
|
+
function isDocfxTab(heading) {
|
|
282
|
+
// See https://dotnet.github.io/docfx/docs/markdown.html?tabs=linux%2Cdotnet#tabs
|
|
283
|
+
if (heading?.type === "atxHeading") {
|
|
284
|
+
const headingTexts = getDescendantsByType(heading, [ "atxHeadingText" ]);
|
|
285
|
+
if ((headingTexts.length === 1) && (headingTexts[0].children.length === 1) && (headingTexts[0].children[0].type === "link")) {
|
|
286
|
+
const resourceDestinationStrings = filterByTypes(headingTexts[0].children[0].children, [ "resourceDestinationString" ]);
|
|
287
|
+
return (resourceDestinationStrings.length === 1) && docfxTabSyntaxRe.test(resourceDestinationStrings[0].text);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
|
|
268
293
|
/**
|
|
269
294
|
* Set containing token types that do not contain content.
|
|
270
295
|
*
|
|
@@ -296,6 +321,7 @@ module.exports = {
|
|
|
296
321
|
getHtmlTagInfo,
|
|
297
322
|
getParentOfType,
|
|
298
323
|
inHtmlFlow,
|
|
324
|
+
isDocfxTab,
|
|
299
325
|
isHtmlFlowComment,
|
|
300
326
|
nonContentTokens
|
|
301
327
|
};
|
package/helpers/package.json
CHANGED
package/lib/cache.mjs
CHANGED
|
@@ -3,14 +3,19 @@
|
|
|
3
3
|
import { getReferenceLinkImageData as helpersGetReferenceLinkImageData } from "../helpers/helpers.cjs";
|
|
4
4
|
import { filterByTypes } from "../helpers/micromark-helpers.cjs";
|
|
5
5
|
|
|
6
|
+
/** @typedef {import("markdownlint").RuleParams} RuleParams */
|
|
7
|
+
/** @typedef {import("markdownlint").MicromarkToken} MicromarkToken */
|
|
8
|
+
/** @typedef {import("markdownlint").MicromarkTokenType} MicromarkTokenType */
|
|
9
|
+
|
|
6
10
|
/** @type {Map<string, object>} */
|
|
7
11
|
const map = new Map();
|
|
12
|
+
/** @type {RuleParams | undefined} */
|
|
8
13
|
let params = undefined;
|
|
9
14
|
|
|
10
15
|
/**
|
|
11
16
|
* Initializes (resets) the cache.
|
|
12
17
|
*
|
|
13
|
-
* @param {
|
|
18
|
+
* @param {RuleParams} [p] Rule parameters object.
|
|
14
19
|
* @returns {void}
|
|
15
20
|
*/
|
|
16
21
|
export function initialize(p) {
|
|
@@ -18,6 +23,15 @@ export function initialize(p) {
|
|
|
18
23
|
params = p;
|
|
19
24
|
}
|
|
20
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Gets the cached Micromark token array (for testing).
|
|
28
|
+
*
|
|
29
|
+
* @returns {MicromarkToken[]} Micromark tokens.
|
|
30
|
+
*/
|
|
31
|
+
export function micromarkTokens() {
|
|
32
|
+
return params?.parsers.micromark.tokens || [];
|
|
33
|
+
}
|
|
34
|
+
|
|
21
35
|
/**
|
|
22
36
|
* Gets a cached object value - computes it and caches it.
|
|
23
37
|
*
|
|
@@ -37,15 +51,15 @@ function getCached(name, getValue) {
|
|
|
37
51
|
/**
|
|
38
52
|
* Filters a list of Micromark tokens by type and caches the result.
|
|
39
53
|
*
|
|
40
|
-
* @param {
|
|
54
|
+
* @param {MicromarkTokenType[]} types Types to allow.
|
|
41
55
|
* @param {boolean} [htmlFlow] Whether to include htmlFlow content.
|
|
42
|
-
* @returns {
|
|
56
|
+
* @returns {MicromarkToken[]} Filtered tokens.
|
|
43
57
|
*/
|
|
44
58
|
export function filterByTypesCached(types, htmlFlow) {
|
|
45
59
|
return getCached(
|
|
46
60
|
// eslint-disable-next-line prefer-rest-params
|
|
47
61
|
JSON.stringify(arguments),
|
|
48
|
-
() => filterByTypes(
|
|
62
|
+
() => filterByTypes(micromarkTokens(), types, htmlFlow)
|
|
49
63
|
);
|
|
50
64
|
}
|
|
51
65
|
|
|
@@ -57,6 +71,6 @@ export function filterByTypesCached(types, htmlFlow) {
|
|
|
57
71
|
export function getReferenceLinkImageData() {
|
|
58
72
|
return getCached(
|
|
59
73
|
getReferenceLinkImageData.name,
|
|
60
|
-
() => helpersGetReferenceLinkImageData(
|
|
74
|
+
() => helpersGetReferenceLinkImageData(micromarkTokens())
|
|
61
75
|
);
|
|
62
76
|
}
|