markdownlint 0.28.2 → 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.28.2 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;
@@ -1165,61 +976,6 @@ function applyFixes(input, errors) {
1165
976
  }
1166
977
  module.exports.applyFixes = applyFixes;
1167
978
 
1168
- /**
1169
- * Gets the range and fixInfo values for reporting an error if the expected
1170
- * text is found on the specified line.
1171
- *
1172
- * @param {string[]} lines Lines of Markdown content.
1173
- * @param {number} lineIndex Line index to check.
1174
- * @param {string} search Text to search for.
1175
- * @param {string} replace Text to replace with.
1176
- * @param {number} [instance] Instance on the line (1-based).
1177
- * @returns {Object} Range and fixInfo wrapper.
1178
- */
1179
- module.exports.getRangeAndFixInfoIfFound = function (lines, lineIndex, search, replace) {
1180
- var instance = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
1181
- var range = null;
1182
- var fixInfo = null;
1183
- var searchIndex = -1;
1184
- while (instance > 0) {
1185
- searchIndex = lines[lineIndex].indexOf(search, searchIndex + 1);
1186
- instance--;
1187
- }
1188
- if (searchIndex !== -1) {
1189
- var column = searchIndex + 1;
1190
- var length = search.length;
1191
- range = [column, length];
1192
- fixInfo = {
1193
- "editColumn": column,
1194
- "deleteCount": length,
1195
- "insertText": replace
1196
- };
1197
- }
1198
- return {
1199
- range: range,
1200
- fixInfo: fixInfo
1201
- };
1202
- };
1203
-
1204
- /**
1205
- * Gets the next (subsequent) child token if it is of the expected type.
1206
- *
1207
- * @param {Object} parentToken Parent token.
1208
- * @param {Object} childToken Child token basis.
1209
- * @param {string} nextType Token type of next token.
1210
- * @param {string} nextNextType Token type of next-next token.
1211
- * @returns {Object} Next token.
1212
- */
1213
- function getNextChildToken(parentToken, childToken, nextType, nextNextType) {
1214
- var children = parentToken.children;
1215
- var index = children.indexOf(childToken);
1216
- if (index !== -1 && children.length > index + 2 && children[index + 1].type === nextType && children[index + 2].type === nextNextType) {
1217
- return children[index + 1];
1218
- }
1219
- return null;
1220
- }
1221
- module.exports.getNextChildToken = getNextChildToken;
1222
-
1223
979
  /**
1224
980
  * Expands a path with a tilde to an absolute path.
1225
981
  *
@@ -1235,6 +991,23 @@ module.exports.expandTildePath = expandTildePath;
1235
991
 
1236
992
  /***/ }),
1237
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
+
1238
1011
  /***/ "markdown-it":
1239
1012
  /*!*****************************!*\
1240
1013
  !*** external "markdownit" ***!
@@ -1337,10 +1110,16 @@ module.exports = {
1337
1110
 
1338
1111
 
1339
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); }
1340
1114
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
1341
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."); }
1342
1116
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
1343
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); }
1344
1123
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
1345
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."); }
1346
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; } }
@@ -1352,9 +1131,12 @@ var _require = __webpack_require__(/*! markdownlint-micromark */ "markdownlint-m
1352
1131
  gfmAutolinkLiteral = _require.gfmAutolinkLiteral,
1353
1132
  gfmFootnote = _require.gfmFootnote,
1354
1133
  gfmTable = _require.gfmTable,
1134
+ math = _require.math,
1355
1135
  parse = _require.parse,
1356
1136
  postprocess = _require.postprocess,
1357
1137
  preprocess = _require.preprocess;
1138
+ var _require2 = __webpack_require__(/*! ./shared.js */ "../helpers/shared.js"),
1139
+ newLineRe = _require2.newLineRe;
1358
1140
 
1359
1141
  /**
1360
1142
  * Markdown token.
@@ -1367,29 +1149,34 @@ var _require = __webpack_require__(/*! markdownlint-micromark */ "markdownlint-m
1367
1149
  * @property {number} endColumn End column (1-based).
1368
1150
  * @property {string} text Token text.
1369
1151
  * @property {Token[]} children Child tokens.
1152
+ * @property {Token[]} [htmlFlowChildren] Child tokens for htmlFlow.
1370
1153
  */
1371
1154
 
1372
1155
  /**
1373
1156
  * Parses a Markdown document and returns Micromark events.
1374
1157
  *
1375
1158
  * @param {string} markdown Markdown document.
1376
- * @param {Object} [options] Options for micromark.
1159
+ * @param {Object} [micromarkOptions] Options for micromark.
1160
+ * @param {boolean} [referencesDefined] Treat references as defined.
1377
1161
  * @returns {Object[]} Micromark events.
1378
1162
  */
