markdownlint 0.36.1 → 0.37.1
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 +11 -0
- package/README.md +70 -117
- package/doc/CustomRules.md +6 -6
- package/helpers/README.md +2 -2
- package/helpers/{helpers.js → helpers.cjs} +15 -6
- package/helpers/micromark-helpers.cjs +5 -3
- package/helpers/package.json +3 -6
- package/lib/{cache.js → cache.mjs} +9 -17
- package/lib/configuration-strict.d.ts +104 -104
- package/lib/configuration.d.ts +1 -1
- package/lib/{constants.js → constants.mjs} +4 -6
- package/lib/exports-async.d.mts +1 -0
- package/lib/exports-async.mjs +3 -0
- package/lib/exports-promise.d.mts +1 -0
- package/lib/exports-promise.mjs +3 -0
- package/lib/exports-sync.d.mts +1 -0
- package/lib/exports-sync.mjs +3 -0
- package/lib/exports.d.mts +28 -0
- package/lib/exports.mjs +31 -0
- package/lib/markdownit.cjs +9 -5
- package/lib/{markdownlint.d.ts → markdownlint.d.mts} +66 -76
- package/lib/{markdownlint.js → markdownlint.mjs} +66 -74
- package/lib/{md001.js → md001.mjs} +5 -8
- package/lib/{md003.js → md003.mjs} +5 -8
- package/lib/{md004.js → md004.mjs} +6 -9
- package/lib/{md005.js → md005.mjs} +4 -7
- package/lib/{md007.js → md007.mjs} +8 -13
- package/lib/{md009.js → md009.mjs} +5 -8
- package/lib/{md010.js → md010.mjs} +7 -11
- package/lib/{md011.js → md011.mjs} +7 -11
- package/lib/{md012.js → md012.mjs} +5 -8
- package/lib/{md013.js → md013.mjs} +8 -9
- package/lib/{md014.js → md014.mjs} +4 -7
- package/lib/{md018.js → md018.mjs} +5 -8
- package/lib/{md019-md021.js → md019-md021.mjs} +7 -10
- package/lib/{md020.js → md020.mjs} +5 -8
- package/lib/{md022.js → md022.mjs} +5 -8
- package/lib/{md023.js → md023.mjs} +4 -7
- package/lib/{md024.js → md024.mjs} +5 -8
- package/lib/{md025.js → md025.mjs} +5 -8
- package/lib/{md026.js → md026.mjs} +5 -8
- package/lib/{md027.js → md027.mjs} +12 -9
- package/lib/{md028.js → md028.mjs} +4 -7
- package/lib/{md029.js → md029.mjs} +6 -9
- package/lib/{md030.js → md030.mjs} +4 -7
- package/lib/{md031.js → md031.mjs} +7 -10
- package/lib/{md032.js → md032.mjs} +5 -8
- package/lib/{md033.js → md033.mjs} +5 -8
- package/lib/{md034.js → md034.mjs} +5 -6
- package/lib/{md035.js → md035.mjs} +4 -7
- package/lib/{md036.js → md036.mjs} +6 -9
- package/lib/{md037.js → md037.mjs} +4 -7
- package/lib/{md038.js → md038.mjs} +5 -8
- package/lib/{md039.js → md039.mjs} +9 -12
- package/lib/{md040.js → md040.mjs} +5 -8
- package/lib/{md041.js → md041.mjs} +4 -8
- package/lib/{md042.js → md042.mjs} +5 -8
- package/lib/{md043.js → md043.mjs} +5 -8
- package/lib/{md044.js → md044.mjs} +8 -11
- package/lib/{md045.js → md045.mjs} +5 -8
- package/lib/{md046.js → md046.mjs} +4 -7
- package/lib/{md047.js → md047.mjs} +3 -6
- package/lib/{md048.js → md048.mjs} +5 -8
- package/lib/{md049-md050.js → md049-md050.mjs} +8 -11
- package/lib/{md051.js → md051.mjs} +8 -12
- package/lib/{md052.js → md052.mjs} +4 -7
- package/lib/{md053.js → md053.mjs} +4 -7
- package/lib/{md054.js → md054.mjs} +5 -8
- package/lib/{md055.js → md055.mjs} +6 -7
- package/lib/{md056.js → md056.mjs} +7 -8
- package/lib/{md058.js → md058.mjs} +6 -7
- package/{helpers/micromark-parse.cjs → lib/micromark-parse.mjs} +29 -33
- package/lib/micromark-types.d.mts +11 -0
- package/lib/node-imports-browser-module.cjs +7 -0
- package/lib/node-imports-browser.mjs +22 -0
- package/lib/node-imports-node.mjs +14 -0
- package/lib/rules.mjs +118 -0
- package/lib/types.d.mts +13 -0
- package/package.json +44 -34
- package/schema/.markdownlint.jsonc +51 -51
- package/schema/.markdownlint.yaml +51 -51
- package/schema/markdownlint-config-schema-strict.json +106 -106
- package/schema/markdownlint-config-schema.json +106 -106
- package/demo/markdownlint-browser.js +0 -7138
- package/helpers/test.cjs +0 -28
- package/lib/rules.js +0 -74
- /package/helpers/{shared.js → shared.cjs} +0 -0
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const { filterByPredicate, filterByTypes } = require("../helpers/micromark-helpers.cjs");
|
|
7
|
-
const { parse } = require("../helpers/micromark-parse.cjs");
|
|
3
|
+
import { addErrorDetailIf, escapeForRegExp, hasOverlap } from "../helpers/helpers.cjs";
|
|
4
|
+
import { filterByPredicate, filterByTypes } from "../helpers/micromark-helpers.cjs";
|
|
5
|
+
import { parse } from "./micromark-parse.mjs";
|
|
8
6
|
|
|
9
7
|
const ignoredChildTypes = new Set(
|
|
10
8
|
[ "codeFencedFence", "definition", "reference", "resource" ]
|
|
11
9
|
);
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
module.exports = {
|
|
11
|
+
/** @type {import("markdownlint").Rule} */
|
|
12
|
+
export default {
|
|
16
13
|
"names": [ "MD044", "proper-names" ],
|
|
17
14
|
"description": "Proper names should have the correct capitalization",
|
|
18
15
|
"tags": [ "spelling" ],
|
|
@@ -48,7 +45,7 @@ module.exports = {
|
|
|
48
45
|
token.children.filter((t) => !ignoredChildTypes.has(t.type))
|
|
49
46
|
)
|
|
50
47
|
);
|
|
51
|
-
/** @type {import("../helpers").FileRange[]} */
|
|
48
|
+
/** @type {import("../helpers/helpers.cjs").FileRange[]} */
|
|
52
49
|
const exclusions = [];
|
|
53
50
|
const scannedTokens = new Set();
|
|
54
51
|
for (const name of names) {
|
|
@@ -64,7 +61,7 @@ module.exports = {
|
|
|
64
61
|
const column = token.startColumn + match.index + leftMatch.length;
|
|
65
62
|
const length = nameMatch.length;
|
|
66
63
|
const lineNumber = token.startLine;
|
|
67
|
-
/** @type {import("../helpers").FileRange} */
|
|
64
|
+
/** @type {import("../helpers/helpers.cjs").FileRange} */
|
|
68
65
|
const nameRange = {
|
|
69
66
|
"startLine": lineNumber,
|
|
70
67
|
"startColumn": column,
|
|
@@ -75,7 +72,7 @@ module.exports = {
|
|
|
75
72
|
!names.includes(nameMatch) &&
|
|
76
73
|
!exclusions.some((exclusion) => hasOverlap(exclusion, nameRange))
|
|
77
74
|
) {
|
|
78
|
-
/** @type {import("../helpers").FileRange[]} */
|
|
75
|
+
/** @type {import("../helpers/helpers.cjs").FileRange[]} */
|
|
79
76
|
let autolinkRanges = [];
|
|
80
77
|
if (!scannedTokens.has(token)) {
|
|
81
78
|
autolinkRanges = filterByTypes(parse(token.text), [ "literalAutolink" ])
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const { getHtmlTagInfo, getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
|
|
7
|
-
const { filterByTypesCached } = require("./cache");
|
|
3
|
+
import { addError, getHtmlAttributeRe, nextLinesRe } from "../helpers/helpers.cjs";
|
|
4
|
+
import { getHtmlTagInfo, getDescendantsByType } from "../helpers/micromark-helpers.cjs";
|
|
5
|
+
import { filterByTypesCached } from "./cache.mjs";
|
|
8
6
|
|
|
9
7
|
const altRe = getHtmlAttributeRe("alt");
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
module.exports = {
|
|
9
|
+
/** @type {import("markdownlint").Rule} */
|
|
10
|
+
export default {
|
|
14
11
|
"names": [ "MD045", "no-alt-text" ],
|
|
15
12
|
"description": "Images should have alternate text (alt text)",
|
|
16
13
|
"tags": [ "accessibility", "images" ],
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const { addErrorDetailIf } = require("../helpers");
|
|
6
|
-
const { filterByTypesCached } = require("./cache");
|
|
3
|
+
import { addErrorDetailIf } from "../helpers/helpers.cjs";
|
|
4
|
+
import { filterByTypesCached } from "./cache.mjs";
|
|
7
5
|
|
|
8
6
|
const tokenTypeToStyle = {
|
|
9
7
|
"codeFenced": "fenced",
|
|
10
8
|
"codeIndented": "indented"
|
|
11
9
|
};
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
module.exports = {
|
|
11
|
+
/** @type {import("markdownlint").Rule} */
|
|
12
|
+
export default {
|
|
16
13
|
"names": [ "MD046", "code-block-style" ],
|
|
17
14
|
"description": "Code block style",
|
|
18
15
|
"tags": [ "code" ],
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { addError, isBlankLine } from "../helpers/helpers.cjs";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// eslint-disable-next-line jsdoc/valid-types
|
|
8
|
-
/** @type import("./markdownlint").Rule */
|
|
9
|
-
module.exports = {
|
|
5
|
+
/** @type {import("markdownlint").Rule} */
|
|
6
|
+
export default {
|
|
10
7
|
"names": [ "MD047", "single-trailing-newline" ],
|
|
11
8
|
"description": "Files should end with a single newline character",
|
|
12
9
|
"tags": [ "blank_lines" ],
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
|
|
7
|
-
const { filterByTypesCached } = require("./cache");
|
|
3
|
+
import { addErrorDetailIf } from "../helpers/helpers.cjs";
|
|
4
|
+
import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
|
|
5
|
+
import { filterByTypesCached } from "./cache.mjs";
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
8
|
* Return the string representation of a fence markup character.
|
|
@@ -21,9 +19,8 @@ function fencedCodeBlockStyleFor(markup) {
|
|
|
21
19
|
}
|
|
22
20
|
};
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
module.exports = {
|
|
22
|
+
/** @type {import("markdownlint").Rule} */
|
|
23
|
+
export default {
|
|
27
24
|
"names": [ "MD048", "code-fence-style" ],
|
|
28
25
|
"description": "Code fence style",
|
|
29
26
|
"tags": [ "code" ],
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const { addError } = require("../helpers");
|
|
6
|
-
const { filterByPredicate, getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
|
|
3
|
+
import { addError } from "../helpers/helpers.cjs";
|
|
4
|
+
import { filterByPredicate, getDescendantsByType } from "../helpers/micromark-helpers.cjs";
|
|
7
5
|
|
|
8
6
|
const intrawordRe = /^\w$/;
|
|
9
7
|
|
|
@@ -23,10 +21,10 @@ function emphasisOrStrongStyleFor(markup) {
|
|
|
23
21
|
};
|
|
24
22
|
|
|
25
23
|
/**
|
|
26
|
-
* @param {import("
|
|
27
|
-
* @param {import("
|
|
28
|
-
* @param {import("
|
|
29
|
-
* @param {import("
|
|
24
|
+
* @param {import("markdownlint").RuleParams} params Rule parameters.
|
|
25
|
+
* @param {import("markdownlint").RuleOnError} onError Error-reporting callback.
|
|
26
|
+
* @param {import("micromark-util-types").TokenType} type Token type.
|
|
27
|
+
* @param {import("micromark-util-types").TokenType} typeSequence Token sequence type.
|
|
30
28
|
* @param {"*" | "**"} asterisk Asterisk kind.
|
|
31
29
|
* @param {"_" | "__"} underline Underline kind.
|
|
32
30
|
* @param {"asterisk" | "consistent" | "underscore"} style Style string.
|
|
@@ -78,9 +76,8 @@ const impl =
|
|
|
78
76
|
}
|
|
79
77
|
};
|
|
80
78
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
module.exports = [
|
|
79
|
+
/** @type {import("markdownlint").Rule[]} */
|
|
80
|
+
export default [
|
|
84
81
|
{
|
|
85
82
|
"names": [ "MD049", "emphasis-style" ],
|
|
86
83
|
"description": "Emphasis style",
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const { filterByPredicate, filterByTypes, getHtmlTagInfo } = require("../helpers/micromark-helpers.cjs");
|
|
7
|
-
const { filterByTypesCached } = require("./cache");
|
|
3
|
+
import { addError, getHtmlAttributeRe } from "../helpers/helpers.cjs";
|
|
4
|
+
import { filterByPredicate, filterByTypes, getHtmlTagInfo } from "../helpers/micromark-helpers.cjs";
|
|
5
|
+
import { filterByTypesCached } from "./cache.mjs";
|
|
8
6
|
|
|
9
7
|
// Regular expression for identifying HTML anchor names
|
|
10
8
|
const idRe = getHtmlAttributeRe("id");
|
|
@@ -22,7 +20,7 @@ const tokensInclude = new Set(
|
|
|
22
20
|
* Converts a Markdown heading into an HTML fragment according to the rules
|
|
23
21
|
* used by GitHub.
|
|
24
22
|
*
|
|
25
|
-
* @param {import("
|
|
23
|
+
* @param {import("markdownlint").MicromarkToken} headingText Heading text token.
|
|
26
24
|
* @returns {string} Fragment string for heading.
|
|
27
25
|
*/
|
|
28
26
|
function convertHeadingToHTMLFragment(headingText) {
|
|
@@ -51,7 +49,7 @@ function convertHeadingToHTMLFragment(headingText) {
|
|
|
51
49
|
/**
|
|
52
50
|
* Unescapes the text of a String-type micromark Token.
|
|
53
51
|
*
|
|
54
|
-
* @param {import("
|
|
52
|
+
* @param {import("markdownlint").MicromarkToken} token String-type micromark Token.
|
|
55
53
|
* @returns {string} Unescaped token text.
|
|
56
54
|
*/
|
|
57
55
|
function unescapeStringTokenText(token) {
|
|
@@ -60,9 +58,8 @@ function unescapeStringTokenText(token) {
|
|
|
60
58
|
.join("");
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
module.exports = {
|
|
61
|
+
/** @type {import("markdownlint").Rule} */
|
|
62
|
+
export default {
|
|
66
63
|
"names": [ "MD051", "link-fragments" ],
|
|
67
64
|
"description": "Link fragments should be valid",
|
|
68
65
|
"tags": [ "links" ],
|
|
@@ -104,8 +101,7 @@ module.exports = {
|
|
|
104
101
|
}
|
|
105
102
|
|
|
106
103
|
// Process link and definition fragments
|
|
107
|
-
|
|
108
|
-
/** @type import("../helpers/micromark-helpers.cjs").TokenType[][] */
|
|
104
|
+
/** @type {import("markdownlint").MicromarkTokenType[][]} */
|
|
109
105
|
const parentChilds = [
|
|
110
106
|
[ "link", "resourceDestinationString" ],
|
|
111
107
|
[ "definition", "definitionDestinationString" ]
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { addError } from "../helpers/helpers.cjs";
|
|
4
|
+
import { getReferenceLinkImageData } from "./cache.mjs";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// eslint-disable-next-line jsdoc/valid-types
|
|
9
|
-
/** @type import("./markdownlint").Rule */
|
|
10
|
-
module.exports = {
|
|
6
|
+
/** @type {import("markdownlint").Rule} */
|
|
7
|
+
export default {
|
|
11
8
|
"names": [ "MD052", "reference-links-images" ],
|
|
12
9
|
"description":
|
|
13
10
|
"Reference links and images should use a label that is defined",
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const { addError, ellipsify } = require("../helpers");
|
|
6
|
-
const { getReferenceLinkImageData } = require("./cache");
|
|
3
|
+
import { addError, ellipsify } from "../helpers/helpers.cjs";
|
|
4
|
+
import { getReferenceLinkImageData } from "./cache.mjs";
|
|
7
5
|
|
|
8
6
|
const linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])\]:/;
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
module.exports = {
|
|
8
|
+
/** @type {import("markdownlint").Rule} */
|
|
9
|
+
export default {
|
|
13
10
|
"names": [ "MD053", "link-image-reference-definitions" ],
|
|
14
11
|
"description": "Link and image reference definitions should be needed",
|
|
15
12
|
"tags": [ "images", "links" ],
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
|
|
7
|
-
const { getReferenceLinkImageData, filterByTypesCached } = require("./cache");
|
|
3
|
+
import { addErrorContext, nextLinesRe } from "../helpers/helpers.cjs";
|
|
4
|
+
import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
|
|
5
|
+
import { getReferenceLinkImageData, filterByTypesCached } from "./cache.mjs";
|
|
8
6
|
|
|
9
7
|
const backslashEscapeRe = /\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g;
|
|
10
8
|
const removeBackslashEscapes = (text) => text.replace(backslashEscapeRe, "$1");
|
|
@@ -20,9 +18,8 @@ const autolinkAble = (destination) => {
|
|
|
20
18
|
return !autolinkDisallowedRe.test(destination);
|
|
21
19
|
};
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
module.exports = {
|
|
21
|
+
/** @type {import("markdownlint").Rule} */
|
|
22
|
+
export default {
|
|
26
23
|
"names": [ "MD054", "link-image-style" ],
|
|
27
24
|
"description": "Link and image style",
|
|
28
25
|
"tags": [ "images", "links" ],
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const { addErrorDetailIf } = require("../helpers");
|
|
6
|
-
const { filterByTypesCached } = require("./cache");
|
|
3
|
+
import { addErrorDetailIf } from "../helpers/helpers.cjs";
|
|
4
|
+
import { filterByTypesCached } from "./cache.mjs";
|
|
7
5
|
|
|
8
6
|
const whitespaceTypes = new Set([ "linePrefix", "whitespace" ]);
|
|
9
7
|
const ignoreWhitespace = (tokens) => tokens.filter(
|
|
@@ -13,9 +11,10 @@ const firstOrNothing = (items) => items[0];
|
|
|
13
11
|
const lastOrNothing = (items) => items[items.length - 1];
|
|
14
12
|
const makeRange = (start, end) => [ start, end - start + 1 ];
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
/** @typedef {import("micromark-extension-gfm-table")} */
|
|
15
|
+
|
|
16
|
+
/** @type {import("markdownlint").Rule} */
|
|
17
|
+
export default {
|
|
19
18
|
"names": [ "MD055", "table-pipe-style" ],
|
|
20
19
|
"description": "Table pipe style",
|
|
21
20
|
"tags": [ "table" ],
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const { getParentOfType } = require("../helpers/micromark-helpers.cjs");
|
|
7
|
-
const { filterByTypesCached } = require("./cache");
|
|
3
|
+
import { addErrorDetailIf } from "../helpers/helpers.cjs";
|
|
4
|
+
import { getParentOfType } from "../helpers/micromark-helpers.cjs";
|
|
5
|
+
import { filterByTypesCached } from "./cache.mjs";
|
|
8
6
|
|
|
9
7
|
const makeRange = (start, end) => [ start, end - start + 1 ];
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
/** @typedef {import("micromark-extension-gfm-table")} */
|
|
10
|
+
|
|
11
|
+
/** @type {import("markdownlint").Rule} */
|
|
12
|
+
export default {
|
|
14
13
|
"names": [ "MD056", "table-column-count" ],
|
|
15
14
|
"description": "Table column count",
|
|
16
15
|
"tags": [ "table" ],
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { addErrorContext, isBlankLine } from "../helpers/helpers.cjs";
|
|
4
|
+
import { getBlockQuotePrefixText } from "../helpers/micromark-helpers.cjs";
|
|
5
|
+
import { filterByTypesCached } from "./cache.mjs";
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
const { getBlockQuotePrefixText } = require("../helpers/micromark-helpers.cjs");
|
|
7
|
-
const { filterByTypesCached } = require("./cache");
|
|
7
|
+
/** @typedef {import("micromark-extension-gfm-table")} */
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
module.exports = {
|
|
9
|
+
/** @type {import("markdownlint").Rule} */
|
|
10
|
+
export default {
|
|
12
11
|
"names": [ "MD058", "blanks-around-tables" ],
|
|
13
12
|
"description": "Tables should be surrounded by blank lines",
|
|
14
13
|
"tags": [ "table" ],
|
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { directive } from "micromark-extension-directive";
|
|
4
|
+
import { gfmAutolinkLiteral } from "micromark-extension-gfm-autolink-literal";
|
|
5
|
+
import { gfmFootnote } from "micromark-extension-gfm-footnote";
|
|
6
|
+
import { gfmTable } from "micromark-extension-gfm-table";
|
|
7
|
+
import { math } from "micromark-extension-math";
|
|
8
|
+
import { parse as micromarkParse, postprocess as micromarkPostprocess, preprocess as micromarkPreprocess } from "micromark";
|
|
9
|
+
// micromark-core-commonmark is not a dependency because this instance must match what's used by micromark
|
|
10
|
+
// eslint-disable-next-line n/no-extraneous-import
|
|
11
|
+
import { labelEnd } from "micromark-core-commonmark";
|
|
12
|
+
import { isHtmlFlowComment } from "../helpers/micromark-helpers.cjs";
|
|
13
|
+
import { flatTokensSymbol, htmlFlowSymbol, newLineRe } from "../helpers/shared.cjs";
|
|
4
14
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/** @typedef {import("
|
|
10
|
-
/** @typedef {import("markdownlint
|
|
11
|
-
/** @typedef {import("
|
|
12
|
-
/** @typedef {import("markdownlint-micromark").State} State */
|
|
13
|
-
/** @typedef {import("markdownlint-micromark").Token} Token */
|
|
14
|
-
/** @typedef {import("markdownlint-micromark").Tokenizer} Tokenizer */
|
|
15
|
-
/** @typedef {import("../lib/markdownlint.js").MicromarkToken} MicromarkToken */
|
|
15
|
+
/** @typedef {import("micromark-util-types").Event} Event */
|
|
16
|
+
/** @typedef {import("micromark-util-types").ParseOptions} MicromarkParseOptions */
|
|
17
|
+
/** @typedef {import("micromark-util-types").State} State */
|
|
18
|
+
/** @typedef {import("micromark-util-types").Token} Token */
|
|
19
|
+
/** @typedef {import("micromark-util-types").Tokenizer} Tokenizer */
|
|
20
|
+
/** @typedef {import("markdownlint").MicromarkToken} MicromarkToken */
|
|
21
|
+
/** @typedef {import("./micromark-types.d.mts")} */
|
|
16
22
|
|
|
17
23
|
/**
|
|
18
24
|
* Parse options.
|
|
@@ -28,27 +34,23 @@ const { flatTokensSymbol, htmlFlowSymbol, newLineRe } = require("./shared.js");
|
|
|
28
34
|
* @param {MicromarkParseOptions} [micromarkParseOptions] Options for micromark.
|
|
29
35
|
* @returns {Event[]} Micromark events.
|
|
30
36
|
*/
|
|
31
|
-
function getEvents(
|
|
37
|
+
export function getEvents(
|
|
32
38
|
markdown,
|
|
33
39
|
micromarkParseOptions = {}
|
|
34
40
|
) {
|
|
35
41
|
// Customize extensions list to add useful extensions
|
|
36
42
|
const extensions = [
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
directive(),
|
|
44
|
+
gfmAutolinkLiteral(),
|
|
45
|
+
gfmFootnote(),
|
|
46
|
+
gfmTable(),
|
|
47
|
+
math(),
|
|
42
48
|
...(micromarkParseOptions.extensions || [])
|
|
43
49
|
];
|
|
44
50
|
|
|
45
51
|
// // Shim labelEnd to identify undefined link labels
|
|
46
52
|
/** @type {Event[][]} */
|
|
47
53
|
const artificialEventLists = [];
|
|
48
|
-
/** @type {Construct} */
|
|
49
|
-
const labelEnd =
|
|
50
|
-
// @ts-ignore
|
|
51
|
-
micromark.labelEnd;
|
|
52
54
|
const tokenizeOriginal = labelEnd.tokenize;
|
|
53
55
|
|
|
54
56
|
/** @type {Tokenizer} */
|
|
@@ -162,9 +164,9 @@ function getEvents(
|
|
|
162
164
|
// Use micromark to parse document into Events
|
|
163
165
|
const encoding = undefined;
|
|
164
166
|
const eol = true;
|
|
165
|
-
const parseContext =
|
|
166
|
-
const chunks =
|
|
167
|
-
const events =
|
|
167
|
+
const parseContext = micromarkParse({ ...micromarkParseOptions, extensions });
|
|
168
|
+
const chunks = micromarkPreprocess()(markdown, encoding, eol);
|
|
169
|
+
const events = micromarkPostprocess(parseContext.document().write(chunks));
|
|
168
170
|
|
|
169
171
|
// Append artificial events and return all events
|
|
170
172
|
// eslint-disable-next-line unicorn/prefer-spread
|
|
@@ -214,8 +216,7 @@ function parseInternal(
|
|
|
214
216
|
};
|
|
215
217
|
const history = [ root ];
|
|
216
218
|
let current = root;
|
|
217
|
-
|
|
218
|
-
/** @type MicromarkParseOptions | null */
|
|
219
|
+
/** @type {MicromarkParseOptions | null} */
|
|
219
220
|
let reparseOptions = null;
|
|
220
221
|
let lines = null;
|
|
221
222
|
let skipHtmlFlowChildren = false;
|
|
@@ -303,11 +304,6 @@ function parseInternal(
|
|
|
303
304
|
* @param {ParseOptions} [parseOptions] Options.
|
|
304
305
|
* @returns {MicromarkToken[]} Micromark tokens.
|
|
305
306
|
*/
|
|
306
|
-
function parse(markdown, parseOptions) {
|
|
307
|
+
export function parse(markdown, parseOptions) {
|
|
307
308
|
return parseInternal(markdown, parseOptions);
|
|
308
309
|
}
|
|
309
|
-
|
|
310
|
-
module.exports = {
|
|
311
|
-
getEvents,
|
|
312
|
-
parse
|
|
313
|
-
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
|
|
3
|
+
// Augment TokenTypeMap with markdownlint-specific types.
|
|
4
|
+
declare module "micromark-util-types" {
|
|
5
|
+
export interface TokenTypeMap {
|
|
6
|
+
undefinedReference: "undefinedReference"
|
|
7
|
+
undefinedReferenceCollapsed: "undefinedReferenceCollapsed"
|
|
8
|
+
undefinedReferenceFull: "undefinedReferenceFull"
|
|
9
|
+
undefinedReferenceShortcut: "undefinedReferenceShortcut"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
const getError = () => new Error("Node APIs are not available in browser context.");
|
|
4
|
+
const throwForSync = () => {
|
|
5
|
+
throw getError();
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const fs = {
|
|
9
|
+
"access": (path, callback) => callback(getError()),
|
|
10
|
+
"accessSync": throwForSync,
|
|
11
|
+
"readFile": (path, options, callback) => callback(getError()),
|
|
12
|
+
"readFileSync": throwForSync
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { default as module } from "./node-imports-browser-module.cjs";
|
|
16
|
+
|
|
17
|
+
export const os = {};
|
|
18
|
+
|
|
19
|
+
export const path = {
|
|
20
|
+
"dirname": throwForSync,
|
|
21
|
+
"resolve": throwForSync
|
|
22
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { access, accessSync, readFile, readFileSync } from "node:fs";
|
|
4
|
+
export const fs = { access, accessSync, readFile, readFileSync };
|
|
5
|
+
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
export const module = { createRequire };
|
|
8
|
+
|
|
9
|
+
import { EOL, homedir } from "node:os";
|
|
10
|
+
export const os = { EOL, homedir };
|
|
11
|
+
|
|
12
|
+
// eslint-disable-next-line unicorn/import-style
|
|
13
|
+
import { dirname, resolve } from "node:path";
|
|
14
|
+
export const path = { dirname, resolve };
|