markdownlint 0.35.0 → 0.36.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.
Files changed (73) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +72 -35
  3. package/demo/markdownlint-browser.js +1259 -1215
  4. package/doc/CustomRules.md +55 -249
  5. package/doc/Rules.md +36 -29
  6. package/doc/md003.md +2 -2
  7. package/doc/md004.md +4 -3
  8. package/doc/md035.md +3 -8
  9. package/doc/md046.md +2 -2
  10. package/doc/md048.md +3 -2
  11. package/doc/md049.md +4 -3
  12. package/doc/md050.md +4 -4
  13. package/doc/md051.md +11 -3
  14. package/doc/md055.md +3 -2
  15. package/helpers/README.md +2 -19
  16. package/helpers/helpers.js +87 -347
  17. package/helpers/micromark-helpers.cjs +296 -0
  18. package/helpers/micromark-parse.cjs +313 -0
  19. package/helpers/package.json +5 -2
  20. package/helpers/shared.js +6 -0
  21. package/helpers/test.cjs +28 -0
  22. package/lib/cache.js +3 -3
  23. package/lib/configuration-strict.d.ts +120 -106
  24. package/lib/constants.js +1 -1
  25. package/lib/markdownit.cjs +172 -0
  26. package/lib/markdownlint.d.ts +41 -3
  27. package/lib/markdownlint.js +153 -115
  28. package/lib/md001.js +1 -1
  29. package/lib/md003.js +1 -1
  30. package/lib/md004.js +3 -3
  31. package/lib/md007.js +3 -3
  32. package/lib/md009.js +1 -1
  33. package/lib/md010.js +18 -14
  34. package/lib/md011.js +24 -23
  35. package/lib/md012.js +1 -1
  36. package/lib/md013.js +1 -1
  37. package/lib/md014.js +5 -9
  38. package/lib/md018.js +1 -1
  39. package/lib/md019-md021.js +1 -1
  40. package/lib/md020.js +2 -2
  41. package/lib/md022.js +9 -15
  42. package/lib/md024.js +1 -1
  43. package/lib/md025.js +1 -1
  44. package/lib/md027.js +2 -2
  45. package/lib/md029.js +3 -3
  46. package/lib/md031.js +8 -6
  47. package/lib/md032.js +27 -15
  48. package/lib/md033.js +1 -1
  49. package/lib/md034.js +21 -29
  50. package/lib/md036.js +18 -24
  51. package/lib/md037.js +1 -1
  52. package/lib/md038.js +9 -14
  53. package/lib/md039.js +13 -15
  54. package/lib/md040.js +11 -13
  55. package/lib/md041.js +4 -4
  56. package/lib/md042.js +2 -6
  57. package/lib/md043.js +1 -1
  58. package/lib/md044.js +31 -28
  59. package/lib/md045.js +2 -2
  60. package/lib/md048.js +28 -17
  61. package/lib/md049-md050.js +20 -5
  62. package/lib/md051.js +16 -18
  63. package/lib/md053.js +5 -4
  64. package/lib/md054.js +11 -13
  65. package/lib/md055.js +39 -46
  66. package/lib/md056.js +31 -36
  67. package/lib/md058.js +29 -14
  68. package/package.json +14 -13
  69. package/schema/.markdownlint.jsonc +55 -52
  70. package/schema/.markdownlint.yaml +54 -52
  71. package/schema/markdownlint-config-schema-strict.json +132 -110
  72. package/schema/markdownlint-config-schema.json +132 -110
  73. package/helpers/micromark.cjs +0 -544
package/lib/md007.js CHANGED
@@ -3,7 +3,7 @@
3
3
  "use strict";
4
4
 
5
5
  const { addErrorDetailIf } = require("../helpers");
6
- const { getTokenParentOfType } = require("../helpers/micromark.cjs");
6
+ const { getParentOfType } = require("../helpers/micromark-helpers.cjs");
7
7
  const { filterByTypesCached } = require("./cache");
8
8
 
9
9
  // eslint-disable-next-line jsdoc/valid-types