1379
1163
  function getMicromarkEvents(markdown) {
1380
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1164
+ var micromarkOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1165
+ var referencesDefined = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
1381
1166
  // Customize options object to add useful extensions
1382
- options.extensions = options.extensions || [];
1383
- options.extensions.push(gfmAutolinkLiteral, gfmFootnote(), gfmTable);
1167
+ micromarkOptions.extensions = micromarkOptions.extensions || [];
1168
+ micromarkOptions.extensions.push(gfmAutolinkLiteral(), gfmFootnote(), gfmTable(), math());
1384
1169
 
1385
1170
  // Use micromark to parse document into Events
1386
1171
  var encoding = undefined;
1387
1172
  var eol = true;
1388
- var parseContext = parse(options);
1389
- // Customize ParseContext to treat all references as defined
1390
- parseContext.defined.includes = function (searchElement) {
1391
- return searchElement.length > 0;
1392
- };
1173
+ var parseContext = parse(micromarkOptions);
1174
+ if (referencesDefined) {
1175
+ // Customize ParseContext to treat all references as defined
1176
+ parseContext.defined.includes = function (searchElement) {
1177
+ return searchElement.length > 0;
1178
+ };
1179
+ }
1393
1180
  var chunks = preprocess()(markdown, encoding, eol);
1394
1181
  var events = postprocess(parseContext.document().write(chunks));
1395
1182
  return events;
@@ -1399,13 +1186,14 @@ function getMicromarkEvents(markdown) {
1399
1186
  * Parses a Markdown document and returns (frozen) tokens.
1400
1187
  *
1401
1188
  * @param {string} markdown Markdown document.
1402
- * @param {Object} [options] Options for micromark.
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.
1403
1192
  * @returns {Token[]} Micromark tokens (frozen).
1404
1193
  */
1405
- function micromarkParse(markdown) {
1406
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1194
+ function micromarkParseWithOffset(markdown, micromarkOptions, referencesDefined, lineDelta) {
1407
1195
  // Use micromark to parse document into Events
1408
- var events = getMicromarkEvents(markdown, options);
1196
+ var events = getMicromarkEvents(markdown, micromarkOptions, referencesDefined);
1409
1197
 
1410
1198
  // Create Token objects
1411
1199
  var document = [];
@@ -1413,6 +1201,8 @@ function micromarkParse(markdown) {
1413
1201
  "children": document
1414
1202
  };
1415
1203
  var history = [current];
1204
+ var reparseOptions = null;
1205
+ var lines = null;
1416
1206
  var _iterator = _createForOfIteratorHelper(events),
1417
1207
  _step;
1418
1208
  try {
@@ -1429,24 +1219,33 @@ function micromarkParse(markdown) {
1429
1219
  startLine = start["line"];
1430
1220
  var endColumn = end["column"],
1431
1221
  endLine = end["line"];
1432
- var text = null;
1433
- try {
1434
- text = context.sliceSerialize(token);
1435
- } catch (_unused) {
1436
- // https://github.com/micromark/micromark/issues/131
1437
- }
1222
+ var text = context.sliceSerialize(token);
1438
1223
  if (kind === "enter") {
1439
1224
  var previous = current;
1440
1225
  history.push(previous);
1441
1226
  current = {
1442
1227
  type: type,
1443
- startLine: startLine,
1228
+ "startLine": startLine + lineDelta,
1444
1229
  startColumn: startColumn,
1445
- endLine: endLine,
1230
+ "endLine": endLine + lineDelta,
1446
1231
  endColumn: endColumn,
1447
1232
  text: text,
1448
1233
  "children": []
1449
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
+ }
1450
1249
  previous.children.push(current);
1451
1250
  } else if (kind === "exit") {
1452
1251
  Object.freeze(current.children);
@@ -1467,11 +1266,25 @@ function micromarkParse(markdown) {
1467
1266
  }
1468
1267
 
1469
1268
  /**
1470
- * Filter a list of Micromark tokens by predicate.
1269
+ * Parses a Markdown document and returns (frozen) tokens.
1471
1270
  *
1472
- * @param {Token[]} tokens Micromark tokens.
1473
- * @param {Function} allowed Allowed token predicate.
1474
- * @param {Function} [transformChildren] Transform children predicate.
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
+ }
1281
+
1282
+ /**
1283
+ * Filter a list of Micromark tokens by predicate.
1284
+ *
1285
+ * @param {Token[]} tokens Micromark tokens.
1286
+ * @param {Function} allowed Allowed token predicate.
1287
+ * @param {Function} [transformChildren] Transform children predicate.
1475
1288
  * @returns {Token[]} Filtered tokens.
1476
1289
  */
1477
1290
  function filterByPredicate(tokens, allowed, transformChildren) {
@@ -1503,6 +1316,74 @@ function filterByTypes(tokens, allowed) {
1503
1316
  });
1504
1317
  }
1505
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
+
1506
1387
  /**
1507
1388
  * Gets information about the tag in an HTML token.
1508
1389
  *
@@ -1563,14 +1444,29 @@ function matchAndGetTokensByType(tokens, matchTypes, resultTypes) {
1563
1444
  }
1564
1445
  return result;
1565
1446
  }
1447
+
1448
+ /**
1449
+ * Returns the specified token iff it is of the desired type.
1450
+ *
1451
+ * @param {Token} token Micromark token candidate.
1452
+ * @param {string} type Desired type.
1453
+ * @returns {Token | null} Token instance.
1454
+ */
1455
+ function tokenIfType(token, type) {
1456
+ return token && token.type === type ? token : null;
1457
+ }
1566
1458
  module.exports = {
1567
1459
  "parse": micromarkParse,
1460
+ filterByHtmlTokens: filterByHtmlTokens,
1568
1461
  filterByPredicate: filterByPredicate,
1569
1462
  filterByTypes: filterByTypes,
1463
+ flattenedChildren: flattenedChildren,
1464
+ getHeadingLevel: getHeadingLevel,
1570
1465
  getHtmlTagInfo: getHtmlTagInfo,
1571
1466
  getMicromarkEvents: getMicromarkEvents,
1572
1467
  getTokenTextByType: getTokenTextByType,
1573
- matchAndGetTokensByType: matchAndGetTokensByType
1468
+ matchAndGetTokensByType: matchAndGetTokensByType,
1469
+ tokenIfType: tokenIfType
1574
1470
  };
1575
1471
 
1576
1472
  /***/ }),
@@ -1610,9 +1506,6 @@ module.exports.codeBlockAndSpanRanges = function () {
1610
1506
  module.exports.flattenedLists = function () {
1611
1507
  return map.get("flattenedLists");
1612
1508
  };
1613
- module.exports.htmlElementRanges = function () {
1614
- return map.get("htmlElementRanges");
1615
- };
1616
1509
  module.exports.lineMetadata = function () {
1617
1510
  return map.get("lineMetadata");
1618
1511
  };
@@ -1636,7 +1529,7 @@ module.exports.referenceLinkImageData = function () {
1636
1529
  module.exports.deprecatedRuleNames = ["MD002", "MD006"];
1637
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"];
1638
1531
  module.exports.homepage = "https://github.com/DavidAnson/markdownlint";
1639
- module.exports.version = "0.28.2";
1532
+ module.exports.version = "0.30.0";
1640
1533
 
1641
1534
  /***/ }),
1642
1535
 
@@ -1725,7 +1618,7 @@ function validateRuleList(ruleList, synchronous) {
1725
1618
  result = newError(_property);
1726
1619
  }
1727
1620
  }
1728
- if (!result && rule.information && Object.getPrototypeOf(rule.information) !== URL.prototype) {
1621
+ if (!result && rule.information && !helpers.isUrl(rule.information)) {
1729
1622
  result = newError("information");
1730
1623
  }
1731
1624
  if (!result && rule.asynchronous !== undefined && typeof rule.asynchronous !== "boolean") {
@@ -2290,7 +2183,7 @@ function getEnabledRulesPerLineNumber(ruleList, lines, frontMatterLines, noInlin
2290
2183
  var disableNextLine = action === "DISABLE-NEXT-LINE";
2291
2184
  if (disableLine || disableNextLine) {
2292
2185
  var nextLineNumber = frontMatterLines.length + lineNumber + (disableNextLine ? 1 : 0);
2293
- enabledRulesPerLineNumber[nextLineNumber] = applyEnableDisable(action, parameter, enabledRulesPerLineNumber[nextLineNumber] || {});
2186
+ enabledRulesPerLineNumber[nextLineNumber] = applyEnableDisable(action, parameter, enabledRulesPerLineNumber[nextLineNumber]);
2294
2187
  }
2295
2188
  }
2296
2189
  // Handle inline comments
@@ -2377,12 +2270,10 @@ function lintContent(ruleList, aliasToRuleNames, name, content, md, config, conf
2377
2270
  var lineMetadata = helpers.getLineMetadata(paramsBase);
2378
2271
  var codeBlockAndSpanRanges = helpers.codeBlockAndSpanRanges(paramsBase, lineMetadata);
2379
2272
  var flattenedLists = helpers.flattenLists(paramsBase.parsers.markdownit.tokens);
2380
- var htmlElementRanges = helpers.htmlElementRanges(paramsBase, lineMetadata);
2381
2273
  var referenceLinkImageData = helpers.getReferenceLinkImageData(paramsBase);
2382
2274
  cache.set({
2383
2275
  codeBlockAndSpanRanges: codeBlockAndSpanRanges,
2384
2276
  flattenedLists: flattenedLists,
2385
- htmlElementRanges: htmlElementRanges,
2386
2277
  lineMetadata: lineMetadata,
2387
2278
  referenceLinkImageData: referenceLinkImageData
2388
2279
  });
@@ -2414,6 +2305,9 @@ function lintContent(ruleList, aliasToRuleNames, name, content, md, config, conf
2414
2305
  if (errorInfo.context && !helpers.isString(errorInfo.context)) {
2415
2306
  throwError("context");
2416
2307
  }
2308
+ if (errorInfo.information && !helpers.isUrl(errorInfo.information)) {
2309
+ throwError("information");
2310
+ }
2417
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)) {
2418
2312
  throwError("range");
2419
2313
  }
@@ -2449,12 +2343,13 @@ function lintContent(ruleList, aliasToRuleNames, name, content, md, config, conf
2449
2343
  cleanFixInfo.insertText = fixInfo.insertText;
2450
2344
  }
2451
2345
  }
2346
+ var information = errorInfo.information || rule.information;
2452
2347
  results.push({
2453
2348
  lineNumber: lineNumber,
2454
2349
  "ruleName": rule.names[0],
2455
2350
  "ruleNames": rule.names,
2456
2351
  "ruleDescription": rule.description,
2457
- "ruleInformation": rule.information ? rule.information.href : null,
2352
+ "ruleInformation": information ? information.href : null,
2458
2353
  "errorDetail": errorInfo.detail || null,
2459
2354
  "errorContext": errorInfo.context || null,
2460
2355
  "errorRange": errorInfo.range ? _toConsumableArray(errorInfo.range) : null,
@@ -2632,8 +2527,18 @@ function lintInput(options, synchronous, callback) {
2632
2527
  // Normalize inputs
2633
2528
  options = options || {};
2634
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
+ });
2635
2540
  // eslint-disable-next-line unicorn/prefer-spread
2636
- var ruleList = rules.concat(options.customRules || []);
2541
+ var ruleList = rules.concat(customRuleList);
2637
2542
  var ruleErr = validateRuleList(ruleList, synchronous);
2638
2543
  if (ruleErr) {
2639
2544
  callback(ruleErr);
@@ -3049,6 +2954,7 @@ module.exports = markdownlint;
3049
2954
  * @property {number} lineNumber Line number (1-based).
3050
2955
  * @property {string} [detail] Detail about the error.
3051
2956
  * @property {string} [context] Context for the error.
2957
+ * @property {URL} [information] Link to more information.
3052
2958
  * @property {number[]} [range] Column number (1-based) and length.
3053
2959
  * @property {RuleOnErrorFixInfo} [fixInfo] Fix information.
3054
2960
  */
@@ -4258,15 +4164,50 @@ module.exports = {
4258
4164
 
4259
4165
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4260
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."); }
4261
- 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); }
4262
- 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; }
4263
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; } }
4264
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; } } }; }
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); }
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; }
4265
4176
  var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
