markdownlint 0.29.0 → 0.30.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.
@@ -1,4 +1,4 @@
1
- /*! markdownlint 0.29.0 https://github.com/DavidAnson/markdownlint @license MIT */
1
+ /*! markdownlint 0.30.0 https://github.com/DavidAnson/markdownlint @license MIT */
2
2
  var markdownlint;
3
3
  /******/ (() => { // webpackBootstrap
4
4
  /******/ var __webpack_modules__ = ({
@@ -36,19 +36,17 @@ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArra
36
36
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
37
37
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
38
38
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
39
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
39
40
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
40
41
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
42
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
41
43
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
42
44
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
43
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
44
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
45
45
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
46
46
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
47
47
  var micromark = __webpack_require__(/*! ./micromark.cjs */ "../helpers/micromark.cjs");
48
-
49
- // Regular expression for matching common newline characters
50
- // See NEWLINES_RE in markdown-it/lib/rules_core/normalize.js
51
- var newLineRe = /\r\n?|\n/g;
48
+ var _require = __webpack_require__(/*! ./shared.js */ "../helpers/shared.js"),
49
+ newLineRe = _require.newLineRe;
52
50
  module.exports.newLineRe = newLineRe;
53
51
 
54
52
  // Regular expression for matching common front matter (YAML and TOML)
@@ -62,17 +60,10 @@ var inlineCommentStartRe =
62
60
  /(<!--\s*markdownlint-(disable|enable|capture|restore|disable-file|enable-file|disable-line|disable-next-line|configure-file))(?:\s|-->)/gi;
63
61
  module.exports.inlineCommentStartRe = inlineCommentStartRe;
64
62
 
65
- // Regular expression for matching HTML elements
66
- var htmlElementRe = /<(([A-Za-z][A-Za-z\d-]*)(?:\s[^`>]*)?)\/?>/g;
67
- module.exports.htmlElementRe = htmlElementRe;
68
-
69
63
  // Regular expressions for range matching
70
64
  module.exports.listItemMarkerRe = /^([\s>]*)(?:[*+-]|\d+[.)])\s+/;
71
65
  module.exports.orderedListItemMarkerRe = /^[\s>]*0*(\d+)[.)]/;
72
66
 
73
- // Regular expression for all instances of emphasis markers
74
- var emphasisMarkersRe = /[_*]/g;
75
-
76
67
  // Regular expression for blockquote prefixes
77
68
  var blockquotePrefixRe = /^[>\s]*/;
78
69
  module.exports.blockquotePrefixRe = blockquotePrefixRe;
@@ -81,6 +72,16 @@ module.exports.blockquotePrefixRe = blockquotePrefixRe;
81
72
  var linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])\]:/;
82
73
  module.exports.linkReferenceDefinitionRe = linkReferenceDefinitionRe;
83
74
 
75
+ // Regular expression for identifying an HTML entity at the end of a line
76
+ module.exports.endOfLineHtmlEntityRe =
77
+ // eslint-disable-next-line max-len
78
+ /&(?:#\d+|#[xX][\da-fA-F]+|[a-zA-Z]{2,31}|blk\d{2}|emsp1[34]|frac\d{2}|sup\d|there4);$/;
79
+
80
+ // Regular expression for identifying a GitHub emoji code at the end of a line
81
+ module.exports.endOfLineGemojiCodeRe =
82
+ // eslint-disable-next-line max-len
83
+ /:(?:[abmovx]|[-+]1|100|1234|(?:1st|2nd|3rd)_place_medal|8ball|clock\d{1,4}|e-mail|non-potable_water|o2|t-rex|u5272|u5408|u55b6|u6307|u6708|u6709|u6e80|u7121|u7533|u7981|u7a7a|[a-z]{2,15}2?|[a-z]{1,14}(?:_[a-z\d]{1,16})+):$/;
84
+
84
85
  // All punctuation characters (normal and full-width)
85
86
  var allPunctuation = ".,;:!?。,;:!?";
86
87
  module.exports.allPunctuation = allPunctuation;
@@ -88,25 +89,82 @@ module.exports.allPunctuation = allPunctuation;
88
89
  // All punctuation characters without question mark (normal and full-width)
89
90
  module.exports.allPunctuationNoQuestion = allPunctuation.replace(/[\?\uFF1F]/g, "");
90
91
 
91
- // Returns true iff the input is a number
92
- module.exports.isNumber = function isNumber(obj) {
92
+ /**
93
+ * Returns true iff the input is a Number.
94
+ *
95
+ * @param {Object} obj Object of unknown type.
96
+ * @returns {boolean} True iff obj is a Number.
97
+ */
98
+ function isNumber(obj) {
93
99
  return typeof obj === "number";
94
- };
100
+ }
101
+ module.exports.isNumber = isNumber;
95
102
 
96
- // Returns true iff the input is a string
97
- module.exports.isString = function isString(obj) {
103
+ /**
104
+ * Returns true iff the input is a String.
105
+ *
106
+ * @param {Object} obj Object of unknown type.
107
+ * @returns {boolean} True iff obj is a String.
108
+ */
109
+ function isString(obj) {
98
110
  return typeof obj === "string";
99
- };
111
+ }
112
+ module.exports.isString = isString;
100
113
 
101
- // Returns true iff the input string is empty
102
- module.exports.isEmptyString = function isEmptyString(str) {
114
+ /**
115
+ * Returns true iff the input String is empty.
116
+ *
117
+ * @param {string} str String of unknown length.
118
+ * @returns {boolean} True iff the input String is empty.
119
+ */
120
+ function isEmptyString(str) {
103
121
  return str.length === 0;
104
- };
122
+ }
123
+ module.exports.isEmptyString = isEmptyString;
105
124
 
106
- // Returns true iff the input is an object
107
- module.exports.isObject = function isObject(obj) {
108
- return obj !== null && _typeof(obj) === "object" && !Array.isArray(obj);
109
- };
125
+ /**
126
+ * Returns true iff the input is an Object.
127
+ *
128
+ * @param {Object} obj Object of unknown type.
129
+ * @returns {boolean} True iff obj is an Object.
130
+ */
131
+ function isObject(obj) {
132
+ return !!obj && _typeof(obj) === "object" && !Array.isArray(obj);
133
+ }
134
+ module.exports.isObject = isObject;
135
+
136
+ /**
137
+ * Returns true iff the input is a URL.
138
+ *
139
+ * @param {Object} obj Object of unknown type.
140
+ * @returns {boolean} True iff obj is a URL.
141
+ */
142
+ function isUrl(obj) {
143
+ return !!obj && Object.getPrototypeOf(obj) === URL.prototype;
144
+ }
145
+ module.exports.isUrl = isUrl;
146
+
147
+ /**
148
+ * Clones the input if it is an Array.
149
+ *
150
+ * @param {Object} arr Object of unknown type.
151
+ * @returns {Object} Clone of obj iff obj is an Array.
152
+ */
153
+ function cloneIfArray(arr) {
154
+ return Array.isArray(arr) ? _toConsumableArray(arr) : arr;
155
+ }
156
+ module.exports.cloneIfArray = cloneIfArray;
157
+
158
+ /**
159
+ * Clones the input if it is a URL.
160
+ *
161
+ * @param {Object} url Object of unknown type.
162
+ * @returns {Object} Clone of obj iff obj is a URL.
163
+ */
164
+ function cloneIfUrl(url) {
165
+ return isUrl(url) ? new URL(url) : url;
166
+ }
167
+ module.exports.cloneIfUrl = cloneIfUrl;
110
168
 
111
169
  /**
112
170
  * Returns true iff the input line is blank (contains nothing, whitespace, or
@@ -315,21 +373,10 @@ function filterTokens(params, type, handler) {
315
373
  }
316
374
  module.exports.filterTokens = filterTokens;
317
375
 
318
- /**
319
- * Returns whether a token is a math block (created by markdown-it-texmath).
320
- *
321
- * @param {Object} token MarkdownItToken instance.
322
- * @returns {boolean} True iff token is a math block.
323
- */
324
- function isMathBlock(token) {
325
- return (token.tag === "$$" || token.tag === "math") && token.type.startsWith("math_block") && !token.type.endsWith("_end");
326
- }
327
- module.exports.isMathBlock = isMathBlock;
328
-
329
376
  // Get line metadata array
330
377
  module.exports.getLineMetadata = function getLineMetadata(params) {
331
378
  var lineMetadata = params.lines.map(function (line, index) {
332
- return [line, index, false, 0, false, false, false, false];
379
+ return [line, index, false, 0, false, false, false];
333
380
  });
334
381
  filterTokens(params, "fence", function (token) {
335
382
  lineMetadata[token.map[0]][3] = 1;
@@ -358,20 +405,6 @@ module.exports.getLineMetadata = function getLineMetadata(params) {
358
405
  filterTokens(params, "hr", function (token) {
359
406
  lineMetadata[token.map[0]][6] = true;
360
407
  });
361
- var _iterator2 = _createForOfIteratorHelper(params.parsers.markdownit.tokens.filter(isMathBlock)),
362
- _step2;
363
- try {
364
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
365
- var token = _step2.value;
366
- for (var i = token.map[0]; i < token.map[1]; i++) {
367
- lineMetadata[i][7] = true;
368
- }
369
- }
370
- } catch (err) {
371
- _iterator2.e(err);
372
- } finally {
373
- _iterator2.f();
374
- }
375
408
  return lineMetadata;
376
409
  };
377
410
 
@@ -380,21 +413,21 @@ module.exports.getLineMetadata = function getLineMetadata(params) {
380
413
  *
381
414
  * @param {Object} lineMetadata Line metadata object.
382
415
  * @param {Function} handler Function taking (line, lineIndex, inCode, onFence,
383
- * inTable, inItem, inBreak, inMath).
416
+ * inTable, inItem, inBreak).
384
417
  * @returns {void}
385
418
  */
386
419
  function forEachLine(lineMetadata, handler) {
387
- var _iterator3 = _createForOfIteratorHelper(lineMetadata),
388
- _step3;
420
+ var _iterator2 = _createForOfIteratorHelper(lineMetadata),
421
+ _step2;
389
422
  try {
390
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
391
- var metadata = _step3.value;
423
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
424
+ var metadata = _step2.value;
392
425
  handler.apply(void 0, _toConsumableArray(metadata));
393
426
  }
394
427
  } catch (err) {
395
- _iterator3.e(err);
428
+ _iterator2.e(err);
396
429
  } finally {
397
- _iterator3.f();
430
+ _iterator2.f();
398
431
  }
399
432
  }
400
433
  module.exports.forEachLine = forEachLine;
@@ -409,11 +442,11 @@ module.exports.flattenLists = function flattenLists(tokens) {
409
442
  var lastWithMap = {
410
443
  "map": [0, 1]
411
444
  };
412
- var _iterator4 = _createForOfIteratorHelper(tokens),
413
- _step4;
445
+ var _iterator3 = _createForOfIteratorHelper(tokens),
446
+ _step3;
414
447
  try {
415
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
416
- var token = _step4.value;
448
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
449
+ var token = _step3.value;
417
450
  if (token.type === "bullet_list_open" || token.type === "ordered_list_open") {
418
451
  // Save current context and start a new one
419
452
  stack.push(current);
@@ -451,49 +484,21 @@ module.exports.flattenLists = function flattenLists(tokens) {
451
484
  }
452
485
  }
453
486
  } catch (err) {
454
- _iterator4.e(err);
487
+ _iterator3.e(err);
455
488
  } finally {
456
- _iterator4.f();
489
+ _iterator3.f();
457
490
  }
458
491
  return flattenedLists;
459
492
  };
460
493
 
461
- /**
462
- * Calls the provided function for each specified inline child token.
463
- *
464
- * @param {Object} params RuleParams instance.
465
- * @param {string} type Token type identifier.
466
- * @param {Function} handler Callback function.
467
- * @returns {void}
468
- */
469
- function forEachInlineChild(params, type, handler) {
470
- filterTokens(params, "inline", function (token) {
471
- var _iterator5 = _createForOfIteratorHelper(token.children.filter(function (c) {
472
- return c.type === type;
473
- })),
474
- _step5;
475
- try {
476
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
477
- var child = _step5.value;
478
- handler(child, token);
479
- }
480
- } catch (err) {
481
- _iterator5.e(err);
482
- } finally {
483
- _iterator5.f();
484
- }
485
- });
486
- }
487
- module.exports.forEachInlineChild = forEachInlineChild;
488
-
489
494
  // Calls the provided function for each heading's content
490
495
  module.exports.forEachHeading = function forEachHeading(params, handler) {
491
496
  var heading = null;
492
- var _iterator6 = _createForOfIteratorHelper(params.parsers.markdownit.tokens),
493
- _step6;
497
+ var _iterator4 = _createForOfIteratorHelper(params.parsers.markdownit.tokens),
498
+ _step4;
494
499
  try {
495
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
496
- var token = _step6.value;
500
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
501
+ var token = _step4.value;
497
502
  if (token.type === "heading_open") {
498
503
  heading = token;
499
504
  } else if (token.type === "heading_close") {
@@ -503,9 +508,9 @@ module.exports.forEachHeading = function forEachHeading(params, handler) {
503
508
  }
504
509
  }
505
510
  } catch (err) {
506
- _iterator6.e(err);
511
+ _iterator4.e(err);
507
512
  } finally {
508
- _iterator6.f();
513
+ _iterator4.f();
509
514
  }
510
515
  };
511
516
 
@@ -640,19 +645,19 @@ module.exports.codeBlockAndSpanRanges = function (params, lineMetadata) {
640
645
  var tokenLines = params.lines.slice(token.map[0], token.map[1]);
641
646
  forEachInlineCodeSpan(tokenLines.join("\n"), function (code, lineIndex, columnIndex) {
642
647
  var codeLines = code.split(newLineRe);
643
- var _iterator7 = _createForOfIteratorHelper(codeLines.entries()),
644
- _step7;
648
+ var _iterator5 = _createForOfIteratorHelper(codeLines.entries()),
649
+ _step5;
645
650
  try {
646
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
647
- var _step7$value = _slicedToArray(_step7.value, 2),
648
- i = _step7$value[0],
649
- line = _step7$value[1];
651
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
652
+ var _step5$value = _slicedToArray(_step5.value, 2),
653
+ i = _step5$value[0],
654
+ line = _step5$value[1];
650
655
  exclusions.push([token.lineNumber - 1 + lineIndex + i, i ? 0 : columnIndex, line.length]);
651
656
  }
652
657
  } catch (err) {
653
- _iterator7.e(err);
658
+ _iterator5.e(err);
654
659
  } finally {
655
- _iterator7.f();
660
+ _iterator5.f();
656
661
  }
657
662
  });
658
663
  }
@@ -660,51 +665,6 @@ module.exports.codeBlockAndSpanRanges = function (params, lineMetadata) {
660
665
  return exclusions;
661
666
  };
662
667
 
663
- /**
664
- * Returns an array of HTML element ranges.
665
- *
666
- * @param {Object} params RuleParams instance.
667
- * @param {Object} lineMetadata Line metadata object.
668
- * @returns {number[][]} Array of ranges (lineIndex, columnIndex, length).
669
- */
670
- module.exports.htmlElementRanges = function (params, lineMetadata) {
671
- var exclusions = [];
672
- // Match with htmlElementRe
673
- forEachLine(lineMetadata, function (line, lineIndex, inCode) {
674
- var match = null;
675
- // eslint-disable-next-line no-unmodified-loop-condition
676
- while (!inCode && (match = htmlElementRe.exec(line)) !== null) {
677
- exclusions.push([lineIndex, match.index, match[0].length]);
678
- }
679
- });
680
- // Match with html_inline
681
- forEachInlineChild(params, "html_inline", function (token, parent) {
682
- var parentContent = parent.content;
683
- var tokenContent = token.content;
684
- var parentIndex = parentContent.indexOf(tokenContent);
685
- var deltaLines = 0;
686
- var indent = 0;
687
- for (var i = parentIndex - 1; i >= 0; i--) {
688
- if (parentContent[i] === "\n") {
689
- deltaLines++;
690
- } else if (deltaLines === 0) {
691
- indent++;
692
- }
693
- }
694
- var lineIndex = token.lineNumber - 1 + deltaLines;
695
- do {
696
- var index = tokenContent.indexOf("\n");
697
- var length = index === -1 ? tokenContent.length : index;
698
- exclusions.push([lineIndex, indent, length]);
699
- tokenContent = tokenContent.slice(length + 1);
700
- lineIndex++;
701
- indent = 0;
702
- } while (tokenContent.length > 0);
703
- });
704
- // Return results
705
- return exclusions;
706
- };
707
-
708
668
  /**
709
669
  * Determines whether the specified range is within another range.
710
670
  *
@@ -742,155 +702,6 @@ module.exports.frontMatterHasTitle = function frontMatterHasTitle(frontMatterLin
742
702
  });
743
703
  };
744
704
 
745
- /**
746
- * Calls the provided function for each link.
747
- *
748
- * @param {string} line Line of Markdown input.
749
- * @param {Function} handler Function taking (index, link, text, destination).
750
- * @returns {void}
751
- */
752
- function forEachLink(line, handler) {
753
- // Helper to find matching close symbol for link text/destination
754
- var findClosingSymbol = function findClosingSymbol(index) {
755
- var begin = line[index];
756
- var end = begin === "[" ? "]" : ")";
757
- var nesting = 0;
758
- var escaping = false;
759
- var pointy = false;
760
- for (var i = index + 1; i < line.length; i++) {
761
- var current = line[i];
762
- if (current === "\\") {
763
- escaping = !escaping;
764
- } else if (!escaping && current === begin) {
765
- nesting++;
766
- } else if (!escaping && current === end) {
767
- if (nesting > 0) {
768
- nesting--;
769
- } else if (!pointy) {
770
- // Return index after matching close symbol
771
- return i + 1;
772
- }
773
- } else if (i === index + 1 && begin === "(" && current === "<") {
774
- pointy = true;
775
- } else if (!escaping && pointy && current === ">") {
776
- pointy = false;
777
- nesting = 0;
778
- } else {
779
- escaping = false;
780
- }
781
- }
782
- // No match found
783
- return -1;
784
- };
785
- // Scan line for unescaped "[" character
786
- var escaping = false;
787
- for (var i = 0; i < line.length; i++) {
788
- var current = line[i];
789
- if (current === "\\") {
790
- escaping = !escaping;
791
- } else if (!escaping && current === "[") {
792
- // Scan for matching close "]" of link text
793
- var textEnd = findClosingSymbol(i);
794
- if (textEnd !== -1) {
795
- if (line[textEnd] === "(" || line[textEnd] === "[") {
796
- // Scan for matching close ")" or "]" of link destination
797
- var destEnd = findClosingSymbol(textEnd);
798
- if (destEnd !== -1) {
799
- // Call handler with link text and destination
800
- var link = line.slice(i, destEnd);
801
- var text = line.slice(i, textEnd);
802
- var dest = line.slice(textEnd, destEnd);
803
- handler(i, link, text, dest);
804
- i = destEnd;
805
- }
806
- }
807
- if (i < textEnd) {
808
- // Call handler with link text only
809
- var _text = line.slice(i, textEnd);
810
- handler(i, _text, _text);
811
- i = textEnd;
812
- }
813
- }
814
- } else {
815
- escaping = false;
816
- }
817
- }
818
- }
819
- module.exports.forEachLink = forEachLink;
820
-
821
- /**
822
- * Returns a list of emphasis markers in code spans and links.
823
- *
824
- * @param {Object} params RuleParams instance.
825
- * @returns {number[][]} List of markers.
826
- */
827
- function emphasisMarkersInContent(params) {
828
- var lines = params.lines;
829
- var byLine = new Array(lines.length);
830
- // Search links
831
- var _iterator8 = _createForOfIteratorHelper(lines.entries()),
832
- _step8;
833
- try {
834
- var _loop = function _loop() {
835
- var _step8$value = _slicedToArray(_step8.value, 2),
836
- tokenLineIndex = _step8$value[0],
837
- tokenLine = _step8$value[1];
838
- var inLine = [];
839
- forEachLink(tokenLine, function (index, match) {
840
- var markerMatch = null;
841
- while (markerMatch = emphasisMarkersRe.exec(match)) {
842
- inLine.push(index + markerMatch.index);
843
- }
844
- });
845
- byLine[tokenLineIndex] = inLine;
846
- };
847
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
848
- _loop();
849
- }
850
- // Search code spans
851
- } catch (err) {
852
- _iterator8.e(err);
853
- } finally {
854
- _iterator8.f();
855
- }
856
- filterTokens(params, "inline", function (token) {
857
- var children = token.children,
858
- lineNumber = token.lineNumber,
859
- map = token.map;
860
- if (children.some(function (child) {
861
- return child.type === "code_inline";
862
- })) {
863
- var tokenLines = lines.slice(map[0], map[1]);
864
- forEachInlineCodeSpan(tokenLines.join("\n"), function (code, lineIndex, column, tickCount) {
865
- var codeLines = code.split(newLineRe);
866
- var _iterator9 = _createForOfIteratorHelper(codeLines.entries()),
867
- _step9;
868
- try {
869
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
870
- var _step9$value = _slicedToArray(_step9.value, 2),
871
- codeLineIndex = _step9$value[0],
872
- codeLine = _step9$value[1];
873
- var byLineIndex = lineNumber - 1 + lineIndex + codeLineIndex;
874
- var inLine = byLine[byLineIndex];
875
- var codeLineOffset = codeLineIndex ? 0 : column - 1 + tickCount;
876
- var match = null;
877
- while (match = emphasisMarkersRe.exec(codeLine)) {
878
- inLine.push(codeLineOffset + match.index);
879
- }
880
- byLine[byLineIndex] = inLine;
881
- }
882
- } catch (err) {
883
- _iterator9.e(err);
884
- } finally {
885
- _iterator9.f();
886
- }
887
- });
888
- }
889
- });
890
- return byLine;
891
- }
892
- module.exports.emphasisMarkersInContent = emphasisMarkersInContent;
893
-
894
705
  /**
895
706
  * Returns an object with information about reference links and images.
896
707
  *
@@ -913,11 +724,11 @@ function getReferenceLinkImageData(params) {
913
724
  "definitionLabelString", "gfmFootnoteDefinitionLabelString",
914
725
  // references and shortcuts
915
726
  "gfmFootnoteCall", "image", "link"]);
916
- var _iterator10 = _createForOfIteratorHelper(filteredTokens),
917
- _step10;
727
+ var _iterator6 = _createForOfIteratorHelper(filteredTokens),
728
+ _step6;
918
729
  try {
919
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
920
- var token = _step10.value;
730
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
731
+ var token = _step6.value;
921
732
  var labelPrefix = "";
922
733
  // eslint-disable-next-line default-case
923
734
  switch (token.type) {
@@ -984,9 +795,9 @@ function getReferenceLinkImageData(params) {
984
795
  }
985
796
  }
986
797
  } catch (err) {
987
- _iterator10.e(err);
798
+ _iterator6.e(err);
988
799
  } finally {
989
- _iterator10.f();
800
+ _iterator6.f();
990
801
  }
991
802
  return {
992
803
  references: references,
@@ -1010,11 +821,11 @@ function getPreferredLineEnding(input, os) {
1010
821
  var lf = 0;
1011
822
  var crlf = 0;
1012
823
  var endings = input.match(newLineRe) || [];
1013
- var _iterator11 = _createForOfIteratorHelper(endings),
1014
- _step11;
824
+ var _iterator7 = _createForOfIteratorHelper(endings),
825
+ _step7;
1015
826
  try {
1016
- for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
1017
- var ending = _step11.value;
827
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
828
+ var ending = _step7.value;
1018
829
  // eslint-disable-next-line default-case
1019
830
  switch (ending) {
1020
831
  case "\r":
@@ -1029,9 +840,9 @@ function getPreferredLineEnding(input, os) {
1029
840
  }
1030
841
  }
1031
842
  } catch (err) {
1032
- _iterator11.e(err);
843
+ _iterator7.e(err);
1033
844
  } finally {
1034
- _iterator11.f();
845
+ _iterator7.f();
1035
846
  }
1036
847
  var preferredLineEnding = null;
1037
848
  if (!cr && !lf && !crlf) {
@@ -1114,11 +925,11 @@ function applyFixes(input, errors) {
1114
925
  lastFixInfo = {
1115
926
  "lineNumber": -1
1116
927
  };
1117
- var _iterator12 = _createForOfIteratorHelper(fixInfos),
1118
- _step12;
928
+ var _iterator8 = _createForOfIteratorHelper(fixInfos),
929
+ _step8;
1119
930
  try {
1120
- for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
1121
- var fixInfo = _step12.value;
931
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
932
+ var fixInfo = _step8.value;
1122
933
  if (fixInfo.lineNumber === lastFixInfo.lineNumber && fixInfo.editColumn === lastFixInfo.editColumn && !fixInfo.insertText && fixInfo.deleteCount > 0 && lastFixInfo.insertText && !lastFixInfo.deleteCount) {
1123
934
  fixInfo.insertText = lastFixInfo.insertText;
1124
935
  lastFixInfo.lineNumber = 0;
@@ -1126,9 +937,9 @@ function applyFixes(input, errors) {
1126
937
  lastFixInfo = fixInfo;
1127
938
  }
1128
939
  } catch (err) {
1129
- _iterator12.e(err);
940
+ _iterator8.e(err);
1130
941
  } finally {
1131
- _iterator12.f();
942
+ _iterator8.f();
1132
943
  }
1133
944
  fixInfos = fixInfos.filter(function (fixInfo) {
1134
945
  return fixInfo.lineNumber;
@@ -1136,11 +947,11 @@ function applyFixes(input, errors) {
1136
947
  // Apply all (remaining/updated) fixes
1137
948
  var lastLineIndex = -1;
1138
949
  var lastEditIndex = -1;
1139
- var _iterator13 = _createForOfIteratorHelper(fixInfos),
1140
- _step13;
950
+ var _iterator9 = _createForOfIteratorHelper(fixInfos),
951
+ _step9;
1141
952
  try {
1142
- for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
1143
- var _fixInfo = _step13.value;
953
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
954
+ var _fixInfo = _step9.value;
1144
955
  var lineNumber = _fixInfo.lineNumber,
1145
956
  editColumn = _fixInfo.editColumn,
1146
957
  deleteCount = _fixInfo.deleteCount;
@@ -1155,9 +966,9 @@ function applyFixes(input, errors) {
1155
966
  }
1156
967
  // Return corrected input
1157
968
  } catch (err) {
1158
- _iterator13.e(err);
969
+ _iterator9.e(err);
1159
970
  } finally {
1160
- _iterator13.f();
971
+ _iterator9.f();
1161
972
  }
1162
973
  return lines.filter(function (line) {
1163
974
  return line !== null;
@@ -1180,6 +991,23 @@ module.exports.expandTildePath = expandTildePath;
1180
991
 
1181
992
  /***/ }),
1182
993
 
994
+ /***/ "../helpers/shared.js":
995
+ /*!****************************!*\
996
+ !*** ../helpers/shared.js ***!
997
+ \****************************/
998
+ /***/ ((module) => {
999
+
1000
+ "use strict";
1001
+ // @ts-check
1002
+
1003
+
1004
+
1005
+ // Regular expression for matching common newline characters
1006
+ // See NEWLINES_RE in markdown-it/lib/rules_core/normalize.js
1007
+ module.exports.newLineRe = /\r\n?|\n/g;
1008
+
1009
+ /***/ }),
1010
+
1183
1011
  /***/ "markdown-it":
1184
1012
  /*!*****************************!*\
1185
1013
  !*** external "markdownit" ***!
@@ -1282,10 +1110,16 @@ module.exports = {
1282
1110
 
1283
1111
 
1284
1112
  // @ts-ignore
1113
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
1285
1114
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
1286
1115
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
1287
1116
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
1288
1117
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
1118
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
1119
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
1120
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
1121
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
1122
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
1289
1123
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
1290
1124
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
1291
1125
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
@@ -1297,9 +1131,12 @@ var _require = __webpack_require__(/*! markdownlint-micromark */ "markdownlint-m
1297
1131
  gfmAutolinkLiteral = _require.gfmAutolinkLiteral,
1298
1132
  gfmFootnote = _require.gfmFootnote,
1299
1133
  gfmTable = _require.gfmTable,
1134
+ math = _require.math,
1300
1135
  parse = _require.parse,
1301
1136
  postprocess = _require.postprocess,
1302
1137
  preprocess = _require.preprocess;
1138
+ var _require2 = __webpack_require__(/*! ./shared.js */ "../helpers/shared.js"),
1139
+ newLineRe = _require2.newLineRe;
1303
1140
 
1304
1141
  /**
1305
1142
  * Markdown token.
@@ -1312,28 +1149,29 @@ var _require = __webpack_require__(/*! markdownlint-micromark */ "markdownlint-m
1312
1149
  * @property {number} endColumn End column (1-based).
1313
1150
  * @property {string} text Token text.
1314
1151
  * @property {Token[]} children Child tokens.
1152
+ * @property {Token[]} [htmlFlowChildren] Child tokens for htmlFlow.
1315
1153
  */
1316
1154
 
1317
1155
  /**
1318
1156
  * Parses a Markdown document and returns Micromark events.
1319
1157
  *
1320
1158
  * @param {string} markdown Markdown document.
1321
- * @param {Object} [options] Options for micromark.
1322
- * @param {boolean} [refsDefined] Whether to treat references as defined.
1159
+ * @param {Object} [micromarkOptions] Options for micromark.
1160
+ * @param {boolean} [referencesDefined] Treat references as defined.
1323
1161
  * @returns {Object[]} Micromark events.
1324
1162
  */
1325
1163
  function getMicromarkEvents(markdown) {
1326
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1327
- var refsDefined = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
1164
+ var micromarkOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1165
+ var referencesDefined = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
1328
1166
  // Customize options object to add useful extensions
1329
- options.extensions = options.extensions || [];
1330
- options.extensions.push(gfmAutolinkLiteral, gfmFootnote(), gfmTable);
1167
+ micromarkOptions.extensions = micromarkOptions.extensions || [];
1168
+ micromarkOptions.extensions.push(gfmAutolinkLiteral(), gfmFootnote(), gfmTable(), math());
1331
1169
 
1332
1170
  // Use micromark to parse document into Events
1333
1171
  var encoding = undefined;
1334
1172
  var eol = true;
1335
- var parseContext = parse(options);
1336
- if (refsDefined) {
1173
+ var parseContext = parse(micromarkOptions);
1174
+ if (referencesDefined) {
1337
1175
  // Customize ParseContext to treat all references as defined
1338
1176
  parseContext.defined.includes = function (searchElement) {
1339
1177
  return searchElement.length > 0;
@@ -1348,15 +1186,14 @@ function getMicromarkEvents(markdown) {
1348
1186
  * Parses a Markdown document and returns (frozen) tokens.
1349
1187
  *
1350
1188
  * @param {string} markdown Markdown document.
1351
- * @param {Object} [options] Options for micromark.
1352
- * @param {boolean} [refsDefined] Whether to treat references as defined.
1189
+ * @param {Object} micromarkOptions Options for micromark.
1190
+ * @param {boolean} referencesDefined Treat references as defined.
1191
+ * @param {number} lineDelta Offset to apply to start/end line.
1353
1192
  * @returns {Token[]} Micromark tokens (frozen).
1354
1193
  */
1355
- function micromarkParse(markdown) {
1356
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1357
- var refsDefined = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
1194
+ function micromarkParseWithOffset(markdown, micromarkOptions, referencesDefined, lineDelta) {
1358
1195
  // Use micromark to parse document into Events
1359
- var events = getMicromarkEvents(markdown, options, refsDefined);
1196
+ var events = getMicromarkEvents(markdown, micromarkOptions, referencesDefined);
1360
1197
 
1361
1198
  // Create Token objects
1362
1199
  var document = [];
@@ -1364,6 +1201,8 @@ function micromarkParse(markdown) {
1364
1201
  "children": document
1365
1202
  };
1366
1203
  var history = [current];
1204
+ var reparseOptions = null;
1205
+ var lines = null;
1367
1206
  var _iterator = _createForOfIteratorHelper(events),
1368
1207
  _step;
1369
1208
  try {
@@ -1386,13 +1225,27 @@ function micromarkParse(markdown) {
1386
1225
  history.push(previous);
1387
1226
  current = {
1388
1227
  type: type,
1389
- startLine: startLine,
1228
+ "startLine": startLine + lineDelta,
1390
1229
  startColumn: startColumn,
1391
- endLine: endLine,
1230
+ "endLine": endLine + lineDelta,
1392
1231
  endColumn: endColumn,
1393
1232
  text: text,
1394
1233
  "children": []
1395
1234
  };
1235
+ if (current.type === "htmlFlow") {
1236
+ if (!reparseOptions || !lines) {
1237
+ reparseOptions = _objectSpread(_objectSpread({}, micromarkOptions), {}, {
1238
+ "extensions": [{
1239
+ "disable": {
1240
+ "null": ["codeIndented", "htmlFlow"]
1241
+ }
1242
+ }]
1243
+ });
1244
+ lines = markdown.split(newLineRe);
1245
+ }
1246
+ var reparseMarkdown = lines.slice(current.startLine - 1, current.endLine).join("\n");
1247
+ current.htmlFlowChildren = micromarkParseWithOffset(reparseMarkdown, reparseOptions, referencesDefined, current.startLine - 1);
1248
+ }
1396
1249
  previous.children.push(current);
1397
1250
  } else if (kind === "exit") {
1398
1251
  Object.freeze(current.children);
@@ -1412,24 +1265,19 @@ function micromarkParse(markdown) {
1412
1265
  return document;
1413
1266
  }
1414
1267
 
1415
- // /**
1416
- // * Log the structure of a Micromark token list.
1417
- // *
1418
- // * @param {Token[]} tokens Micromark tokens.
1419
- // * @param {number} depth Tree depth.
1420
- // * @returns {void}
1421
- // */
1422
- // function consoleLogTokens(tokens, depth = 0) {
1423
- // for (const token of tokens) {
1424
- // const { children, text, type } = token;
1425
- // console.log(
1426
- // `${" ".repeat(depth * 2)}${type} ${text.replace(/\n/g, "\\n")}`
1427
- // );
1428
- // if (children.length > 0) {
1429
- // consoleLogTokens(children, depth + 1);
1430
- // }
1431
- // }
1432
- // }
1268
+ /**
1269
+ * Parses a Markdown document and returns (frozen) tokens.
1270
+ *
1271
+ * @param {string} markdown Markdown document.
1272
+ * @param {Object} [micromarkOptions] Options for micromark.
1273
+ * @param {boolean} [referencesDefined] Treat references as defined.
1274
+ * @returns {Token[]} Micromark tokens (frozen).
1275
+ */
1276
+ function micromarkParse(markdown) {
1277
+ var micromarkOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1278
+ var referencesDefined = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
1279
+ return micromarkParseWithOffset(markdown, micromarkOptions, referencesDefined, 0);
1280
+ }
1433
1281
 
1434
1282
  /**
1435
1283
  * Filter a list of Micromark tokens by predicate.
@@ -1468,6 +1316,74 @@ function filterByTypes(tokens, allowed) {
1468
1316
  });
1469
1317
  }
1470
1318
 
1319
+ /**
1320
+ * Filter a list of Micromark tokens for HTML tokens.
1321
+ *
1322
+ * @param {Token[]} tokens Micromark tokens.
1323
+ * @returns {Token[]} Filtered tokens.
1324
+ */
1325
+ function filterByHtmlTokens(tokens) {
1326
+ var result = [];
1327
+ var pending = [tokens];
1328
+ var current = null;
1329
+ while (current = pending.shift()) {
1330
+ var _iterator2 = _createForOfIteratorHelper(filterByTypes(current, ["htmlFlow", "htmlText"])),
1331
+ _step2;
1332
+ try {
1333
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1334
+ var token = _step2.value;
1335
+ if (token.type === "htmlText") {
1336
+ result.push(token);
1337
+ } else {
1338
+ // token.type === "htmlFlow"
1339
+ // @ts-ignore
1340
+ pending.push(token.htmlFlowChildren);
1341
+ }
1342
+ }
1343
+ } catch (err) {
1344
+ _iterator2.e(err);
1345
+ } finally {
1346
+ _iterator2.f();
1347
+ }
1348
+ }
1349
+ return result;
1350
+ }
1351
+
1352
+ /**
1353
+ * Returns a list of all nested child tokens.
1354
+ *
1355
+ * @param {Token} parent Micromark token.
1356
+ * @returns {Token[]} Flattened children.
1357
+ */
1358
+ function flattenedChildren(parent) {
1359
+ var result = [];
1360
+ var pending = _toConsumableArray(parent.children);
1361
+ var token = null;
1362
+ while (token = pending.shift()) {
1363
+ result.push(token);
1364
+ pending.unshift.apply(pending, _toConsumableArray(token.children));
1365
+ }
1366
+ return result;
1367
+ }
1368
+
1369
+ /**
1370
+ * Gets the heading level of a Micromark heading tokan.
1371
+ *
1372
+ * @param {Token} heading Micromark heading token.
1373
+ * @returns {number} Heading level.
1374
+ */
1375
+ function getHeadingLevel(heading) {
1376
+ var headingSequence = filterByTypes(heading.children, ["atxHeadingSequence", "setextHeadingLineSequence"]);
1377
+ var level = 1;
1378
+ var text = headingSequence[0].text;
1379
+ if (text[0] === "#") {
1380
+ level = Math.min(text.length, 6);
1381
+ } else if (text[0] === "-") {
1382
+ level = 2;
1383
+ }
1384
+ return level;
1385
+ }
1386
+
1471
1387
  /**
1472
1388
  * Gets information about the tag in an HTML token.
1473
1389
  *
@@ -1541,8 +1457,11 @@ function tokenIfType(token, type) {
1541
1457
  }
1542
1458
  module.exports = {
1543
1459
  "parse": micromarkParse,
1460
+ filterByHtmlTokens: filterByHtmlTokens,
1544
1461
  filterByPredicate: filterByPredicate,
1545
1462
  filterByTypes: filterByTypes,
1463
+ flattenedChildren: flattenedChildren,
1464
+ getHeadingLevel: getHeadingLevel,
1546
1465
  getHtmlTagInfo: getHtmlTagInfo,
1547
1466
  getMicromarkEvents: getMicromarkEvents,
1548
1467
  getTokenTextByType: getTokenTextByType,
@@ -1587,9 +1506,6 @@ module.exports.codeBlockAndSpanRanges = function () {
1587
1506
  module.exports.flattenedLists = function () {
1588
1507
  return map.get("flattenedLists");
1589
1508
  };
1590
- module.exports.htmlElementRanges = function () {
1591
- return map.get("htmlElementRanges");
1592
- };
1593
1509
  module.exports.lineMetadata = function () {
1594
1510
  return map.get("lineMetadata");
1595
1511
  };
@@ -1613,7 +1529,7 @@ module.exports.referenceLinkImageData = function () {
1613
1529
  module.exports.deprecatedRuleNames = ["MD002", "MD006"];
1614
1530
  module.exports.fixableRuleNames = ["MD004", "MD005", "MD006", "MD007", "MD009", "MD010", "MD011", "MD012", "MD014", "MD018", "MD019", "MD020", "MD021", "MD022", "MD023", "MD026", "MD027", "MD030", "MD031", "MD032", "MD034", "MD037", "MD038", "MD039", "MD044", "MD047", "MD049", "MD050", "MD051", "MD053"];
1615
1531
  module.exports.homepage = "https://github.com/DavidAnson/markdownlint";
1616
- module.exports.version = "0.29.0";
1532
+ module.exports.version = "0.30.0";
1617
1533
 
1618
1534
  /***/ }),
1619
1535
 
@@ -1702,7 +1618,7 @@ function validateRuleList(ruleList, synchronous) {
1702
1618
  result = newError(_property);
1703
1619
  }
1704
1620
  }
1705
- if (!result && rule.information && Object.getPrototypeOf(rule.information) !== URL.prototype) {
1621
+ if (!result && rule.information && !helpers.isUrl(rule.information)) {
1706
1622
  result = newError("information");
1707
1623
  }
1708
1624
  if (!result && rule.asynchronous !== undefined && typeof rule.asynchronous !== "boolean") {
@@ -2267,7 +2183,7 @@ function getEnabledRulesPerLineNumber(ruleList, lines, frontMatterLines, noInlin
2267
2183
  var disableNextLine = action === "DISABLE-NEXT-LINE";
2268
2184
  if (disableLine || disableNextLine) {
2269
2185
  var nextLineNumber = frontMatterLines.length + lineNumber + (disableNextLine ? 1 : 0);
2270
- enabledRulesPerLineNumber[nextLineNumber] = applyEnableDisable(action, parameter, enabledRulesPerLineNumber[nextLineNumber] || {});
2186
+ enabledRulesPerLineNumber[nextLineNumber] = applyEnableDisable(action, parameter, enabledRulesPerLineNumber[nextLineNumber]);
2271
2187
  }
2272
2188
  }
2273
2189
  // Handle inline comments
@@ -2354,12 +2270,10 @@ function lintContent(ruleList, aliasToRuleNames, name, content, md, config, conf
2354
2270
  var lineMetadata = helpers.getLineMetadata(paramsBase);
2355
2271
  var codeBlockAndSpanRanges = helpers.codeBlockAndSpanRanges(paramsBase, lineMetadata);
2356
2272
  var flattenedLists = helpers.flattenLists(paramsBase.parsers.markdownit.tokens);
2357
- var htmlElementRanges = helpers.htmlElementRanges(paramsBase, lineMetadata);
2358
2273
  var referenceLinkImageData = helpers.getReferenceLinkImageData(paramsBase);
2359
2274
  cache.set({
2360
2275
  codeBlockAndSpanRanges: codeBlockAndSpanRanges,
2361
2276
  flattenedLists: flattenedLists,
2362
- htmlElementRanges: htmlElementRanges,
2363
2277
  lineMetadata: lineMetadata,
2364
2278
  referenceLinkImageData: referenceLinkImageData
2365
2279
  });
@@ -2391,6 +2305,9 @@ function lintContent(ruleList, aliasToRuleNames, name, content, md, config, conf
2391
2305
  if (errorInfo.context && !helpers.isString(errorInfo.context)) {
2392
2306
  throwError("context");
2393
2307
  }
2308
+ if (errorInfo.information && !helpers.isUrl(errorInfo.information)) {
2309
+ throwError("information");
2310
+ }
2394
2311
  if (errorInfo.range && (!Array.isArray(errorInfo.range) || errorInfo.range.length !== 2 || !helpers.isNumber(errorInfo.range[0]) || errorInfo.range[0] < 1 || !helpers.isNumber(errorInfo.range[1]) || errorInfo.range[1] < 1 || errorInfo.range[0] + errorInfo.range[1] - 1 > lines[errorInfo.lineNumber - 1].length)) {
2395
2312
  throwError("range");
2396
2313
  }
@@ -2426,12 +2343,13 @@ function lintContent(ruleList, aliasToRuleNames, name, content, md, config, conf
2426
2343
  cleanFixInfo.insertText = fixInfo.insertText;
2427
2344
  }
2428
2345
  }
2346
+ var information = errorInfo.information || rule.information;
2429
2347
  results.push({
2430
2348
  lineNumber: lineNumber,
2431
2349
  "ruleName": rule.names[0],
2432
2350
  "ruleNames": rule.names,
2433
2351
  "ruleDescription": rule.description,
2434
- "ruleInformation": rule.information ? rule.information.href : null,
2352
+ "ruleInformation": information ? information.href : null,
2435
2353
  "errorDetail": errorInfo.detail || null,
2436
2354
  "errorContext": errorInfo.context || null,
2437
2355
  "errorRange": errorInfo.range ? _toConsumableArray(errorInfo.range) : null,
@@ -2609,8 +2527,18 @@ function lintInput(options, synchronous, callback) {
2609
2527
  // Normalize inputs
2610
2528
  options = options || {};
2611
2529
  callback = callback || function noop() {};
2530
+ var customRuleList = [options.customRules || []].flat().map(function (rule) {
2531
+ return {
2532
+ "names": helpers.cloneIfArray(rule.names),
2533
+ "description": rule.description,
2534
+ "information": helpers.cloneIfUrl(rule.information),
2535
+ "tags": helpers.cloneIfArray(rule.tags),
2536
+ "asynchronous": rule.asynchronous,
2537
+ "function": rule["function"]
2538
+ };
2539
+ });
2612
2540
  // eslint-disable-next-line unicorn/prefer-spread
2613
- var ruleList = rules.concat(options.customRules || []);
2541
+ var ruleList = rules.concat(customRuleList);
2614
2542
  var ruleErr = validateRuleList(ruleList, synchronous);
2615
2543
  if (ruleErr) {
2616
2544
  callback(ruleErr);
@@ -3026,6 +2954,7 @@ module.exports = markdownlint;
3026
2954
  * @property {number} lineNumber Line number (1-based).
3027
2955
  * @property {string} [detail] Detail about the error.
3028
2956
  * @property {string} [context] Context for the error.
2957
+ * @property {URL} [information] Link to more information.
3029
2958
  * @property {number[]} [range] Column number (1-based) and length.
3030
2959
  * @property {RuleOnErrorFixInfo} [fixInfo] Fix information.
3031
2960
  */
@@ -4235,15 +4164,50 @@ module.exports = {
4235
4164
 
4236
4165
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4237
4166
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4167
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
4168
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
4169
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4170
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4171
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
4172
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
4173
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
4238
4174
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4239
4175
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
4240
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
4241
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
4242
4176
  var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
4243
4177
  addErrorDetailIf = _require.addErrorDetailIf,
4244
4178
  blockquotePrefixRe = _require.blockquotePrefixRe,
4245
- filterTokens = _require.filterTokens,
4246
4179
  isBlankLine = _require.isBlankLine;
4180
+ var _require2 = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs"),
4181
+ filterByTypes = _require2.filterByTypes,
4182
+ getHeadingLevel = _require2.getHeadingLevel;
4183
+ var defaultLines = 1;
4184
+ var getLinesFunction = function getLinesFunction(linesParam) {
4185
+ if (Array.isArray(linesParam)) {
4186
+ var linesArray = new Array(6).fill(defaultLines);
4187
+ var _iterator = _createForOfIteratorHelper(_toConsumableArray(linesParam.entries()).slice(0, 6)),
4188
+ _step;
4189
+ try {
4190
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
4191
+ var _step$value = _slicedToArray(_step.value, 2),
4192
+ index = _step$value[0],
4193
+ value = _step$value[1];
4194
+ linesArray[index] = value;
4195
+ }
4196
+ } catch (err) {
4197
+ _iterator.e(err);
4198
+ } finally {
4199
+ _iterator.f();
4200
+ }
4201
+ return function (heading) {
4202
+ return linesArray[getHeadingLevel(heading) - 1];
4203
+ };
4204
+ }
4205
+ // Coerce linesParam to a number
4206
+ var lines = linesParam === undefined ? defaultLines : Number(linesParam);
4207
+ return function () {
4208
+ return lines;
4209
+ };
4210
+ };
4247
4211
  var getBlockQuote = function getBlockQuote(str, count) {
4248
4212
  return (str || "").match(blockquotePrefixRe)[0].trimEnd()
4249
4213
  // eslint-disable-next-line unicorn/prefer-spread
@@ -4254,35 +4218,50 @@ module.exports = {
4254
4218
  "description": "Headings should be surrounded by blank lines",
4255
4219
  "tags": ["headings", "headers", "blank_lines"],
4256
4220
  "function": function MD022(params, onError) {
4257
- var linesAbove = params.config.lines_above;
4258
- linesAbove = Number(linesAbove === undefined ? 1 : linesAbove);
4259
- var linesBelow = params.config.lines_below;
4260
- linesBelow = Number(linesBelow === undefined ? 1 : linesBelow);
4261
- var lines = params.lines;
4262
- filterTokens(params, "heading_open", function (token) {
4263
- var _token$map = _slicedToArray(token.map, 2),
4264
- topIndex = _token$map[0],
4265
- nextIndex = _token$map[1];
4266
- var actualAbove = 0;
4267
- for (var i = 0; i < linesAbove; i++) {
4268
- if (isBlankLine(lines[topIndex - i - 1])) {
4269
- actualAbove++;
4221
+ var getLinesAbove = getLinesFunction(params.config.lines_above);
4222
+ var getLinesBelow = getLinesFunction(params.config.lines_below);
4223
+ var lines = params.lines,
4224
+ parsers = params.parsers;
4225
+ var headings = filterByTypes(parsers.micromark.tokens, ["atxHeading", "setextHeading"]);
4226
+ var _iterator2 = _createForOfIteratorHelper(headings),
4227
+ _step2;
4228
+ try {
4229
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
4230
+ var heading = _step2.value;
4231
+ var startLine = heading.startLine,
4232
+ endLine = heading.endLine;
4233
+ var line = lines[startLine - 1].trim();
4234
+
4235
+ // Check lines above
4236
+ var linesAbove = getLinesAbove(heading);
4237
+ if (linesAbove >= 0) {
4238
+ var actualAbove = 0;
4239
+ for (var i = 0; i < linesAbove && isBlankLine(lines[startLine - 2 - i]); i++) {
4240
+ actualAbove++;
4241
+ }
4242
+ addErrorDetailIf(onError, startLine, linesAbove, actualAbove, "Above", line, null, {
4243
+ "insertText": getBlockQuote(lines[startLine - 2], linesAbove - actualAbove)
4244
+ });
4270
4245
  }
4271
- }
4272
- addErrorDetailIf(onError, topIndex + 1, linesAbove, actualAbove, "Above", lines[topIndex].trim(), null, {
4273
- "insertText": getBlockQuote(lines[topIndex - 1], linesAbove - actualAbove)
4274
- });
4275
- var actualBelow = 0;
4276
- for (var _i2 = 0; _i2 < linesBelow; _i2++) {
4277
- if (isBlankLine(lines[nextIndex + _i2])) {
4278
- actualBelow++;
4246
+
4247
+ // Check lines below
4248
+ var linesBelow = getLinesBelow(heading);
4249
+ if (linesBelow >= 0) {
4250
+ var actualBelow = 0;
4251
+ for (var _i2 = 0; _i2 < linesBelow && isBlankLine(lines[endLine + _i2]); _i2++) {
4252
+ actualBelow++;
4253
+ }
4254
+ addErrorDetailIf(onError, startLine, linesBelow, actualBelow, "Below", line, null, {
4255
+ "lineNumber": endLine + 1,
4256
+ "insertText": getBlockQuote(lines[endLine], linesBelow - actualBelow)
4257
+ });
4279
4258
  }
4280
4259
  }
4281
- addErrorDetailIf(onError, topIndex + 1, linesBelow, actualBelow, "Below", lines[topIndex].trim(), null, {
4282
- "lineNumber": nextIndex + 1,
4283
- "insertText": getBlockQuote(lines[nextIndex], linesBelow - actualBelow)
4284
- });
4285
- });
4260
+ } catch (err) {
4261
+ _iterator2.e(err);
4262
+ } finally {
4263
+ _iterator2.f();
4264
+ }
4286
4265
  }
4287
4266
  };
4288
4267
 
@@ -4434,12 +4413,17 @@ module.exports = {
4434
4413
 
4435
4414
 
4436
4415
 
4416
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
4417
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4418
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
4437
4419
  var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
4438
4420
  addError = _require.addError,
4439
4421
  allPunctuationNoQuestion = _require.allPunctuationNoQuestion,
4440
- escapeForRegExp = _require.escapeForRegExp,
4441
- forEachHeading = _require.forEachHeading;
4442
- var endOfLineHtmlEntityRe = /&#?[\da-zA-Z]+;$/;
4422
+ endOfLineGemojiCodeRe = _require.endOfLineGemojiCodeRe,
4423
+ endOfLineHtmlEntityRe = _require.endOfLineHtmlEntityRe,
4424
+ escapeForRegExp = _require.escapeForRegExp;
4425
+ var _require2 = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs"),
4426
+ filterByTypes = _require2.filterByTypes;
4443
4427
  module.exports = {
4444
4428
  "names": ["MD026", "no-trailing-punctuation"],
4445
4429
  "description": "Trailing punctuation in heading",
@@ -4448,21 +4432,31 @@ module.exports = {
4448
4432
  var punctuation = params.config.punctuation;
4449
4433
  punctuation = String(punctuation === undefined ? allPunctuationNoQuestion : punctuation);
4450
4434
  var trailingPunctuationRe = new RegExp("\\s*[" + escapeForRegExp(punctuation) + "]+$");
4451
- forEachHeading(params, function (heading) {
4452
- var line = heading.line,
4453
- lineNumber = heading.lineNumber;
4454
- var trimmedLine = line.replace(/([^\s#])[\s#]+$/, "$1");
4455
- var match = trailingPunctuationRe.exec(trimmedLine);
4456
- if (match && !endOfLineHtmlEntityRe.test(trimmedLine)) {
4457
- var fullMatch = match[0];
4458
- var column = match.index + 1;
4459
- var length = fullMatch.length;
4460
- addError(onError, lineNumber, "Punctuation: '".concat(fullMatch, "'"), null, [column, length], {
4461
- "editColumn": column,
4462
- "deleteCount": length
4463
- });
4435
+ var headings = filterByTypes(params.parsers.micromark.tokens, ["atxHeadingText", "setextHeadingText"]);
4436
+ var _iterator = _createForOfIteratorHelper(headings),
4437
+ _step;
4438
+ try {
4439
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
4440
+ var heading = _step.value;
4441
+ var endLine = heading.endLine,
4442
+ startColumn = heading.startColumn,
4443
+ text = heading.text;
4444
+ var match = trailingPunctuationRe.exec(text);
4445
+ if (match && !endOfLineHtmlEntityRe.test(text) && !endOfLineGemojiCodeRe.test(text)) {
4446
+ var fullMatch = match[0];
4447
+ var column = startColumn + match.index;
4448
+ var length = fullMatch.length;
4449
+ addError(onError, endLine, "Punctuation: '".concat(fullMatch, "'"), undefined, [column, length], {
4450
+ "editColumn": column,
4451
+ "deleteCount": length
4452
+ });
4453
+ }
4464
4454
  }
4465
- });
4455
+ } catch (err) {
4456
+ _iterator.e(err);
4457
+ } finally {
4458
+ _iterator.f();
4459
+ }
4466
4460
  }
4467
4461
  };
4468
4462
 
@@ -4843,38 +4837,66 @@ var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
4843
4837
  addErrorContext = _require.addErrorContext,
4844
4838
  blockquotePrefixRe = _require.blockquotePrefixRe,
4845
4839
  isBlankLine = _require.isBlankLine;
4846
- var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"),
4847
- flattenedLists = _require2.flattenedLists;
4840
+ var _require2 = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs"),
4841
+ filterByPredicate = _require2.filterByPredicate,
4842
+ flattenedChildren = _require2.flattenedChildren;
4843
+ var nonContentTokens = new Set(["blockQuoteMarker", "blockQuotePrefix", "blockQuotePrefixWhitespace", "lineEnding", "lineEndingBlank", "linePrefix", "listItemIndent"]);
4844
+ var isList = function isList(token) {
4845
+ return token.type === "listOrdered" || token.type === "listUnordered";
4846
+ };
4847
+ var addBlankLineError = function addBlankLineError(onError, lines, lineIndex, lineNumber) {
4848
+ var line = lines[lineIndex];
4849
+ var quotePrefix = line.match(blockquotePrefixRe)[0].trimEnd();
4850
+ addErrorContext(onError, lineIndex + 1, line.trim(), null, null, null, {
4851
+ lineNumber: lineNumber,
4852
+ "insertText": "".concat(quotePrefix, "\n")
4853
+ });
4854
+ };
4848
4855
  module.exports = {
4849
4856
  "names": ["MD032", "blanks-around-lists"],
4850
4857
  "description": "Lists should be surrounded by blank lines",
4851
4858
  "tags": ["bullet", "ul", "ol", "blank_lines"],
4852
4859
  "function": function MD032(params, onError) {
4853
- var lines = params.lines;
4854
- var filteredLists = flattenedLists().filter(function (list) {
4855
- return !list.nesting;
4860
+ var lines = params.lines,
4861
+ parsers = params.parsers;
4862
+
4863
+ // For every top-level list...
4864
+ var topLevelLists = filterByPredicate(parsers.micromark.tokens, isList, function (token) {
4865
+ return isList(token) ? [] : token.children;
4856
4866
  });
4857
- var _iterator = _createForOfIteratorHelper(filteredLists),
4867
+ var _iterator = _createForOfIteratorHelper(topLevelLists),
4858
4868
  _step;
4859
4869
  try {
4860
4870
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
4861
4871
  var list = _step.value;
4862
- var firstIndex = list.open.map[0];
4872
+ // Look for a blank line above the list
4873
+ var firstIndex = list.startLine - 1;
4863
4874
  if (!isBlankLine(lines[firstIndex - 1])) {
4864
- var line = lines[firstIndex];
4865
- var quotePrefix = line.match(blockquotePrefixRe)[0].trimEnd();
4866
- addErrorContext(onError, firstIndex + 1, line.trim(), null, null, null, {
4867
- "insertText": "".concat(quotePrefix, "\n")
4868
- });
4875
+ addBlankLineError(onError, lines, firstIndex);
4876
+ }
4877
+
4878
+ // Find the "visual" end of the list
4879
+ var endLine = list.endLine;
4880
+ var _iterator2 = _createForOfIteratorHelper(flattenedChildren(list).reverse()),
4881
+ _step2;
4882
+ try {
4883
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
4884
+ var child = _step2.value;
4885
+ if (!nonContentTokens.has(child.type)) {
4886
+ endLine = child.endLine;
4887
+ break;
4888
+ }
4889
+ }
4890
+
4891
+ // Look for a blank line below the list
4892
+ } catch (err) {
4893
+ _iterator2.e(err);
4894
+ } finally {
4895
+ _iterator2.f();
4869
4896
  }
4870
- var lastIndex = list.lastLineIndex - 1;
4897
+ var lastIndex = endLine - 1;
4871
4898
  if (!isBlankLine(lines[lastIndex + 1])) {
4872
- var _line = lines[lastIndex];
4873
- var _quotePrefix = _line.match(blockquotePrefixRe)[0].trimEnd();
4874
- addErrorContext(onError, lastIndex + 1, _line.trim(), null, null, null, {
4875
- "lineNumber": lastIndex + 2,
4876
- "insertText": "".concat(_quotePrefix, "\n")
4877
- });
4899
+ addBlankLineError(onError, lines, lastIndex, lastIndex + 2);
4878
4900
  }
4879
4901
  }
4880
4902
  } catch (err) {
@@ -4898,19 +4920,14 @@ module.exports = {
4898
4920
 
4899
4921
 
4900
4922
 
4901
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
4902
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4903
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4923
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
4904
4924
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4905
4925
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
4906
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
4907
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
4908
4926
  var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
4909
4927
  addError = _require.addError;
4910
4928
  var _require2 = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs"),
4911
- filterByTypes = _require2.filterByTypes,
4912
- getHtmlTagInfo = _require2.getHtmlTagInfo,
4913
- parse = _require2.parse;
4929
+ filterByHtmlTokens = _require2.filterByHtmlTokens,
4930
+ getHtmlTagInfo = _require2.getHtmlTagInfo;
4914
4931
  var nextLinesRe = /[\r\n][\s\S]*$/;
4915
4932
  module.exports = {
4916
4933
  "names": ["MD033", "no-inline-html"],
@@ -4922,45 +4939,21 @@ module.exports = {
4922
4939
  allowedElements = allowedElements.map(function (element) {
4923
4940
  return element.toLowerCase();
4924
4941
  });
4925
- var pending = [[0, params.parsers.micromark.tokens]];
4926
- var current = null;
4927
- while (current = pending.shift()) {
4928
- var _current = current,
4929
- _current2 = _slicedToArray(_current, 2),
4930
- offset = _current2[0],
4931
- tokens = _current2[1];
4932
- var _iterator = _createForOfIteratorHelper(filterByTypes(tokens, ["htmlFlow", "htmlText"])),
4933
- _step;
4934
- try {
4935
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
4936
- var token = _step.value;
4937
- if (token.type === "htmlText") {
4938
- var htmlTagInfo = getHtmlTagInfo(token);
4939
- if (htmlTagInfo && !htmlTagInfo.close && !allowedElements.includes(htmlTagInfo.name.toLowerCase())) {
4940
- var range = [token.startColumn, token.text.replace(nextLinesRe, "").length];
4941
- addError(onError, token.startLine + offset, "Element: " + htmlTagInfo.name, undefined, range);
4942
- }
4943
- } else {
4944
- // token.type === "htmlFlow"
4945
- // Re-parse without "htmlFlow" to get only "htmlText" tokens
4946
- var options = {
4947
- "extensions": [{
4948
- "disable": {
4949
- "null": ["codeIndented", "htmlFlow"]
4950
- }
4951
- }]
4952
- };
4953
- // Use lines instead of token.text for accurate columns
4954
- var lines = params.lines.slice(token.startLine - 1, token.endLine).join("\n");
4955
- var flowTokens = parse(lines, options);
4956
- pending.push([token.startLine - 1, flowTokens]);
4957
- }
4942
+ var _iterator = _createForOfIteratorHelper(filterByHtmlTokens(params.parsers.micromark.tokens)),
4943
+ _step;
4944
+ try {
4945
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
4946
+ var token = _step.value;
4947
+ var htmlTagInfo = getHtmlTagInfo(token);
4948
+ if (htmlTagInfo && !htmlTagInfo.close && !allowedElements.includes(htmlTagInfo.name.toLowerCase())) {
4949
+ var range = [token.startColumn, token.text.replace(nextLinesRe, "").length];
4950
+ addError(onError, token.startLine, "Element: " + htmlTagInfo.name, undefined, range);
4958
4951
  }
4959
- } catch (err) {
4960
- _iterator.e(err);
4961
- } finally {
4962
- _iterator.f();
4963
4952
  }
4953
+ } catch (err) {
4954
+ _iterator.e(err);
4955
+ } finally {
4956
+ _iterator.f();
4964
4957
  }
4965
4958
  }
4966
4959
  };
@@ -5184,6 +5177,11 @@ module.exports = {
5184
5177
 
5185
5178
 
5186
5179
 
5180
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
5181
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5182
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
5183
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
5184
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
5187
5185
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
5188
5186
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5189
5187
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -5191,154 +5189,113 @@ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symb
5191
5189
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
5192
5190
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5193
5191
  var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
5194
- addErrorContext = _require.addErrorContext,
5195
- emphasisMarkersInContent = _require.emphasisMarkersInContent,
5196
- forEachLine = _require.forEachLine,
5197
- isBlankLine = _require.isBlankLine,
5198
- withinAnyRange = _require.withinAnyRange;
5199
- var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"),
5200
- htmlElementRanges = _require2.htmlElementRanges,
5201
- lineMetadata = _require2.lineMetadata;
5202
- var emphasisRe = /(^|[^\\]|\\\\)(?:(\*{1,3})|(_{1,3}))/g;
5203
- var embeddedUnderscoreRe = /([A-Za-z\d])(_([A-Za-z\d]))+/g;
5204
- var asteriskListItemMarkerRe = /^([\s>]*)\*(\s+)/;
5205
- var leftSpaceRe = /^\s+/;
5206
- var rightSpaceRe = /\s+$/;
5207
- var tablePipeRe = /\|/;
5208
- var allUnderscoresRe = /_/g;
5192
+ addError = _require.addError;
5193
+ var emphasisStartTextRe = /^(\S{1,3})(\s+)\S/;
5194
+ var emphasisEndTextRe = /\S(\s+)(\S{1,3})$/;
5209
5195
  module.exports = {
5210
5196
  "names": ["MD037", "no-space-in-emphasis"],
5211
5197
  "description": "Spaces inside emphasis markers",
5212
5198
  "tags": ["whitespace", "emphasis"],
5213
5199
  "function": function MD037(params, onError) {
5214
- var exclusions = htmlElementRanges();
5215
- // eslint-disable-next-line init-declarations
5216
- var effectiveEmphasisLength,
5217
- emphasisIndex,
5218
- emphasisKind,
5219
- emphasisLength,
5220
- pendingError = null;
5221
- // eslint-disable-next-line jsdoc/require-jsdoc
5222
- function resetRunTracking() {
5223
- emphasisIndex = -1;
5224
- emphasisLength = 0;
5225
- emphasisKind = "";
5226
- effectiveEmphasisLength = 0;
5227
- pendingError = null;
5200
+ // Initialize variables
5201
+ var lines = params.lines,
5202
+ parsers = params.parsers;
5203
+ var emphasisTokensByMarker = new Map();
5204
+ for (var _i = 0, _arr = ["_", "__", "___", "*", "**", "***"]; _i < _arr.length; _i++) {
5205
+ var marker = _arr[_i];
5206
+ emphasisTokensByMarker.set(marker, []);
5228
5207
  }
5229
- // eslint-disable-next-line jsdoc/require-jsdoc
5230
- function handleRunEnd(line, lineIndex, contextLength, match, matchIndex, inTable) {
5231
- // Close current run
5232
- var content = line.substring(emphasisIndex, matchIndex);
5233
- if (!emphasisLength) {
5234
- content = content.trimStart();
5235
- }
5236
- if (!match) {
5237
- content = content.trimEnd();
5208
+ var pending = _toConsumableArray(parsers.micromark.tokens);
5209
+ var token = null;
5210
+ while (token = pending.shift()) {
5211
+ // Use reparsed children of htmlFlow tokens
5212
+ if (token.type === "htmlFlow") {
5213
+ pending.unshift.apply(pending, _toConsumableArray(token.htmlFlowChildren));
5214
+ continue;
5238
5215
  }
5239
- var leftSpace = leftSpaceRe.test(content);
5240
- var rightSpace = rightSpaceRe.test(content);
5241
- if ((leftSpace || rightSpace) && (!inTable || !tablePipeRe.test(content))) {
5242
- // Report the violation
5243
- var contextStart = emphasisIndex - emphasisLength;
5244
- var contextEnd = matchIndex + contextLength;
5245
- var column = contextStart + 1;
5246
- var length = contextEnd - contextStart;
5247
- if (!withinAnyRange(exclusions, lineIndex, column, length)) {
5248
- var context = line.substring(contextStart, contextEnd);
5249
- var leftMarker = line.substring(contextStart, emphasisIndex);
5250
- var rightMarker = match ? match[2] || match[3] : "";
5251
- var fixedText = "".concat(leftMarker).concat(content.trim()).concat(rightMarker);
5252
- return [onError, lineIndex + 1, context, leftSpace, rightSpace, [column, length], {
5253
- "editColumn": column,
5254
- "deleteCount": length,
5255
- "insertText": fixedText
5256
- }];
5216
+ pending.push.apply(pending, _toConsumableArray(token.children));
5217
+
5218
+ // Build lists of bare tokens for each emphasis marker type
5219
+ var _iterator = _createForOfIteratorHelper(emphasisTokensByMarker.values()),
5220
+ _step;
5221
+ try {
5222
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
5223
+ var emphasisTokens = _step.value;
5224
+ emphasisTokens.length = 0;
5257
5225
  }
5226
+ } catch (err) {
5227
+ _iterator.e(err);
5228
+ } finally {
5229
+ _iterator.f();
5258
5230
  }
5259
- return null;
5260
- }
5261
- // Initialize
5262
- var ignoreMarkersByLine = emphasisMarkersInContent(params);
5263
- resetRunTracking();
5264
- forEachLine(lineMetadata(), function (line, lineIndex, inCode, onFence, inTable, inItem, onBreak, inMath) {
5265
- var onItemStart = inItem === 1;
5266
- if (inCode || onFence || inTable || onBreak || onItemStart || isBlankLine(line)) {
5267
- // Emphasis resets when leaving a block
5268
- resetRunTracking();
5269
- }
5270
- if (inCode || onFence || onBreak || inMath) {
5271
- // Emphasis has no meaning here
5272
- return;
5273
- }
5274
- var patchedLine = line.replace(embeddedUnderscoreRe, function (match) {
5275
- return match.replace(allUnderscoresRe, " ");
5276
- });
5277
- if (onItemStart) {
5278
- // Trim overlapping '*' list item marker
5279
- patchedLine = patchedLine.replace(asteriskListItemMarkerRe, "$1 $2");
5280
- }
5281
- var match = null;
5282
- // Match all emphasis-looking runs in the line...
5283
- while (match = emphasisRe.exec(patchedLine)) {
5284
- var ignoreMarkersForLine = ignoreMarkersByLine[lineIndex];
5285
- var matchIndex = match.index + match[1].length;
5286
- if (ignoreMarkersForLine.includes(matchIndex)) {
5287
- // Ignore emphasis markers inside code spans and links
5288
- continue;
5231
+ var _iterator2 = _createForOfIteratorHelper(token.children),
5232
+ _step2;
5233
+ try {
5234
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
5235
+ var child = _step2.value;
5236
+ var text = child.text,
5237
+ type = child.type;
5238
+ if (type === "data" && text.length <= 3) {
5239
+ var _emphasisTokens = emphasisTokensByMarker.get(text);
5240
+ if (_emphasisTokens) {
5241
+ _emphasisTokens.push(child);
5242
+ }
5243
+ }
5289
5244
  }
5290
- var matchLength = match[0].length - match[1].length;
5291
- var matchKind = (match[2] || match[3])[0];
5292
- if (emphasisIndex === -1) {
5293
- // New run
5294
- emphasisIndex = matchIndex + matchLength;
5295
- emphasisLength = matchLength;
5296
- emphasisKind = matchKind;
5297
- effectiveEmphasisLength = matchLength;
5298
- } else if (matchKind === emphasisKind) {
5299
- // Matching emphasis markers
5300
- if (matchLength === effectiveEmphasisLength) {
5301
- // Ending an existing run, report any pending error
5302
- if (pendingError) {
5303
- // @ts-ignore
5304
- addErrorContext.apply(void 0, _toConsumableArray(pendingError));
5305
- pendingError = null;
5245
+
5246
+ // Process bare tokens for each emphasis marker type
5247
+ } catch (err) {
5248
+ _iterator2.e(err);
5249
+ } finally {
5250
+ _iterator2.f();
5251
+ }
5252
+ var _iterator3 = _createForOfIteratorHelper(emphasisTokensByMarker.values()),
5253
+ _step3;
5254
+ try {
5255
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
5256
+ var _emphasisTokens2 = _step3.value;
5257
+ for (var i = 0; i + 1 < _emphasisTokens2.length; i += 2) {
5258
+ // Process start token of start/end pair
5259
+ var startToken = _emphasisTokens2[i];
5260
+ var startText = lines[startToken.startLine - 1].slice(startToken.startColumn - 1);
5261
+ var startMatch = startText.match(emphasisStartTextRe);
5262
+ if (startMatch) {
5263
+ var _startMatch = _slicedToArray(startMatch, 3),
5264
+ startContext = _startMatch[0],
5265
+ startMarker = _startMatch[1],
5266
+ startSpaces = _startMatch[2];
5267
+ if (startMarker === startToken.text && startSpaces.length > 0) {
5268
+ addError(onError, startToken.startLine, undefined, startContext, [startToken.startColumn, startContext.length], {
5269
+ "editColumn": startToken.endColumn,
5270
+ "deleteCount": startSpaces.length
5271
+ });
5272
+ }
5306
5273
  }
5307
- var error = handleRunEnd(line, lineIndex, effectiveEmphasisLength, match, matchIndex, inTable);
5308
- if (error) {
5309
- // @ts-ignore
5310
- addErrorContext.apply(void 0, _toConsumableArray(error));
5274
+
5275
+ // Process end token of start/end pair
5276
+ var endToken = _emphasisTokens2[i + 1];
5277
+ var endText = lines[endToken.startLine - 1].slice(0, endToken.endColumn - 1);
5278
+ var endMatch = endText.match(emphasisEndTextRe);
5279
+ if (endMatch) {
5280
+ var _endMatch = _slicedToArray(endMatch, 3),
5281
+ endContext = _endMatch[0],
5282
+ endSpace = _endMatch[1],
5283
+ endMarker = _endMatch[2];
5284
+ if (endMarker === endToken.text && endSpace.length > 0) {
5285
+ addError(onError, endToken.startLine, undefined, endContext, [endToken.endColumn - endContext.length, endContext.length], {
5286
+ "editColumn": endToken.startColumn - endSpace.length,
5287
+ "deleteCount": endSpace.length
5288
+ });
5289
+ }
5311
5290
  }
5312
- // Reset
5313
- resetRunTracking();
5314
- } else if (matchLength === 3) {
5315
- // Swap internal run length (1->2 or 2->1)
5316
- effectiveEmphasisLength = matchLength - effectiveEmphasisLength;
5317
- } else if (effectiveEmphasisLength === 3) {
5318
- // Downgrade internal run (3->1 or 3->2)
5319
- effectiveEmphasisLength -= matchLength;
5320
- } else {
5321
- // Upgrade to internal run (1->3 or 2->3)
5322
- effectiveEmphasisLength += matchLength;
5323
- }
5324
- // Back up one character so RegExp has a chance to match the
5325
- // next marker (ex: "**star**_underscore_")
5326
- if (emphasisRe.lastIndex > 1) {
5327
- emphasisRe.lastIndex--;
5328
5291
  }
5329
- } else if (emphasisRe.lastIndex > 1) {
5330
- // Back up one character so RegExp has a chance to match the
5331
- // mis-matched marker (ex: "*text_*")
5332
- emphasisRe.lastIndex--;
5333
5292
  }
5293
+ } catch (err) {
5294
+ _iterator3.e(err);
5295
+ } finally {
5296
+ _iterator3.f();
5334
5297
  }
5335
- if (emphasisIndex !== -1) {
5336
- pendingError = pendingError || handleRunEnd(line, lineIndex, 0, null, line.length, inTable);
5337
- // Adjust for pending run on new line
5338
- emphasisIndex = 0;
5339
- emphasisLength = 0;
5340
- }
5341
- });
5298
+ }
5342
5299
  }
5343
5300
  };
5344
5301
 
@@ -5938,19 +5895,37 @@ module.exports = {
5938
5895
 
5939
5896
 
5940
5897
 
5898
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
5899
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5900
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5941
5901
  var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
5942
- addError = _require.addError,
5943
- forEachInlineChild = _require.forEachInlineChild;
5902
+ addError = _require.addError;
5903
+ var _require2 = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs"),
5904
+ filterByTypes = _require2.filterByTypes;
5944
5905
  module.exports = {
5945
5906
  "names": ["MD045", "no-alt-text"],
5946
5907
  "description": "Images should have alternate text (alt text)",
5947
5908
  "tags": ["accessibility", "images"],
5948
5909
  "function": function MD045(params, onError) {
5949
- forEachInlineChild(params, "image", function forToken(token) {
5950
- if (token.content === "") {
5951
- addError(onError, token.lineNumber);
5910
+ var images = filterByTypes(params.parsers.micromark.tokens, ["image"]);
5911
+ var _iterator = _createForOfIteratorHelper(images),
5912
+ _step;
5913
+ try {
5914
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
5915
+ var image = _step.value;
5916
+ var labelTexts = filterByTypes(image.children, ["labelText"]);
5917
+ if (labelTexts.some(function (labelText) {
5918
+ return labelText.text.length === 0;
5919
+ })) {
5920
+ var range = image.startLine === image.endLine ? [image.startColumn, image.endColumn - image.startColumn] : undefined;
5921
+ addError(onError, image.startLine, undefined, undefined, range);
5922
+ }
5952
5923
  }
5953
- });
5924
+ } catch (err) {
5925
+ _iterator.e(err);
5926
+ } finally {
5927
+ _iterator.f();
5928
+ }
5954
5929
  }
5955
5930
  };
5956
5931
 
@@ -6184,35 +6159,34 @@ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symb
6184
6159
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6185
6160
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6186
6161
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6187
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6188
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
6189
6162
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
6190
6163
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
6164
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
6165
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6166
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
6191
6167
  var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
6192
6168
  addError = _require.addError,
6193
- addErrorDetailIf = _require.addErrorDetailIf,
6194
- escapeForRegExp = _require.escapeForRegExp,
6195
- filterTokens = _require.filterTokens,
6196
- forEachInlineChild = _require.forEachInlineChild,
6197
- forEachHeading = _require.forEachHeading,
6198
- htmlElementRe = _require.htmlElementRe;
6169
+ addErrorDetailIf = _require.addErrorDetailIf;
6170
+ var _require2 = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs"),
6171
+ filterByHtmlTokens = _require2.filterByHtmlTokens,
6172
+ filterByTypes = _require2.filterByTypes,
6173
+ getHtmlTagInfo = _require2.getHtmlTagInfo;
6199
6174
 
6200
6175
  // Regular expression for identifying HTML anchor names
6201
6176
  var idRe = /[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]id[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*=[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*["']?((?:(?![\t-\r "'>\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uD800-\uDFFF\uFEFF])[\s\S]|[\uD800-\uDBFF][\uDC00-\uDFFF])+)/i;
6202
6177
  var nameRe = /[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]name[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*=[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*["']?((?:(?![\t-\r "'>\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uD800-\uDFFF\uFEFF])[\s\S]|[\uD800-\uDBFF][\uDC00-\uDFFF])+)/i;
6178
+ var anchorRe = /\{(#[0-9a-z]+(?:[\x2D_][0-9a-z]+)*)\}/g;
6203
6179
 
6204
6180
  /**
6205
6181
  * Converts a Markdown heading into an HTML fragment according to the rules
6206
6182
  * used by GitHub.
6207
6183
  *
6208
- * @param {Object} inline Inline token for heading.
6184
+ * @param {Object} headingText Heading text token.
6209
6185
  * @returns {string} Fragment string for heading.
6210
6186
  */
6211
- function convertHeadingToHTMLFragment(inline) {
6212
- var inlineText = inline.children.filter(function (token) {
6213
- return token.type !== "html_inline";
6214
- }).map(function (token) {
6215
- return token.content;
6187
+ function convertHeadingToHTMLFragment(headingText) {
6188
+ var inlineText = filterByTypes(headingText.children, ["codeTextData", "data"]).map(function (token) {
6189
+ return token.text;
6216
6190
  }).join("");
6217
6191
  return "#" + encodeURIComponent(inlineText.toLowerCase()
6218
6192
  // RegExp source with Ruby's \p{Word} expanded into its General Categories
@@ -6226,72 +6200,119 @@ module.exports = {
6226
6200
  "description": "Link fragments should be valid",
6227
6201
  "tags": ["links"],
6228
6202
  "function": function MD051(params, onError) {
6203
+ var tokens = params.parsers.micromark.tokens;
6229
6204
  var fragments = new Map();
6205
+
6230
6206
  // Process headings
6231
- forEachHeading(params, function (heading, content, inline) {
6232
- var fragment = convertHeadingToHTMLFragment(inline);
6233
- var count = fragments.get(fragment) || 0;
6234
- if (count) {
6235
- fragments.set("".concat(fragment, "-").concat(count), 0);
6236
- }
6237
- fragments.set(fragment, count + 1);
6238
- });
6239
- // Process HTML anchors
6240
- var processHtmlToken = function processHtmlToken(token) {
6241
- var match = null;
6242
- while ((match = htmlElementRe.exec(token.content)) !== null) {
6243
- var _match = match,
6244
- _match2 = _slicedToArray(_match, 3),
6245
- tag = _match2[0],
6246
- element = _match2[2];
6247
- var anchorMatch = idRe.exec(tag) || element.toLowerCase() === "a" && nameRe.exec(tag);
6248
- if (anchorMatch) {
6249
- fragments.set("#".concat(anchorMatch[1]), 0);
6207
+ var headingTexts = filterByTypes(tokens, ["atxHeadingText", "setextHeadingText"]);
6208
+ var _iterator = _createForOfIteratorHelper(headingTexts),
6209
+ _step;
6210
+ try {
6211
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
6212
+ var headingText = _step.value;
6213
+ var fragment = convertHeadingToHTMLFragment(headingText);
6214
+ var count = fragments.get(fragment) || 0;
6215
+ if (count) {
6216
+ fragments.set("".concat(fragment, "-").concat(count), 0);
6217
+ }
6218
+ fragments.set(fragment, count + 1);
6219
+ var match = null;
6220
+ while ((match = anchorRe.exec(headingText.text)) !== null) {
6221
+ var _match = match,
6222
+ _match2 = _slicedToArray(_match, 2),
6223
+ anchor = _match2[1];
6224
+ if (!fragments.has(anchor)) {
6225
+ fragments.set(anchor, 1);
6226
+ }
6250
6227
  }
6251
6228
  }
6252
- };
6253
- filterTokens(params, "html_block", processHtmlToken);
6254
- forEachInlineChild(params, "html_inline", processHtmlToken);
6255
- // Process link fragments
6256
- forEachInlineChild(params, "link_open", function (token) {
6257
- var attrs = token.attrs,
6258
- lineNumber = token.lineNumber,
6259
- line = token.line;
6260
- var href = attrs.find(function (attr) {
6261
- return attr[0] === "href";
6262
- });
6263
- var id = href && href[1];
6264
- if (id && id.length > 1 && id[0] === "#" && !fragments.has(id)) {
6265
- var context = id;
6266
- var range = null;
6267
- var fixInfo = null;
6268
- var match = line.match(new RegExp("\\[.*?\\]\\(".concat(escapeForRegExp(context), "\\)")));
6269
- if (match) {
6270
- var _match3 = _slicedToArray(match, 1);
6271
- context = _match3[0];
6272
- var index = match.index;
6273
- var length = context.length;
6274
- range = [index + 1, length];
6275
- fixInfo = {
6276
- "editColumn": index + (length - id.length),
6277
- "deleteCount": id.length,
6278
- "insertText": null
6279
- };
6229
+
6230
+ // Process HTML anchors
6231
+ } catch (err) {
6232
+ _iterator.e(err);
6233
+ } finally {
6234
+ _iterator.f();
6235
+ }
6236
+ var _iterator2 = _createForOfIteratorHelper(filterByHtmlTokens(tokens)),
6237
+ _step2;
6238
+ try {
6239
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
6240
+ var token = _step2.value;
6241
+ var htmlTagInfo = getHtmlTagInfo(token);
6242
+ if (htmlTagInfo && !htmlTagInfo.close) {
6243
+ var anchorMatch = idRe.exec(token.text) || htmlTagInfo.name.toLowerCase() === "a" && nameRe.exec(token.text);
6244
+ if (anchorMatch) {
6245
+ fragments.set("#".concat(anchorMatch[1]), 0);
6246
+ }
6280
6247
  }
6281
- var idLower = id.toLowerCase();
6282
- var mixedCaseKey = _toConsumableArray(fragments.keys()).find(function (key) {
6283
- return idLower === key.toLowerCase();
6284
- });
6285
- if (mixedCaseKey) {
6286
- (fixInfo || {}).insertText = mixedCaseKey;
6287
- addErrorDetailIf(onError, lineNumber, mixedCaseKey, id, undefined, context, range, fixInfo);
6288
- } else {
6289
- addError(onError, lineNumber, undefined, context,
6290
- // @ts-ignore
6291
- range);
6248
+ }
6249
+
6250
+ // Process link and definition fragments
6251
+ } catch (err) {
6252
+ _iterator2.e(err);
6253
+ } finally {
6254
+ _iterator2.f();
6255
+ }
6256
+ var parentChilds = [["link", "resourceDestinationString"], ["definition", "definitionDestinationString"]];
6257
+ for (var _i = 0, _parentChilds = parentChilds; _i < _parentChilds.length; _i++) {
6258
+ var _parentChilds$_i = _slicedToArray(_parentChilds[_i], 2),
6259
+ parentType = _parentChilds$_i[0],
6260
+ definitionType = _parentChilds$_i[1];
6261
+ var links = filterByTypes(tokens, [parentType]);
6262
+ var _iterator3 = _createForOfIteratorHelper(links),
6263
+ _step3;
6264
+ try {
6265
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
6266
+ var link = _step3.value;
6267
+ var definitions = filterByTypes(link.children, [definitionType]);
6268
+ var _iterator4 = _createForOfIteratorHelper(definitions),
6269
+ _step4;
6270
+ try {
6271
+ var _loop = function _loop() {
6272
+ var definition = _step4.value;
6273
+ if (definition.text.length > 1 && definition.text.startsWith("#") && !fragments.has(definition.text)) {
6274
+ // eslint-disable-next-line no-undef-init
6275
+ var context = undefined;
6276
+ // eslint-disable-next-line no-undef-init
6277
+ var range = undefined;
6278
+ // eslint-disable-next-line no-undef-init
6279
+ var fixInfo = undefined;
6280
+ if (link.startLine === link.endLine) {
6281
+ context = link.text;
6282
+ range = [link.startColumn, link.endColumn - link.startColumn];
6283
+ fixInfo = {
6284
+ "editColumn": definition.startColumn,
6285
+ "deleteCount": definition.endColumn - definition.startColumn
6286
+ };
6287
+ }
6288
+ var definitionTextLower = definition.text.toLowerCase();
6289
+ var mixedCaseKey = _toConsumableArray(fragments.keys()).find(function (key) {
6290
+ return definitionTextLower === key.toLowerCase();
6291
+ });
6292
+ if (mixedCaseKey) {
6293
+ // @ts-ignore
6294
+ (fixInfo || {}).insertText = mixedCaseKey;
6295
+ addErrorDetailIf(onError, link.startLine, mixedCaseKey, definition.text, undefined, context, range, fixInfo);
6296
+ } else {
6297
+ addError(onError, link.startLine, undefined, context, range);
6298
+ }
6299
+ }
6300
+ };
6301
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
6302
+ _loop();
6303
+ }
6304
+ } catch (err) {
6305
+ _iterator4.e(err);
6306
+ } finally {
6307
+ _iterator4.f();
6308
+ }
6292
6309
  }
6310
+ } catch (err) {
6311
+ _iterator3.e(err);
6312
+ } finally {
6313
+ _iterator3.f();
6293
6314
  }
6294
- });
6315
+ }
6295
6316
  }
6296
6317
  };
6297
6318