@@ -35,11 +35,11 @@ module.exports = {
35
35
  lastBlockQuotePrefix = token;
36
36
  } else if (type === "listUnordered") {
37
37
  let nesting = 0;
38
- /** @type {import("../helpers/micromark.cjs").Token | null} */
38
+ /** @type {import("../helpers/micromark-helpers.cjs").Token | null} */
39
39
  let current = token;
40
40
  while (
41
41
  // @ts-ignore
42
- (current = getTokenParentOfType(current, unorderedParentTypes))
42
+ (current = getParentOfType(current, unorderedParentTypes))
43
43
  ) {
44
44
  if (current.type === "listUnordered") {
45
45
  nesting++;
package/lib/md009.js CHANGED
@@ -3,7 +3,7 @@
3
3
  "use strict";
4
4
 
5
5
  const { addError } = require("../helpers");
6
- const { addRangeToSet } = require("../helpers/micromark.cjs");
6
+ const { addRangeToSet } = require("../helpers/micromark-helpers.cjs");
7
7
  const { filterByTypesCached } = require("./cache");
8
8
 
9
9
  // eslint-disable-next-line jsdoc/valid-types
package/lib/md010.js CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  "use strict";
4
4
 
5
- const { addError, withinAnyRange } = require("../helpers");
6
- const { getDescendantsByType, getExclusionsForToken } = require("../helpers/micromark.cjs");
5
+ const { addError, hasOverlap } = require("../helpers");
6
+ const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
7
7
  const { filterByTypesCached } = require("./cache");
8
8
 
9
9
  const tabRe = /\t+/g;
@@ -26,9 +26,8 @@ module.exports = {
26
26
  const spaceMultiplier = (spacesPerTab === undefined) ?
27
27
  1 :
28
28
  Math.max(0, Number(spacesPerTab));
29
- const exclusions = [];
30
29
  // eslint-disable-next-line jsdoc/valid-types
31
- /** @type import("../helpers/micromark.cjs").TokenType[] */
30
+ /** @type import("../helpers/micromark-helpers.cjs").TokenType[] */
32
31
  const exclusionTypes = [];
33
32
  if (includeCode) {
34
33
  if (ignoreCodeLanguages.size > 0) {
@@ -44,24 +43,29 @@ module.exports = {
44
43
  }
45
44
  return true;
46
45
  });
47
- for (const codeToken of codeTokens) {
48
- const exclusionsForToken = getExclusionsForToken(params.lines, codeToken);
49
- if (codeToken.type === "codeFenced") {
50
- exclusionsForToken.pop();
51
- exclusionsForToken.shift();
52
- }
53
- exclusions.push(...exclusionsForToken);
54
- }
46
+ const codeRanges = codeTokens.map((token) => {
47
+ const { type, startLine, startColumn, endLine, endColumn } = token;
48
+ const codeFenced = (type === "codeFenced");
49
+ return {
50
+ "startLine": startLine + (codeFenced ? 1 : 0),
51
+ "startColumn": codeFenced ? 0 : startColumn,
52
+ "endLine": endLine - (codeFenced ? 1 : 0),
53
+ "endColumn": codeFenced ? Number.MAX_SAFE_INTEGER : endColumn
54
+ };
55
+ });
55
56
  for (let lineIndex = 0; lineIndex < params.lines.length; lineIndex++) {
56
57
  const line = params.lines[lineIndex];
57
58
  let match = null;
58
59
  while ((match = tabRe.exec(line)) !== null) {
60
+ const lineNumber = lineIndex + 1;
59
61
  const column = match.index + 1;
60
62
  const length = match[0].length;
61
- if (!withinAnyRange(exclusions, lineIndex + 1, column, length)) {
63
+ /** @type {import("../helpers").FileRange} */
64
+ const range = { "startLine": lineNumber, "startColumn": column, "endLine": lineNumber, "endColumn": column + length - 1 };
65
+ if (!codeRanges.some((codeRange) => hasOverlap(codeRange, range))) {
62
66
  addError(
63
67
  onError,
64
- lineIndex + 1,
68
+ lineNumber,
65
69
  "Column: " + column,
66
70
  undefined,
67
71
  [ column, length ],
package/lib/md011.js CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  "use strict";
4
4
 
5
- const { addError, withinAnyRange } = require("../helpers");
6
- const { addRangeToSet, getExclusionsForToken } = require("../helpers/micromark.cjs");
5
+ const { addError, hasOverlap } = require("../helpers");
6
+ const { addRangeToSet } = require("../helpers/micromark-helpers.cjs");
7
7
  const { filterByTypesCached } = require("./cache");
8
8
 
9
9
  const reversedLinkRe =
@@ -21,34 +21,35 @@ module.exports = {
21
21
  for (const codeBlock of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
22
22
  addRangeToSet(codeBlockLineNumbers, codeBlock.startLine, codeBlock.endLine);
23
23
  }
24
- const exclusions = [];
25
- for (const codeText of filterByTypesCached([ "codeText" ])) {
26
- exclusions.push(...getExclusionsForToken(params.lines, codeText));
27
- }
24
+ const codeTexts = filterByTypesCached([ "codeText" ]);
28
25
  for (const [ lineIndex, line ] of params.lines.entries()) {
29
- if (!codeBlockLineNumbers.has(lineIndex + 1)) {
26
+ const lineNumber = lineIndex + 1;
27
+ if (!codeBlockLineNumbers.has(lineNumber)) {
30
28
  let match = null;
31
29
  while ((match = reversedLinkRe.exec(line)) !== null) {
32
30
  const [ reversedLink, preChar, linkText, linkDestination ] = match;
33
- const index = match.index + preChar.length;
34
- const length = match[0].length - preChar.length;
35
31
  if (
36
32
  !linkText.endsWith("\\") &&
37
- !linkDestination.endsWith("\\") &&
38
- !withinAnyRange(exclusions, lineIndex + 1, index, length)
33
+ !linkDestination.endsWith("\\")
39
34
  ) {
40
- addError(
41
- onError,
42
- lineIndex + 1,
43
- reversedLink.slice(preChar.length),
44
- undefined,
45
- [ index + 1, length ],
46
- {
47
- "editColumn": index + 1,
48
- "deleteCount": length,
49
- "insertText": `[${linkText}](${linkDestination})`
50
- }
51
- );
35
+ const column = match.index + preChar.length + 1;
36
+ const length = match[0].length - preChar.length;
37
+ /** @type {import("../helpers").FileRange} */
38
+ const range = { "startLine": lineNumber, "startColumn": column, "endLine": lineNumber, "endColumn": column + length - 1 };
39
+ if (!codeTexts.some((codeText) => hasOverlap(codeText, range))) {
40
+ addError(
41
+ onError,
42
+ lineNumber,
43
+ reversedLink.slice(preChar.length),
44
+ undefined,
45
+ [ column, length ],
46
+ {
47
+ "editColumn": column,
48
+ "deleteCount": length,
49
+ "insertText": `[${linkText}](${linkDestination})`
50
+ }
51
+ );
52
+ }
52
53
  }
53
54
  }
54
55
  }
package/lib/md012.js CHANGED
@@ -3,7 +3,7 @@
3
3
  "use strict";
4
4
 
5
5
  const { addErrorDetailIf } = require("../helpers");
6
- const { addRangeToSet } = require("../helpers/micromark.cjs");
6
+ const { addRangeToSet } = require("../helpers/micromark-helpers.cjs");
7
7
  const { filterByTypesCached } = require("./cache");
8
8
 
9
9
  // eslint-disable-next-line jsdoc/valid-types
package/lib/md013.js CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  const { addErrorDetailIf } = require("../helpers");
6
6
  const { getReferenceLinkImageData } = require("./cache");
7
- const { addRangeToSet, getDescendantsByType } = require("../helpers/micromark.cjs");
7
+ const { addRangeToSet, getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
8
8
  const { filterByTypesCached } = require("./cache");
9
9
 
10
10
  const longLineRePrefix = "^.{";
package/lib/md014.js CHANGED
@@ -3,7 +3,6 @@
3
3
  "use strict";
4
4
 
5
5
  const { addErrorContext } = require("../helpers");
6
- const { filterByTypes } = require("../helpers/micromark.cjs");
7
6
  const { filterByTypesCached } = require("./cache");
8
7
 
9
8
  const dollarCommandRe = /^(\s*)(\$\s+)/;
@@ -17,18 +16,15 @@ module.exports = {
17
16
  "parser": "micromark",
18
17
  "function": function MD014(params, onError) {
19
18
  for (const codeBlock of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
20
- const codeFlowValues = filterByTypes(
21
- codeBlock.children,
22
- [ "codeFlowValue" ]
23
- );
24
- const dollarMatches = codeFlowValues.
25
- map((codeFlowValue) => ({
19
+ const codeFlowValues = codeBlock.children.filter((child) => child.type === "codeFlowValue");
20
+ const dollarMatches = codeFlowValues
21
+ .map((codeFlowValue) => ({
26
22
  "result": codeFlowValue.text.match(dollarCommandRe),
27
23
  "startColumn": codeFlowValue.startColumn,
28
24
  "startLine": codeFlowValue.startLine,
29
25
  "text": codeFlowValue.text
30
- })).
31
- filter((dollarMatch) => dollarMatch.result);
26
+ }))
27
+ .filter((dollarMatch) => dollarMatch.result);
32
28
  if (dollarMatches.length === codeFlowValues.length) {
33
29
  for (const dollarMatch of dollarMatches) {
34
30
  // @ts-ignore
package/lib/md018.js CHANGED
@@ -3,7 +3,7 @@
3
3
  "use strict";
4
4
 
5
5
  const { addErrorContext } = require("../helpers");
6
- const { addRangeToSet } = require("../helpers/micromark.cjs");
6
+ const { addRangeToSet } = require("../helpers/micromark-helpers.cjs");
7
7
  const { filterByTypesCached } = require("./cache");
8
8
 
9
9
  // eslint-disable-next-line jsdoc/valid-types
@@ -3,7 +3,7 @@
3
3
  "use strict";
4
4
 
5
5
  const { addErrorContext } = require("../helpers/helpers");
6
- const { getHeadingStyle } = require("../helpers/micromark.cjs");
6
+ const { getHeadingStyle } = require("../helpers/micromark-helpers.cjs");
7
7
  const { filterByTypesCached } = require("./cache");
8
8
 
9
9
  /**
package/lib/md020.js CHANGED
@@ -3,7 +3,7 @@
3
3
  "use strict";
4
4
 
5
5
  const { addErrorContext } = require("../helpers");
6
- const { addRangeToSet } = require("../helpers/micromark.cjs");
6
+ const { addRangeToSet } = require("../helpers/micromark-helpers.cjs");
7
7
  const { filterByTypesCached } = require("./cache");
8
8
 
9
9
  // eslint-disable-next-line jsdoc/valid-types
@@ -22,7 +22,7 @@ module.exports = {
22
22
  for (const [ lineIndex, line ] of lines.entries()) {
23
23
  if (!ignoreBlockLineNumbers.has(lineIndex + 1)) {
24
24
  const match =
25
- /^(#+)([ \t]*)([^#]*?[^#\\])([ \t]*)((?:\\#)?)(#+)(\s*)$/.exec(line);
25
+ /^(#+)([ \t]*)([^# \t\\]|[^# \t][^#]*?[^# \t\\])([ \t]*)((?:\\#)?)(#+)(\s*)$/.exec(line);
26
26
  if (match) {
27
27
  const [
28
28
  ,
package/lib/md022.js CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  "use strict";
4
4
 
5
- const { addErrorDetailIf, blockquotePrefixRe, isBlankLine } = require("../helpers");
6
- const { getHeadingLevel } = require("../helpers/micromark.cjs");
5
+ const { addErrorDetailIf, isBlankLine } = require("../helpers");
6
+ const { getBlockQuotePrefixText, getHeadingLevel } = require("../helpers/micromark-helpers.cjs");
7
7
  const { filterByTypesCached } = require("./cache");
8
8
 
9
9
  const defaultLines = 1;
@@ -21,15 +21,6 @@ const getLinesFunction = (linesParam) => {
21
21
  return () => lines;
22
22
  };
23
23
 
24
- const getBlockQuote = (str, count) => (
25
- (str || "")
26
- .match(blockquotePrefixRe)[0]
27
- .trimEnd()
28
- // eslint-disable-next-line unicorn/prefer-spread
29
- .concat("\n")
30
- .repeat(count)
31
- );
32
-
33
24
  // eslint-disable-next-line jsdoc/valid-types
34
25
  /** @type import("./markdownlint").Rule */
35
26
  module.exports = {
@@ -41,6 +32,7 @@ module.exports = {
41
32
  const getLinesAbove = getLinesFunction(params.config.lines_above);
42
33
  const getLinesBelow = getLinesFunction(params.config.lines_below);
43
34
  const { lines } = params;
35
+ const blockQuotePrefixes = filterByTypesCached([ "blockQuotePrefix", "linePrefix" ]);
44
36
  for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
45
37
  const { startLine, endLine } = heading;
46
38
  const line = lines[startLine - 1].trim();
@@ -65,8 +57,9 @@ module.exports = {
65
57
  line,
66
58
  undefined,
67
59
  {
68
- "insertText": getBlockQuote(
69
- lines[startLine - 2],
60
+ "insertText": getBlockQuotePrefixText(
61
+ blockQuotePrefixes,
62
+ startLine - 1,
70
63
  linesAbove - actualAbove
71
64
  )
72
65
  }
@@ -94,8 +87,9 @@ module.exports = {
94
87
  undefined,
95
88
  {
96
89
  "lineNumber": endLine + 1,
97
- "insertText": getBlockQuote(
98
- lines[endLine],
90
+ "insertText": getBlockQuotePrefixText(
91
+ blockQuotePrefixes,
92
+ endLine + 1,
99
93
  linesBelow - actualBelow
100
94
  )
101
95
  }
package/lib/md024.js CHANGED
@@ -3,7 +3,7 @@
3
3
  "use strict";
4
4
 
5
5
  const { addErrorContext } = require("../helpers");
6
- const { getHeadingLevel, getHeadingText } = require("../helpers/micromark.cjs");
6
+ const { getHeadingLevel, getHeadingText } = require("../helpers/micromark-helpers.cjs");
7
7
  const { filterByTypesCached } = require("./cache");
8
8
 
9
9
  // eslint-disable-next-line jsdoc/valid-types
package/lib/md025.js CHANGED
@@ -3,7 +3,7 @@
3
3
  "use strict";
4
4
 
5
5
  const { addErrorContext, frontMatterHasTitle } = require("../helpers");
6
- const { getHeadingLevel, getHeadingText } = require("../helpers/micromark.cjs");
6
+ const { getHeadingLevel, getHeadingText } = require("../helpers/micromark-helpers.cjs");
7
7
  const { filterByTypesCached } = require("./cache");
8
8
 
9
9
  // eslint-disable-next-line jsdoc/valid-types
package/lib/md027.js CHANGED
@@ -8,9 +8,9 @@ const { filterByTypesCached } = require("./cache");
8
8
  // eslint-disable-next-line jsdoc/valid-types
9
9
  /** @type import("./markdownlint").Rule */
10
10
  module.exports = {
11
- "names": ["MD027", "no-multiple-space-blockquote"],
11
+ "names": [ "MD027", "no-multiple-space-blockquote" ],
12
12
  "description": "Multiple spaces after blockquote symbol",
13
- "tags": ["blockquote", "whitespace", "indentation"],
13
+ "tags": [ "blockquote", "whitespace", "indentation" ],
14
14
  "parser": "micromark",
15
15
  "function": function MD027(params, onError) {
16
16
  for (const token of filterByTypesCached([ "linePrefix" ])) {
package/lib/md029.js CHANGED
@@ -3,7 +3,7 @@
3
3
  "use strict";
4
4
 
5
5
  const { addErrorDetailIf } = require("../helpers");
6
- const { getDescendantsByType, getTokenTextByType } = require("../helpers/micromark.cjs");
6
+ const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
7
7
  const { filterByTypesCached } = require("./cache");
8
8
 
9
9
  const listStyleExamples = {
@@ -15,11 +15,11 @@ const listStyleExamples = {
15
15
  /**
16
16
  * Gets the value of an ordered list item prefix token.
17
17
  *
18
- * @param {import("../helpers/micromark.cjs").Token} listItemPrefix List item prefix token.
18
+ * @param {import("../helpers/micromark-helpers.cjs").Token} listItemPrefix List item prefix token.
19
19
  * @returns {number} List item value.
20
20
  */
21
21
  function getOrderedListItemValue(listItemPrefix) {
22
- return Number(getTokenTextByType(listItemPrefix.children, "listItemValue"));
22
+ return Number(getDescendantsByType(listItemPrefix, [ "listItemValue" ])[0].text);
23
23
  }
24
24
 
25
25
  // eslint-disable-next-line jsdoc/valid-types
package/lib/md031.js CHANGED
@@ -3,7 +3,7 @@
3
3
  "use strict";
4
4
 
5
5
  const { addErrorContext, isBlankLine } = require("../helpers");
6
- const { getTokenParentOfType } = require("../helpers/micromark.cjs");
6
+ const { getParentOfType } = require("../helpers/micromark-helpers.cjs");
7
7
  const { filterByTypesCached } = require("./cache");
8
8
 
9
9
  const codeFencePrefixRe = /^(.*?)[`~]/;
@@ -23,10 +23,12 @@ const codeFencePrefixRe = /^(.*?)[`~]/;
23
23
  function addError(onError, lines, lineNumber, top) {
24
24
  const line = lines[lineNumber - 1];
25
25
  const [ , prefix ] = line.match(codeFencePrefixRe) || [];
26
- const fixInfo = (prefix === undefined) ? null : {
27
- "lineNumber": lineNumber + (top ? 0 : 1),
28
- "insertText": `${prefix.replace(/[^>]/g, " ").trim()}\n`
29
- };
26
+ const fixInfo = (prefix === undefined) ?
27
+ null :
28
+ {
29
+ "lineNumber": lineNumber + (top ? 0 : 1),
30
+ "insertText": `${prefix.replace(/[^>]/g, " ").trim()}\n`
31
+ };
30
32
  addErrorContext(
31
33
  onError,
32
34
  lineNumber,
@@ -50,7 +52,7 @@ module.exports = {
50
52
  const includeListItems = (listItems === undefined) ? true : !!listItems;
51
53
  const { lines } = params;
52
54
  for (const codeBlock of filterByTypesCached([ "codeFenced" ])) {
53
- if (includeListItems || !(getTokenParentOfType(codeBlock, [ "listOrdered", "listUnordered" ]))) {
55
+ if (includeListItems || !(getParentOfType(codeBlock, [ "listOrdered", "listUnordered" ]))) {
54
56
  if (!isBlankLine(lines[codeBlock.startLine - 2])) {
55
57
  addError(onError, lines, codeBlock.startLine, true);
56
58
  }
package/lib/md032.js CHANGED
@@ -2,8 +2,9 @@
2
2
 
3
3
  "use strict";
4
4
 
5
- const { addErrorContextForLine, isBlankLine } = require("../helpers");
6
- const { filterByPredicate, nonContentTokens } = require("../helpers/micromark.cjs");
5
+ const { addErrorContext, isBlankLine } = require("../helpers");
6
+ const { filterByPredicate, getBlockQuotePrefixText, nonContentTokens } = require("../helpers/micromark-helpers.cjs");
7
+ const { filterByTypesCached } = require("./cache");
7
8
 
8
9
  const isList = (token) => (
9
10
  (token.type === "listOrdered") || (token.type === "listUnordered")
@@ -18,6 +19,7 @@ module.exports = {
18
19
  "parser": "micromark",
19
20
  "function": function MD032(params, onError) {
20
21
  const { lines, parsers } = params;
22
+ const blockQuotePrefixes = filterByTypesCached([ "blockQuotePrefix", "linePrefix" ]);
21
23
 
22
24
  // For every top-level list...
23
25
  const topLevelLists = filterByPredicate(
@@ -30,13 +32,18 @@ module.exports = {
30
32
  for (const list of topLevelLists) {
31
33
 
32
34
  // Look for a blank line above the list
33
- const firstIndex = list.startLine - 1;
34
- if (!isBlankLine(lines[firstIndex - 1])) {
35
- addErrorContextForLine(
35
+ const firstLineNumber = list.startLine;
36
+ if (!isBlankLine(lines[firstLineNumber - 2])) {
37
+ addErrorContext(
36
38
  onError,
37
- // @ts-ignore
38
- lines,
39
- firstIndex
39
+ firstLineNumber,
40
+ lines[firstLineNumber - 1].trim(),
41
+ undefined,
42
+ undefined,
43
+ undefined,
44
+ {
45
+ "insertText": getBlockQuotePrefixText(blockQuotePrefixes, firstLineNumber)
46
+ }
40
47
  );
41
48
  }
42
49
 
@@ -51,14 +58,19 @@ module.exports = {
51
58
  }
52
59
 
53
60
  // Look for a blank line below the list
54
- const lastIndex = endLine - 1;
55
- if (!isBlankLine(lines[lastIndex + 1])) {
56
- addErrorContextForLine(
61
+ const lastLineNumber = endLine;
62
+ if (!isBlankLine(lines[lastLineNumber])) {
63
+ addErrorContext(
57
64
  onError,
58
- // @ts-ignore
59
- lines,
60
- lastIndex,
61
- lastIndex + 2
65
+ lastLineNumber,
66
+ lines[lastLineNumber - 1].trim(),
67
+ undefined,
68
+ undefined,
69
+ undefined,
70
+ {
71
+ "lineNumber": lastLineNumber + 1,
72
+ "insertText": getBlockQuotePrefixText(blockQuotePrefixes, lastLineNumber)
73
+ }
62
74
  );
63
75
  }
64
76
  }
package/lib/md033.js CHANGED
@@ -3,7 +3,7 @@
3
3
  "use strict";
4
4
 
5
5
  const { addError, nextLinesRe } = require("../helpers");
6
- const { getHtmlTagInfo } = require("../helpers/micromark.cjs");
6
+ const { getHtmlTagInfo } = require("../helpers/micromark-helpers.cjs");
7
7
  const { filterByTypesCached } = require("./cache");
8
8
 
9
9
  // eslint-disable-next-line jsdoc/valid-types
package/lib/md034.js CHANGED
@@ -3,8 +3,7 @@
3
3
  "use strict";
4
4
 
5
5
  const { addErrorContext } = require("../helpers");
6
- const { filterByPredicate, getHtmlTagInfo, inHtmlFlow, parse } = require("../helpers/micromark.cjs");
7
- const { filterByTypesCached } = require("./cache");
6
+ const { filterByPredicate, getHtmlTagInfo, inHtmlFlow } = require("../helpers/micromark-helpers.cjs");
8
7
 
9
8
  // eslint-disable-next-line jsdoc/valid-types
10
9
  /** @type import("./markdownlint").Rule */
@@ -21,8 +20,6 @@ module.exports = {
21
20
  if ((token.type === "literalAutolink") && !inHtmlFlow(token)) {
22
21
  // Detect and ignore https://github.com/micromark/micromark/issues/164
23
22
  const siblings = token.parent?.children;
24
- // Commented-out due to not being able to exercise in test/code coverage
25
- // || micromarkTokens;
26
23
  const index = siblings?.indexOf(token);
27
24
  // @ts-ignore
28
25
  const prev = siblings?.at(index - 1);
@@ -40,6 +37,7 @@ module.exports = {
40
37
  return false;
41
38
  },
42
39
  (token) => {
40
+ // Ignore content of inline HTML tags
43
41
  const { children } = token;
44
42
  const result = [];
45
43
  for (let i = 0; i < children.length; i++) {
@@ -70,31 +68,25 @@ module.exports = {
70
68
  }
71
69
  )
72
70
  );
73
- const autoLinks = filterByTypesCached([ "literalAutolink" ]);
74
- if (autoLinks.length > 0) {
75
- // Re-parse with correct link/image reference definition handling
76
- const document = params.lines.join("\n");
77
- const tokens = parse(document, undefined, false);
78
- for (const token of literalAutolinks(tokens)) {
79
- const range = [
80
- token.startColumn,
81
- token.endColumn - token.startColumn
82
- ];
83
- const fixInfo = {
84
- "editColumn": range[0],
85
- "deleteCount": range[1],
86
- "insertText": `<${token.text}>`
87
- };
88
- addErrorContext(
89
- onError,
90
- token.startLine,
91
- token.text,
92
- undefined,
93
- undefined,
94
- range,
95
- fixInfo
96
- );
97
- }
71
+ for (const token of literalAutolinks(params.parsers.micromark.tokens)) {
72
+ const range = [
73
+ token.startColumn,
74
+ token.endColumn - token.startColumn
75
+ ];
76
+ const fixInfo = {
77
+ "editColumn": range[0],
78
+ "deleteCount": range[1],
79
+ "insertText": `<${token.text}>`
80
+ };
81
+ addErrorContext(
82
+ onError,
83
+ token.startLine,
84
+ token.text,
85
+ undefined,
86
+ undefined,
87
+ range,
88
+ fixInfo
89
+ );
98
90
  }
99
91
  }
100
92
  };
package/lib/md036.js CHANGED
@@ -3,15 +3,15 @@
3
3
  "use strict";
4
4
 
5
5
  const { addErrorContext, allPunctuation } = require("../helpers");
6
- const { matchAndGetTokensByType } = require("../helpers/micromark.cjs");
6
+ const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
7
7
  const { filterByTypesCached } = require("./cache");
8
8
 
9
- /** @typedef {import("../helpers/micromark.cjs").TokenType} TokenType */
10
- /** @type {Map<TokenType, TokenType[]>} */
11
- const emphasisAndChildrenTypes = new Map([
12
- [ "emphasis", [ "emphasisSequence", "emphasisText", "emphasisSequence" ] ],
13
- [ "strong", [ "strongSequence", "strongText", "strongSequence" ] ]
14
- ]);
9
+ /** @typedef {import("../helpers/micromark-helpers.cjs").TokenType} TokenType */
10
+ /** @type {TokenType[][]} */
11
+ const emphasisTypes = [
12
+ [ "emphasis", "emphasisText" ],
13
+ [ "strong", "strongText" ]
14
+ ];
15
15
 
16
16
  // eslint-disable-next-line jsdoc/valid-types
17
17
  /** @type import("./markdownlint").Rule */
@@ -25,25 +25,19 @@ module.exports = {
25
25
  punctuation = String((punctuation === undefined) ? allPunctuation : punctuation);
26
26
  const punctuationRe = new RegExp("[" + punctuation + "]$");
27
27
  const paragraphTokens =
28
- filterByTypesCached([ "paragraph" ]).
29
- filter((token) =>
28
+ filterByTypesCached([ "paragraph" ])
29
+ .filter((token) =>
30
30
  (token.parent?.type === "content") && !token.parent?.parent && (token.children.length === 1)
31
31
  );
32
- for (const paragraphToken of paragraphTokens) {
33
- const childToken = paragraphToken.children[0];
34
- for (const [ emphasisType, emphasisChildrenTypes ] of emphasisAndChildrenTypes) {
35
- if (childToken.type === emphasisType) {
36
- const matchingTokens = matchAndGetTokensByType(childToken.children, emphasisChildrenTypes);
37
- if (matchingTokens) {
38
- const textToken = matchingTokens[1];
39
- if (
40
- (textToken.children.length === 1) &&
41
- (textToken.children[0].type === "data") &&
42
- !punctuationRe.test(textToken.text)
43
- ) {
44
- addErrorContext(onError, textToken.startLine, textToken.text);
45
- }
46
- }
32
+ for (const emphasisType of emphasisTypes) {
33
+ const textTokens = getDescendantsByType(paragraphTokens, emphasisType);
34
+ for (const textToken of textTokens) {
35
+ if (
36
+ (textToken.children.length === 1) &&
37
+ (textToken.children[0].type === "data") &&
38
+ !punctuationRe.test(textToken.text)
39
+ ) {
40
+ addErrorContext(onError, textToken.startLine, textToken.text);
47
41
  }
48
42
  }
49
43
  }
package/lib/md037.js CHANGED
@@ -3,7 +3,7 @@
3
3
  "use strict";
4
4
 
5
5
  const { addError } = require("../helpers");
6
- const { filterByPredicate, inHtmlFlow } = require("../helpers/micromark.cjs");
6
+ const { filterByPredicate, inHtmlFlow } = require("../helpers/micromark-helpers.cjs");
7
7
 
8
8
  // eslint-disable-next-line jsdoc/valid-types
9
9
  /** @type import("./markdownlint").Rule */