4266
4177
  addErrorDetailIf = _require.addErrorDetailIf,
4267
4178
  blockquotePrefixRe = _require.blockquotePrefixRe,
4268
- filterTokens = _require.filterTokens,
4269
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
+ };
4270
4211
  var getBlockQuote = function getBlockQuote(str, count) {
4271
4212
  return (str || "").match(blockquotePrefixRe)[0].trimEnd()
4272
4213
  // eslint-disable-next-line unicorn/prefer-spread
@@ -4277,35 +4218,50 @@ module.exports = {
4277
4218
  "description": "Headings should be surrounded by blank lines",
4278
4219
  "tags": ["headings", "headers", "blank_lines"],
4279
4220
  "function": function MD022(params, onError) {
4280
- var linesAbove = params.config.lines_above;
4281
- linesAbove = Number(linesAbove === undefined ? 1 : linesAbove);
4282
- var linesBelow = params.config.lines_below;
4283
- linesBelow = Number(linesBelow === undefined ? 1 : linesBelow);
4284
- var lines = params.lines;
4285
- filterTokens(params, "heading_open", function (token) {
4286
- var _token$map = _slicedToArray(token.map, 2),
4287
- topIndex = _token$map[0],
4288
- nextIndex = _token$map[1];
4289
- var actualAbove = 0;
4290
- for (var i = 0; i < linesAbove; i++) {
4291
- if (isBlankLine(lines[topIndex - i - 1])) {
4292
- 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
+ });
4293
4245
  }
4294
- }
4295
- addErrorDetailIf(onError, topIndex + 1, linesAbove, actualAbove, "Above", lines[topIndex].trim(), null, {
4296
- "insertText": getBlockQuote(lines[topIndex - 1], linesAbove - actualAbove)
4297
- });
4298
- var actualBelow = 0;
4299
- for (var _i2 = 0; _i2 < linesBelow; _i2++) {
4300
- if (isBlankLine(lines[nextIndex + _i2])) {
4301
- 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
+ });
4302
4258
  }
4303
4259
  }
4304
- addErrorDetailIf(onError, topIndex + 1, linesBelow, actualBelow, "Below", lines[topIndex].trim(), null, {
4305
- "lineNumber": nextIndex + 1,
4306
- "insertText": getBlockQuote(lines[nextIndex], linesBelow - actualBelow)
4307
- });
4308
- });
4260
+ } catch (err) {
4261
+ _iterator2.e(err);
4262
+ } finally {
4263
+ _iterator2.f();
4264
+ }
4309
4265
  }
4310
4266
  };
4311
4267
 
@@ -4457,12 +4413,17 @@ module.exports = {
4457
4413
 
4458
4414
 
4459
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; }
4460
4419
  var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
4461
4420
  addError = _require.addError,
4462
4421
  allPunctuationNoQuestion = _require.allPunctuationNoQuestion,
4463
- escapeForRegExp = _require.escapeForRegExp,
4464
- forEachHeading = _require.forEachHeading;
4465
- 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;
4466
4427
  module.exports = {
4467
4428
  "names": ["MD026", "no-trailing-punctuation"],
4468
4429
  "description": "Trailing punctuation in heading",
@@ -4471,21 +4432,31 @@ module.exports = {
4471
4432
  var punctuation = params.config.punctuation;
4472
4433
  punctuation = String(punctuation === undefined ? allPunctuationNoQuestion : punctuation);
4473
4434
  var trailingPunctuationRe = new RegExp("\\s*[" + escapeForRegExp(punctuation) + "]+$");
4474
- forEachHeading(params, function (heading) {
4475
- var line = heading.line,
4476
- lineNumber = heading.lineNumber;
4477
- var trimmedLine = line.replace(/([^\s#])[\s#]+$/, "$1");
4478
- var match = trailingPunctuationRe.exec(trimmedLine);
4479
- if (match && !endOfLineHtmlEntityRe.test(trimmedLine)) {
4480
- var fullMatch = match[0];
4481
- var column = match.index + 1;
4482
- var length = fullMatch.length;
4483
- addError(onError, lineNumber, "Punctuation: '".concat(fullMatch, "'"), null, [column, length], {
4484
- "editColumn": column,
4485
- "deleteCount": length
4486
- });
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
+ }
4487
4454
  }
4488
- });
4455
+ } catch (err) {
4456
+ _iterator.e(err);
4457
+ } finally {
4458
+ _iterator.f();
4459
+ }
4489
4460
  }
4490
4461
  };
4491
4462
 
@@ -4866,38 +4837,66 @@ var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
4866
4837
  addErrorContext = _require.addErrorContext,
4867
4838
  blockquotePrefixRe = _require.blockquotePrefixRe,
4868
4839
  isBlankLine = _require.isBlankLine;
4869
- var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"),
4870
- 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
+ };
4871
4855
  module.exports = {
4872
4856
  "names": ["MD032", "blanks-around-lists"],
4873
4857
  "description": "Lists should be surrounded by blank lines",
4874
4858
  "tags": ["bullet", "ul", "ol", "blank_lines"],
4875
4859
  "function": function MD032(params, onError) {
4876
- var lines = params.lines;
4877
- var filteredLists = flattenedLists().filter(function (list) {
4878
- 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;
4879
4866
  });
4880
- var _iterator = _createForOfIteratorHelper(filteredLists),
4867
+ var _iterator = _createForOfIteratorHelper(topLevelLists),
4881
4868
  _step;
4882
4869
  try {
4883
4870
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
4884
4871
  var list = _step.value;
4885
- var firstIndex = list.open.map[0];
4872
+ // Look for a blank line above the list
4873
+ var firstIndex = list.startLine - 1;
4886
4874
  if (!isBlankLine(lines[firstIndex - 1])) {
4887
- var line = lines[firstIndex];
4888
- var quotePrefix = line.match(blockquotePrefixRe)[0].trimEnd();
4889
- addErrorContext(onError, firstIndex + 1, line.trim(), null, null, null, {
4890
- "insertText": "".concat(quotePrefix, "\n")
4891
- });
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();
4892
4896
  }
4893
- var lastIndex = list.lastLineIndex - 1;
4897
+ var lastIndex = endLine - 1;
4894
4898
  if (!isBlankLine(lines[lastIndex + 1])) {
4895
- var _line = lines[lastIndex];
4896
- var _quotePrefix = _line.match(blockquotePrefixRe)[0].trimEnd();
4897
- addErrorContext(onError, lastIndex + 1, _line.trim(), null, null, null, {
4898
- "lineNumber": lastIndex + 2,
4899
- "insertText": "".concat(_quotePrefix, "\n")
4900
- });
4899
+ addBlankLineError(onError, lines, lastIndex, lastIndex + 2);
4901
4900
  }
4902
4901
  }
4903
4902
  } catch (err) {
@@ -4921,19 +4920,14 @@ module.exports = {
4921
4920
 
4922
4921
 
4923
4922
 
4924
- 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; } } }; }
4925
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4926
- 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; } } }; }
4927
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); }
4928
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; }
4929
- 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; } }
4930
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
4931
4926
  var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
4932
4927
  addError = _require.addError;
4933
4928
  var _require2 = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs"),
4934
- filterByTypes = _require2.filterByTypes,
4935
- getHtmlTagInfo = _require2.getHtmlTagInfo,
4936
- parse = _require2.parse;
4929
+ filterByHtmlTokens = _require2.filterByHtmlTokens,
4930
+ getHtmlTagInfo = _require2.getHtmlTagInfo;
4937
4931
  var nextLinesRe = /[\r\n][\s\S]*$/;
4938
4932
  module.exports = {
4939
4933
  "names": ["MD033", "no-inline-html"],
@@ -4945,45 +4939,21 @@ module.exports = {
4945
4939
  allowedElements = allowedElements.map(function (element) {
4946
4940
  return element.toLowerCase();
4947
4941
  });
4948
- var pending = [[0, params.parsers.micromark.tokens]];
4949
- var current = null;
4950
- while (current = pending.shift()) {
4951
- var _current = current,
4952
- _current2 = _slicedToArray(_current, 2),
4953
- offset = _current2[0],
4954
- tokens = _current2[1];
4955
- var _iterator = _createForOfIteratorHelper(filterByTypes(tokens, ["htmlFlow", "htmlText"])),
4956
- _step;
4957
- try {
4958
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
4959
- var token = _step.value;
4960
- if (token.type === "htmlText") {
4961
- var htmlTagInfo = getHtmlTagInfo(token);
4962
- if (htmlTagInfo && !htmlTagInfo.close && !allowedElements.includes(htmlTagInfo.name.toLowerCase())) {
4963
- var range = [token.startColumn, token.text.replace(nextLinesRe, "").length];
4964
- addError(onError, token.startLine + offset, "Element: " + htmlTagInfo.name, undefined, range);
4965
- }
4966
- } else {
4967
- // token.type === "htmlFlow"
4968
- // Re-parse without "htmlFlow" to get only "htmlText" tokens
4969
- var options = {
4970
- "extensions": [{
4971
- "disable": {
4972
- "null": ["codeIndented", "htmlFlow"]
4973
- }
4974
- }]
4975
- };
4976
- // Use lines instead of token.text for accurate columns
4977
- var lines = params.lines.slice(token.startLine - 1, token.endLine).join("\n");
4978
- var flowTokens = parse(lines, options);
4979
- pending.push([token.startLine - 1, flowTokens]);
4980
- }
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);
4981
4951
  }
4982
- } catch (err) {
4983
- _iterator.e(err);
4984
- } finally {
4985
- _iterator.f();
4986
4952
  }
4953
+ } catch (err) {
4954
+ _iterator.e(err);
4955
+ } finally {
4956
+ _iterator.f();
4987
4957
  }
4988
4958
  }
4989
4959
  };
@@ -5008,60 +4978,68 @@ var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
5008
4978
  addErrorContext = _require.addErrorContext;
5009
4979
  var _require2 = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs"),
5010
4980
  filterByPredicate = _require2.filterByPredicate,
5011
- getHtmlTagInfo = _require2.getHtmlTagInfo;
4981
+ getHtmlTagInfo = _require2.getHtmlTagInfo,
4982
+ parse = _require2.parse;
5012
4983
  module.exports = {
5013
4984
  "names": ["MD034", "no-bare-urls"],
5014
4985
  "description": "Bare URL used",
5015
4986
  "tags": ["links", "url"],
5016
4987
  "function": function MD034(params, onError) {
5017
- var literalAutolinks = filterByPredicate(params.parsers.micromark.tokens, function (token) {
5018
- return token.type === "literalAutolink";
5019
- }, function (token) {
5020
- var children = token.children;
5021
- var result = [];
5022
- for (var i = 0; i < children.length; i++) {
5023
- var openToken = children[i];
5024
- var openTagInfo = getHtmlTagInfo(openToken);
5025
- if (openTagInfo && !openTagInfo.close) {
5026
- var count = 1;
5027
- for (var j = i + 1; j < children.length; j++) {
5028
- var closeToken = children[j];
5029
- var closeTagInfo = getHtmlTagInfo(closeToken);
5030
- if (closeTagInfo && openTagInfo.name === closeTagInfo.name) {
5031
- if (closeTagInfo.close) {
5032
- count--;
5033
- if (count === 0) {
5034
- i = j;
5035
- break;
4988
+ var literalAutolinks = function literalAutolinks(tokens) {
4989
+ return filterByPredicate(tokens, function (token) {
4990
+ return token.type === "literalAutolink";
4991
+ }, function (token) {
4992
+ var children = token.children;
4993
+ var result = [];
4994
+ for (var i = 0; i < children.length; i++) {
4995
+ var openToken = children[i];
4996
+ var openTagInfo = getHtmlTagInfo(openToken);
4997
+ if (openTagInfo && !openTagInfo.close) {
4998
+ var count = 1;
4999
+ for (var j = i + 1; j < children.length; j++) {
5000
+ var closeToken = children[j];
5001
+ var closeTagInfo = getHtmlTagInfo(closeToken);
5002
+ if (closeTagInfo && openTagInfo.name === closeTagInfo.name) {
5003
+ if (closeTagInfo.close) {
5004
+ count--;
5005
+ if (count === 0) {
5006
+ i = j;
5007
+ break;
5008
+ }
5009
+ } else {
5010
+ count++;
5036
5011
  }
5037
- } else {
5038
- count++;
5039
5012
  }
5040
5013
  }
5014
+ } else {
5015
+ result.push(openToken);
5041
5016
  }
5042
- } else {
5043
- result.push(openToken);
5044
5017
  }
5018
+ return result;
5019
+ });
5020
+ };
5021
+ if (literalAutolinks(params.parsers.micromark.tokens).length > 0) {
5022
+ // Re-parse with correct link/image reference definition handling
5023
+ var document = params.lines.join("\n");
5024
+ var tokens = parse(document, undefined, false);
5025
+ var _iterator = _createForOfIteratorHelper(literalAutolinks(tokens)),
5026
+ _step;
5027
+ try {
5028
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
5029
+ var token = _step.value;
5030
+ var range = [token.startColumn, token.endColumn - token.startColumn];
5031
+ var fixInfo = {
5032
+ "editColumn": range[0],
5033
+ "deleteCount": range[1],
5034
+ "insertText": "<".concat(token.text, ">")
5035
+ };
5036
+ addErrorContext(onError, token.startLine, token.text, null, null, range, fixInfo);
5037
+ }
5038
+ } catch (err) {
5039
+ _iterator.e(err);
5040
+ } finally {
5041
+ _iterator.f();
5045
5042
  }
5046
- return result;
5047
- });
5048
- var _iterator = _createForOfIteratorHelper(literalAutolinks),
5049
- _step;
5050
- try {
5051
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
5052
- var token = _step.value;
5053
- var range = [token.startColumn, token.endColumn - token.startColumn];
5054
- var fixInfo = {
5055
- "editColumn": range[0],
5056
- "deleteCount": range[1],
5057
- "insertText": "<".concat(token.text, ">")
5058
- };
5059
- addErrorContext(onError, token.startLine, token.text, null, null, range, fixInfo);
5060
- }
5061
- } catch (err) {
5062
- _iterator.e(err);
5063
- } finally {
5064
- _iterator.f();
5065
5043
  }
5066
5044
  }
5067
5045
  };
@@ -5199,6 +5177,11 @@ module.exports = {
5199
5177
 
5200
5178
 
5201
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; } } }; }
5202
5185
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
5203
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."); }
5204
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); }
@@ -5206,151 +5189,113 @@ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symb
5206
5189
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
5207
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; }
5208
5191
  var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
5209
- addErrorContext = _require.addErrorContext,
5210
- emphasisMarkersInContent = _require.emphasisMarkersInContent,
5211
- forEachLine = _require.forEachLine,
5212
- isBlankLine = _require.isBlankLine,
5213
- withinAnyRange = _require.withinAnyRange;
5214
- var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"),
5215
- htmlElementRanges = _require2.htmlElementRanges,
5216
- lineMetadata = _require2.lineMetadata;
5217
- var emphasisRe = /(^|[^\\]|\\\\)(?:(\*{1,3})|(_{1,3}))/g;
5218
- var embeddedUnderscoreRe = /([A-Za-z\d])_([A-Za-z\d])/g;
5219
- var asteriskListItemMarkerRe = /^([\s>]*)\*(\s+)/;
5220
- var leftSpaceRe = /^\s+/;
5221
- var rightSpaceRe = /\s+$/;
5222
- var tablePipeRe = /\|/;
5192
+ addError = _require.addError;
5193
+ var emphasisStartTextRe = /^(\S{1,3})(\s+)\S/;
5194
+ var emphasisEndTextRe = /\S(\s+)(\S{1,3})$/;
5223
5195
  module.exports = {
5224
5196
  "names": ["MD037", "no-space-in-emphasis"],
5225
5197
  "description": "Spaces inside emphasis markers",
5226
5198
  "tags": ["whitespace", "emphasis"],
5227
5199
  "function": function MD037(params, onError) {
5228
- var exclusions = htmlElementRanges();
5229
- // eslint-disable-next-line init-declarations
5230
- var effectiveEmphasisLength,
5231
- emphasisIndex,
5232
- emphasisKind,
5233
- emphasisLength,
5234
- pendingError = null;
5235
- // eslint-disable-next-line jsdoc/require-jsdoc
5236
- function resetRunTracking() {
5237
- emphasisIndex = -1;
5238
- emphasisLength = 0;
5239
- emphasisKind = "";
5240
- effectiveEmphasisLength = 0;
5241
- 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, []);
5242
5207
  }
5243
- // eslint-disable-next-line jsdoc/require-jsdoc
5244
- function handleRunEnd(line, lineIndex, contextLength, match, matchIndex, inTable) {
5245
- // Close current run
5246
- var content = line.substring(emphasisIndex, matchIndex);
5247
- if (!emphasisLength) {
5248
- content = content.trimStart();
5249
- }
5250
- if (!match) {
5251
- 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;
5252
5215
  }
5253
- var leftSpace = leftSpaceRe.test(content);
5254
- var rightSpace = rightSpaceRe.test(content);
5255
- if ((leftSpace || rightSpace) && (!inTable || !tablePipeRe.test(content))) {
5256
- // Report the violation
5257
- var contextStart = emphasisIndex - emphasisLength;
5258
- var contextEnd = matchIndex + contextLength;
5259
- var column = contextStart + 1;
5260
- var length = contextEnd - contextStart;
5261
- if (!withinAnyRange(exclusions, lineIndex, column, length)) {
5262
- var context = line.substring(contextStart, contextEnd);
5263
- var leftMarker = line.substring(contextStart, emphasisIndex);
5264
- var rightMarker = match ? match[2] || match[3] : "";
5265
- var fixedText = "".concat(leftMarker).concat(content.trim()).concat(rightMarker);
5266
- return [onError, lineIndex + 1, context, leftSpace, rightSpace, [column, length], {
5267
- "editColumn": column,
5268
- "deleteCount": length,
5269
- "insertText": fixedText
5270
- }];
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;
5271
5225
  }
5226
+ } catch (err) {
5227
+ _iterator.e(err);
5228
+ } finally {
5229
+ _iterator.f();
5272
5230
  }
5273
- return null;
5274
- }
5275
- // Initialize
5276
- var ignoreMarkersByLine = emphasisMarkersInContent(params);
5277
- resetRunTracking();
5278
- forEachLine(lineMetadata(), function (line, lineIndex, inCode, onFence, inTable, inItem, onBreak, inMath) {
5279
- var onItemStart = inItem === 1;
5280
- if (inCode || onFence || inTable || onBreak || onItemStart || isBlankLine(line)) {
5281
- // Emphasis resets when leaving a block
5282
- resetRunTracking();
5283
- }
5284
- if (inCode || onFence || onBreak || inMath) {
5285
- // Emphasis has no meaning here
5286
- return;
5287
- }
5288
- var patchedLine = line.replace(embeddedUnderscoreRe, "$1 $2");
5289
- if (onItemStart) {
5290
- // Trim overlapping '*' list item marker
5291
- patchedLine = patchedLine.replace(asteriskListItemMarkerRe, "$1 $2");
5292
- }
5293
- var match = null;
5294
- // Match all emphasis-looking runs in the line...
5295
- while (match = emphasisRe.exec(patchedLine)) {
5296
- var ignoreMarkersForLine = ignoreMarkersByLine[lineIndex];
5297
- var matchIndex = match.index + match[1].length;
5298
- if (ignoreMarkersForLine.includes(matchIndex)) {
5299
- // Ignore emphasis markers inside code spans and links
5300
- 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
+ }
5301
5244
  }
5302
- var matchLength = match[0].length - match[1].length;
5303
- var matchKind = (match[2] || match[3])[0];
5304
- if (emphasisIndex === -1) {
5305
- // New run
5306
- emphasisIndex = matchIndex + matchLength;
5307
- emphasisLength = matchLength;
5308
- emphasisKind = matchKind;
5309
- effectiveEmphasisLength = matchLength;
5310
- } else if (matchKind === emphasisKind) {
5311
- // Matching emphasis markers
5312
- if (matchLength === effectiveEmphasisLength) {
5313
- // Ending an existing run, report any pending error
5314
- if (pendingError) {
5315
- // @ts-ignore
5316
- addErrorContext.apply(void 0, _toConsumableArray(pendingError));
5317
- 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
+ }
5318
5273
  }
5319
- var error = handleRunEnd(line, lineIndex, effectiveEmphasisLength, match, matchIndex, inTable);
5320
- if (error) {
5321
- // @ts-ignore
5322
- 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
+ }
5323
5290
  }
5324
- // Reset
5325
- resetRunTracking();
5326
- } else if (matchLength === 3) {
5327
- // Swap internal run length (1->2 or 2->1)
5328
- effectiveEmphasisLength = matchLength - effectiveEmphasisLength;
5329
- } else if (effectiveEmphasisLength === 3) {
5330
- // Downgrade internal run (3->1 or 3->2)
5331
- effectiveEmphasisLength -= matchLength;
5332
- } else {
5333
- // Upgrade to internal run (1->3 or 2->3)
5334
- effectiveEmphasisLength += matchLength;
5335
- }
5336
- // Back up one character so RegExp has a chance to match the
5337
- // next marker (ex: "**star**_underscore_")
5338
- if (emphasisRe.lastIndex > 1) {
5339
- emphasisRe.lastIndex--;
5340
5291
  }
5341
- } else if (emphasisRe.lastIndex > 1) {
5342
- // Back up one character so RegExp has a chance to match the
5343
- // mis-matched marker (ex: "*text_*")
5344
- emphasisRe.lastIndex--;
5345
5292
  }
5293
+ } catch (err) {
5294
+ _iterator3.e(err);
5295
+ } finally {
5296
+ _iterator3.f();
5346
5297
  }
5347
- if (emphasisIndex !== -1) {
5348
- pendingError = pendingError || handleRunEnd(line, lineIndex, 0, null, line.length, inTable);
5349
- // Adjust for pending run on new line
5350
- emphasisIndex = 0;
5351
- emphasisLength = 0;
5352
- }
5353
- });
5298
+ }
5354
5299
  }
5355
5300
  };
5356
5301
 
@@ -5373,7 +5318,8 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
5373
5318
  var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
5374
5319
  addErrorContext = _require.addErrorContext;
5375
5320
  var _require2 = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs"),
5376
- filterByTypes = _require2.filterByTypes;
5321
+ filterByTypes = _require2.filterByTypes,
5322
+ tokenIfType = _require2.tokenIfType;
5377
5323
  var leftSpaceRe = /^\s(?:[^`]|$)/;
5378
5324
  var rightSpaceRe = /[^`]\s$/;
5379
5325
  var trimCodeText = function trimCodeText(text, start, end) {
@@ -5386,9 +5332,6 @@ var trimCodeText = function trimCodeText(text, start, end) {
5386
5332
  }
5387
5333
  return text;
5388
5334
  };
5389
- var tokenIfType = function tokenIfType(token, type) {
5390
- return token && token.type === type && token;
5391
- };
5392
5335
  module.exports = {
5393
5336
  "names": ["MD038", "no-space-in-code"],
5394
5337
  "description": "Spaces inside code span elements",
@@ -5781,20 +5724,21 @@ module.exports = {
5781
5724
 
5782
5725
 
5783
5726
 
5784
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
5785
- 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."); }
5786
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5787
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
5788
5727
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
5789
5728
  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."); }
5790
5729
  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; } }
5791
5730
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
5792
5731
  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; } } }; }
5732
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
5733
+ 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."); }
5793
5734
  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); }
5735
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5736
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
5794
5737
  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; }
5795
5738
  var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
5796
5739
  addErrorDetailIf = _require.addErrorDetailIf,
5797
5740
  escapeForRegExp = _require.escapeForRegExp,
5741
+ newLineRe = _require.newLineRe,
5798
5742
  withinAnyRange = _require.withinAnyRange;
5799
5743
  var _require2 = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs"),
5800
5744
  filterByPredicate = _require2.filterByPredicate,
@@ -5820,12 +5764,39 @@ module.exports = {
5820
5764
  scannedTypes.add("codeFlowValue");
5821
5765
  scannedTypes.add("codeTextData");
5822
5766
  }
5767
+ var tokenAdjustments = new Map();
5823
5768
  var contentTokens = filterByPredicate(params.parsers.micromark.tokens, function (token) {
5824
5769
  return scannedTypes.has(token.type);
5825
5770
  }, function (token) {
5826
5771
  var children = token.children;
5772
+ var startLine = token.startLine,
5773
+ text = token.text;
5827
5774
  if (!includeHtmlElements && token.type === "htmlFlow") {
5828
- children = children.slice(1, -1);
5775
+ if (text.startsWith("<!--")) {
5776
+ // Remove comment content
5777
+ children = [];
5778
+ } else {
5779
+ // Re-parse to get htmlText elements for detailed tokenization
5780
+ var htmlTextLines = "<md044>\n".concat(text, "\n</md044>").split(newLineRe);
5781
+ children = parse(htmlTextLines.join(""));
5782
+ var reTokens = _toConsumableArray(children);
5783
+ var _iterator = _createForOfIteratorHelper(reTokens),
5784
+ _step;
5785
+ try {
5786
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
5787
+ var reToken = _step.value;
5788
+ tokenAdjustments.set(reToken, {
5789
+ htmlTextLines: htmlTextLines,
5790
+ startLine: startLine
5791
+ });
5792
+ reTokens.push.apply(reTokens, _toConsumableArray(reToken.children));
5793
+ }
5794
+ } catch (err) {
5795
+ _iterator.e(err);
5796
+ } finally {
5797
+ _iterator.f();
5798
+ }
5799
+ }
5829
5800
  }
5830
5801
  return children.filter(function (t) {
5831
5802
  return !ignoredChildTypes.has(t.type);
@@ -5833,21 +5804,21 @@ module.exports = {
5833
5804
  });
5834
5805
  var exclusions = [];
5835
5806
  var autoLinked = new Set();
5836
- var _iterator = _createForOfIteratorHelper(names),
5837
- _step;
5807
+ var _iterator2 = _createForOfIteratorHelper(names),
5808
+ _step2;
5838
5809
  try {
5839
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
5840
- var name = _step.value;
5810
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
5811
+ var name = _step2.value;
5841
5812
  var escapedName = escapeForRegExp(name);
5842
5813
  var startNamePattern = /^\W/.test(name) ? "" : "\\b_*";
5843
5814
  var endNamePattern = /\W$/.test(name) ? "" : "_*\\b";
5844
5815
  var namePattern = "(".concat(startNamePattern, ")(").concat(escapedName, ")").concat(endNamePattern);
5845
5816
  var nameRe = new RegExp(namePattern, "gi");
5846
- var _iterator2 = _createForOfIteratorHelper(contentTokens),
5847
- _step2;
5817
+ var _iterator3 = _createForOfIteratorHelper(contentTokens),
5818
+ _step3;
5848
5819
  try {
5849
5820
  var _loop = function _loop() {
5850
- var token = _step2.value;
5821
+ var token = _step3.value;
5851
5822
  var match = null;
5852
5823
  var _loop2 = function _loop2() {
5853
5824
  var _match = match,
@@ -5867,8 +5838,21 @@ module.exports = {
5867
5838
  autoLinked.add(token);
5868
5839
  }
5869
5840
  if (!withinAnyRange(urlRanges, lineIndex, index, length)) {
5870
- var column = index + 1;
5871
- addErrorDetailIf(onError, token.startLine, name, nameMatch, null, null, [column, length], {
5841
+ var lineNumber = token.startLine;
5842
+ var column = index;
5843
+ if (tokenAdjustments.has(token)) {
5844
+ var _tokenAdjustments$get = tokenAdjustments.get(token),
5845
+ htmlTextLines = _tokenAdjustments$get.htmlTextLines,
5846
+ startLine = _tokenAdjustments$get.startLine;
5847
+ var lineDelta = 0;
5848
+ while (htmlTextLines[lineDelta].length <= column) {
5849
+ column -= htmlTextLines[lineDelta].length;
5850
+ lineDelta++;
5851
+ }
5852
+ lineNumber = startLine + lineDelta - 1;
5853
+ }
5854
+ column++;
5855
+ addErrorDetailIf(onError, lineNumber, name, nameMatch, null, null, [column, length], {
5872
5856
  "editColumn": column,
5873
5857
  "deleteCount": length,
5874
5858
  "insertText": name
@@ -5881,19 +5865,19 @@ module.exports = {
5881
5865
  _loop2();
5882
5866
  }
5883
5867
  };
5884
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
5868
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
5885
5869
  _loop();
5886
5870
  }
5887
5871
  } catch (err) {
5888
- _iterator2.e(err);
5872
+ _iterator3.e(err);
5889
5873
  } finally {
5890
- _iterator2.f();
5874
+ _iterator3.f();
5891
5875
  }
5892
5876
  }
5893
5877
  } catch (err) {
5894
- _iterator.e(err);
5878
+ _iterator2.e(err);
5895
5879
  } finally {
5896
- _iterator.f();
5880
+ _iterator2.f();
5897
5881
  }
5898
5882
  }
5899
5883
  };
@@ -5911,19 +5895,37 @@ module.exports = {
5911
5895
 
5912
5896
 
5913
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; }
5914
5901
  var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
5915
- addError = _require.addError,
5916
- forEachInlineChild = _require.forEachInlineChild;
5902
+ addError = _require.addError;
5903
+ var _require2 = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs"),
5904
+ filterByTypes = _require2.filterByTypes;
5917
5905
  module.exports = {
5918
5906
  "names": ["MD045", "no-alt-text"],
5919
5907
  "description": "Images should have alternate text (alt text)",
5920
5908
  "tags": ["accessibility", "images"],
5921
5909
  "function": function MD045(params, onError) {
5922
- forEachInlineChild(params, "image", function forToken(token) {
5923
- if (token.content === "") {
5924
- 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
+ }
5925
5923
  }
5926
- });
5924
+ } catch (err) {
5925
+ _iterator.e(err);
5926
+ } finally {
5927
+ _iterator.f();
5928
+ }
5927
5929
  }
5928
5930
  };
5929
5931
 
@@ -6072,57 +6074,69 @@ module.exports = {
6072
6074
 
6073
6075
 
6074
6076
 
6077
+ 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; } } }; }
6078
+ 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); }
6079
+ 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; }
6075
6080
  var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
6076
6081
  addError = _require.addError,
6077
- emphasisOrStrongStyleFor = _require.emphasisOrStrongStyleFor,
6078
- forEachInlineChild = _require.forEachInlineChild,
6079
- getNextChildToken = _require.getNextChildToken,
6080
- getRangeAndFixInfoIfFound = _require.getRangeAndFixInfoIfFound;
6081
- var impl = function impl(params, onError, tagPrefix, asterisk, underline, style) {
6082
- var lastLineNumber = -1;
6083
- var instances = new Map();
6084
- forEachInlineChild(params, "".concat(tagPrefix, "_open"), function (token, parent) {
6085
- var lineNumber = token.lineNumber,
6086
- markup = token.markup;
6087
- var markupStyle = emphasisOrStrongStyleFor(markup);
6088
- if (style === "consistent") {
6089
- style = markupStyle;
6090
- }
6091
- if (style !== markupStyle) {
6092
- var rangeAndFixInfo = {};
6093
- var contentToken = getNextChildToken(parent, token, "text", "".concat(tagPrefix, "_close"));
6094
- if (contentToken) {
6095
- var content = contentToken.content;
6096
- var actual = "".concat(markup).concat(content).concat(markup);
6097
- var expectedMarkup = style === "asterisk" ? asterisk : underline;
6098
- var expected = "".concat(expectedMarkup).concat(content).concat(expectedMarkup);
6099
- if (lastLineNumber !== lineNumber) {
6100
- lastLineNumber = lineNumber;
6101
- instances.clear();
6082
+ emphasisOrStrongStyleFor = _require.emphasisOrStrongStyleFor;
6083
+ var _require2 = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs"),
6084
+ filterByTypes = _require2.filterByTypes,
6085
+ tokenIfType = _require2.tokenIfType;
6086
+ var intrawordRe = /\w/;
6087
+ var impl = function impl(params, onError, type, asterisk, underline) {
6088
+ var style = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : "consistent";
6089
+ var lines = params.lines,
6090
+ parsers = params.parsers;
6091
+ var emphasisTokens = filterByTypes(parsers.micromark.tokens, [type]);
6092
+ var _iterator = _createForOfIteratorHelper(emphasisTokens),
6093
+ _step;
6094
+ try {
6095
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
6096
+ var token = _step.value;
6097
+ var children = token.children;
6098
+ var childType = "".concat(type, "Sequence");
6099
+ var startSequence = tokenIfType(children[0], childType);
6100
+ var endSequence = tokenIfType(children[children.length - 1], childType);
6101
+ if (startSequence && endSequence) {
6102
+ var markupStyle = emphasisOrStrongStyleFor(startSequence.text);
6103
+ if (style === "consistent") {
6104
+ style = markupStyle;
6105
+ }
6106
+ if (style !== markupStyle) {
6107
+ var underscoreIntraword = style === "underscore" && (intrawordRe.test(lines[startSequence.startLine - 1][startSequence.startColumn - 2]) || intrawordRe.test(lines[endSequence.endLine - 1][endSequence.endColumn - 1]));
6108
+ if (!underscoreIntraword) {
6109
+ for (var _i = 0, _arr = [startSequence, endSequence]; _i < _arr.length; _i++) {
6110
+ var sequence = _arr[_i];
6111
+ addError(onError, sequence.startLine, "Expected: ".concat(style, "; Actual: ").concat(markupStyle), undefined, [sequence.startColumn, sequence.text.length], {
6112
+ "editColumn": sequence.startColumn,
6113
+ "deleteCount": sequence.text.length,
6114
+ "insertText": style === "asterisk" ? asterisk : underline
6115
+ });
6116
+ }
6117
+ }
6102
6118
  }
6103
- var instance = (instances.get(expected) || 0) + 1;
6104
- instances.set(expected, instance);
6105
- rangeAndFixInfo = getRangeAndFixInfoIfFound(params.lines, lineNumber - 1, actual, expected, instance);
6106
6119
  }
6107
- addError(onError, lineNumber, "Expected: ".concat(style, "; Actual: ").concat(markupStyle), null, rangeAndFixInfo.range, rangeAndFixInfo.fixInfo);
6108
6120
  }
6109
- });
6121
+ } catch (err) {
6122
+ _iterator.e(err);
6123
+ } finally {
6124
+ _iterator.f();
6125
+ }
6110
6126
  };
6111
6127
  module.exports = [{
6112
6128
  "names": ["MD049", "emphasis-style"],
6113
6129
  "description": "Emphasis style should be consistent",
6114
6130
  "tags": ["emphasis"],
6115
6131
  "function": function MD049(params, onError) {
6116
- var style = String(params.config.style || "consistent");
6117
- return impl(params, onError, "em", "*", "_", style);
6132
+ return impl(params, onError, "emphasis", "*", "_", params.config.style || undefined);
6118
6133
  }
6119
6134
  }, {
6120
6135
  "names": ["MD050", "strong-style"],
6121
6136
  "description": "Strong style should be consistent",
6122
6137
  "tags": ["emphasis"],
6123
6138
  "function": function MD050(params, onError) {
6124
- var style = String(params.config.style || "consistent");
6125
- return impl(params, onError, "strong", "**", "__", style);
6139
+ return impl(params, onError, "strong", "**", "__", params.config.style || undefined);
6126
6140
  }
6127
6141
  }];
6128
6142
 
@@ -6145,35 +6159,34 @@ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symb
6145
6159
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6146
6160
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6147
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."); }
6148
- 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); }
6149
- 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; }
6150
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; } }
6151
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; }
6152
6167
  var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
6153
6168
  addError = _require.addError,
6154
- addErrorDetailIf = _require.addErrorDetailIf,
6155
- escapeForRegExp = _require.escapeForRegExp,
6156
- filterTokens = _require.filterTokens,
6157
- forEachInlineChild = _require.forEachInlineChild,
6158
- forEachHeading = _require.forEachHeading,
6159
- 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;
6160
6174
 
6161
6175
  // Regular expression for identifying HTML anchor names
6162
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;
6163
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;
6164
6179
 
6165
6180
  /**
6166
6181
  * Converts a Markdown heading into an HTML fragment according to the rules
6167
6182
  * used by GitHub.
6168
6183
  *
6169
- * @param {Object} inline Inline token for heading.
6184
+ * @param {Object} headingText Heading text token.
6170
6185
  * @returns {string} Fragment string for heading.
6171
6186
  */
6172
- function convertHeadingToHTMLFragment(inline) {
6173
- var inlineText = inline.children.filter(function (token) {
6174
- return token.type !== "html_inline";
6175
- }).map(function (token) {
6176
- return token.content;
6187
+ function convertHeadingToHTMLFragment(headingText) {
6188
+ var inlineText = filterByTypes(headingText.children, ["codeTextData", "data"]).map(function (token) {
6189
+ return token.text;
6177
6190
  }).join("");
6178
6191
  return "#" + encodeURIComponent(inlineText.toLowerCase()
6179
6192
  // RegExp source with Ruby's \p{Word} expanded into its General Categories
@@ -6187,72 +6200,119 @@ module.exports = {
6187
6200
  "description": "Link fragments should be valid",
6188
6201
  "tags": ["links"],
6189
6202
  "function": function MD051(params, onError) {
6203
+ var tokens = params.parsers.micromark.tokens;
6190
6204
  var fragments = new Map();
6205
+
6191
6206
  // Process headings
6192
- forEachHeading(params, function (heading, content, inline) {
6193
- var fragment = convertHeadingToHTMLFragment(inline);
6194
- var count = fragments.get(fragment) || 0;
6195
- if (count) {
6196
- fragments.set("".concat(fragment, "-").concat(count), 0);
6197
- }
6198
- fragments.set(fragment, count + 1);
6199
- });
6200
- // Process HTML anchors
6201
- var processHtmlToken = function processHtmlToken(token) {
6202
- var match = null;
6203
- while ((match = htmlElementRe.exec(token.content)) !== null) {
6204
- var _match = match,
6205
- _match2 = _slicedToArray(_match, 3),
6206
- tag = _match2[0],
6207
- element = _match2[2];
6208
- var anchorMatch = idRe.exec(tag) || element.toLowerCase() === "a" && nameRe.exec(tag);
6209
- if (anchorMatch) {
6210
- 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
+ }
6211
6227
  }
6212
6228
  }
6213
- };
6214
- filterTokens(params, "html_block", processHtmlToken);
6215
- forEachInlineChild(params, "html_inline", processHtmlToken);
6216
- // Process link fragments
6217
- forEachInlineChild(params, "link_open", function (token) {
6218
- var attrs = token.attrs,
6219
- lineNumber = token.lineNumber,
6220
- line = token.line;
6221
- var href = attrs.find(function (attr) {
6222
- return attr[0] === "href";
6223
- });
6224
- var id = href && href[1];
6225
- if (id && id.length > 1 && id[0] === "#" && !fragments.has(id)) {
6226
- var context = id;
6227
- var range = null;
6228
- var fixInfo = null;
6229
- var match = line.match(new RegExp("\\[.*?\\]\\(".concat(escapeForRegExp(context), "\\)")));
6230
- if (match) {
6231
- var _match3 = _slicedToArray(match, 1);
6232
- context = _match3[0];
6233
- var index = match.index;
6234
- var length = context.length;
6235
- range = [index + 1, length];
6236
- fixInfo = {
6237
- "editColumn": index + (length - id.length),
6238
- "deleteCount": id.length,
6239
- "insertText": null
6240
- };
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
+ }
6241
6247
  }
6242
- var idLower = id.toLowerCase();
6243
- var mixedCaseKey = _toConsumableArray(fragments.keys()).find(function (key) {
6244
- return idLower === key.toLowerCase();
6245
- });
6246
- if (mixedCaseKey) {
6247
- (fixInfo || {}).insertText = mixedCaseKey;
6248
- addErrorDetailIf(onError, lineNumber, mixedCaseKey, id, undefined, context, range, fixInfo);
6249
- } else {
6250
- addError(onError, lineNumber, undefined, context,
6251
- // @ts-ignore
6252
- 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
+ }
6253
6309
  }
6310
+ } catch (err) {
6311
+ _iterator3.e(err);
6312
+ } finally {
6313
+ _iterator3.f();
6254
6314
  }
6255
- });
6315
+ }
6256
6316
  }
6257
6317
  };
6258
6318