From ac665704a6bd178ad04a12c309ffaccf64cfc071 Mon Sep 17 00:00:00 2001 From: David Anson Date: Tue, 17 Jan 2023 04:19:40 +0000 Subject: [PATCH] Convert demo from using ts-loader to babel-loader for transpiling JavaScript for web browsers (adds support for .cjs, see https://github.com/TypeStrong/ts-loader/pull/1503). --- demo/markdownlint-browser.js | 8270 +++++++++++++++++++--------------- demo/tsconfig.json | 10 - demo/webpack.config.js | 16 +- package.json | 4 +- 4 files changed, 4743 insertions(+), 3557 deletions(-) delete mode 100644 demo/tsconfig.json diff --git a/demo/markdownlint-browser.js b/demo/markdownlint-browser.js index 0e0b17c45..ed10bf158 100644 --- a/demo/markdownlint-browser.js +++ b/demo/markdownlint-browser.js @@ -30,56 +30,85 @@ module.exports = webpackEmptyContext; "use strict"; // @ts-check + + // Regular expression for matching common newline characters // See NEWLINES_RE in markdown-it/lib/rules_core/normalize.js -const newLineRe = /\r\n?|\n/g; +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } +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."); } +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; } } +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } +function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } +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."); } +function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } +function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } +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; } } }; } +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); } +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; } +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); } +var newLineRe = /\r\n?|\n/g; module.exports.newLineRe = newLineRe; + // Regular expression for matching common front matter (YAML and TOML) module.exports.frontMatterRe = - // eslint-disable-next-line max-len - /((^---\s*$[\s\S]*?^---\s*)|(^\+\+\+\s*$[\s\S]*?^(\+\+\+|\.\.\.)\s*)|(^\{\s*$[\s\S]*?^\}\s*))(\r\n|\r|\n|$)/m; +// eslint-disable-next-line max-len +/((^---\s*$[\s\S]*?^---\s*)|(^\+\+\+\s*$[\s\S]*?^(\+\+\+|\.\.\.)\s*)|(^\{\s*$[\s\S]*?^\}\s*))(\r\n|\r|\n|$)/m; + // Regular expression for matching the start of inline disable/enable comments -const inlineCommentStartRe = +var inlineCommentStartRe = // eslint-disable-next-line max-len /()/gi; module.exports.inlineCommentStartRe = inlineCommentStartRe; + // Regular expression for matching HTML elements -const htmlElementRe = /<(([A-Za-z][A-Za-z\d-]*)(?:\s[^`>]*)?)\/?>/g; +var htmlElementRe = /<(([A-Za-z][A-Za-z\d-]*)(?:\s[^`>]*)?)\/?>/g; module.exports.htmlElementRe = htmlElementRe; + // Regular expressions for range matching module.exports.listItemMarkerRe = /^([\s>]*)(?:[*+-]|\d+[.)])\s+/; module.exports.orderedListItemMarkerRe = /^[\s>]*0*(\d+)[.)]/; + // Regular expression for all instances of emphasis markers -const emphasisMarkersRe = /[_*]/g; +var emphasisMarkersRe = /[_*]/g; + // Regular expression for blockquote prefixes -const blockquotePrefixRe = /^[>\s]*/; +var blockquotePrefixRe = /^[>\s]*/; module.exports.blockquotePrefixRe = blockquotePrefixRe; + // Regular expression for reference links (full, collapsed, and shortcut) -const referenceLinkRe = /!?\\?\[((?:\[[^\]\0]*\]|[^[\]\0])*)\](?:\[([^\]\0]*)\]|([^(])|$)/g; +var referenceLinkRe = /!?\\?\[((?:\[[^\]\0]*\]|[^[\]\0])*)\](?:\[([^\]\0]*)\]|([^(])|$)/g; + // Regular expression for link reference definitions -const linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])\]:/; +var linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])\]:/; module.exports.linkReferenceDefinitionRe = linkReferenceDefinitionRe; + // All punctuation characters (normal and full-width) -const allPunctuation = ".,;:!?。,;:!?"; +var allPunctuation = ".,;:!?。,;:!?"; module.exports.allPunctuation = allPunctuation; + // All punctuation characters without question mark (normal and full-width) -module.exports.allPunctuationNoQuestion = allPunctuation.replace(/[??]/gu, ""); +module.exports.allPunctuationNoQuestion = allPunctuation.replace(/[\?\uFF1F]/g, ""); + // Returns true iff the input is a number module.exports.isNumber = function isNumber(obj) { - return typeof obj === "number"; + return typeof obj === "number"; }; + // Returns true iff the input is a string module.exports.isString = function isString(obj) { - return typeof obj === "string"; + return typeof obj === "string"; }; + // Returns true iff the input string is empty module.exports.isEmptyString = function isEmptyString(str) { - return str.length === 0; + return str.length === 0; }; + // Returns true iff the input is an object module.exports.isObject = function isObject(obj) { - return (obj !== null) && (typeof obj === "object") && !Array.isArray(obj); + return obj !== null && _typeof(obj) === "object" && !Array.isArray(obj); }; + /** * Returns true iff the input line is blank (contains nothing, whitespace, or * comments (unclosed start/end comments allowed)). @@ -88,36 +117,32 @@ module.exports.isObject = function isObject(obj) { * @returns {boolean} True iff line is blank. */ function isBlankLine(line) { - const startComment = ""; - const removeComments = (s) => { - // eslint-disable-next-line no-constant-condition - while (true) { - const start = s.indexOf(startComment); - const end = s.indexOf(endComment); - if ((end !== -1) && ((start === -1) || (end < start))) { - // Unmatched end comment is first - s = s.slice(end + endComment.length); - } - else if ((start !== -1) && (end !== -1)) { - // Start comment is before end comment - s = s.slice(0, start) + s.slice(end + endComment.length); - } - else if ((start !== -1) && (end === -1)) { - // Unmatched start comment is last - s = s.slice(0, start); - } - else { - // No more comments to remove - return s; - } - } - }; - return (!line || - !line.trim() || - !removeComments(line).replace(/>/g, "").trim()); + var startComment = ""; + var removeComments = function removeComments(s) { + // eslint-disable-next-line no-constant-condition + while (true) { + var start = s.indexOf(startComment); + var end = s.indexOf(endComment); + if (end !== -1 && (start === -1 || end < start)) { + // Unmatched end comment is first + s = s.slice(end + endComment.length); + } else if (start !== -1 && end !== -1) { + // Start comment is before end comment + s = s.slice(0, start) + s.slice(end + endComment.length); + } else if (start !== -1 && end === -1) { + // Unmatched start comment is last + s = s.slice(0, start); + } else { + // No more comments to remove + return s; + } + } + }; + return !line || !line.trim() || !removeComments(line).replace(/>/g, "").trim(); } module.exports.isBlankLine = isBlankLine; + /** * Compare function for Array.prototype.sort for ascending order of numbers. * @@ -126,122 +151,116 @@ module.exports.isBlankLine = isBlankLine; * @returns {number} Positive value if a>b, negative value if b> 1; - if (array[mid] < element) { - left = mid + 1; - } - else if (array[mid] > element) { - right = mid - 1; - } - else { - return true; - } + var left = 0; + var right = array.length - 1; + while (left <= right) { + // eslint-disable-next-line no-bitwise + var mid = left + right >> 1; + if (array[mid] < element) { + left = mid + 1; + } else if (array[mid] > element) { + right = mid - 1; + } else { + return true; } - return false; + } + return false; }; + // Replaces the content of properly-formatted CommonMark comments with "." // This preserves the line/column information for the rest of the document // https://spec.commonmark.org/0.29/#html-blocks // https://spec.commonmark.org/0.29/#html-comment -const htmlCommentBegin = ""; -const safeCommentCharacter = "."; -const startsWithPipeRe = /^ *\|/; -const notCrLfRe = /[^\r\n]/g; -const notSpaceCrLfRe = /[^ \r\n]/g; -const trailingSpaceRe = / +[\r\n]/g; -const replaceTrailingSpace = (s) => s.replace(notCrLfRe, safeCommentCharacter); +var htmlCommentBegin = ""; +var safeCommentCharacter = "."; +var startsWithPipeRe = /^ *\|/; +var notCrLfRe = /[^\r\n]/g; +var notSpaceCrLfRe = /[^ \r\n]/g; +var trailingSpaceRe = / +[\r\n]/g; +var replaceTrailingSpace = function replaceTrailingSpace(s) { + return s.replace(notCrLfRe, safeCommentCharacter); +}; module.exports.clearHtmlCommentText = function clearHtmlCommentText(text) { - let i = 0; - while ((i = text.indexOf(htmlCommentBegin, i)) !== -1) { - const j = text.indexOf(htmlCommentEnd, i + 2); - if (j === -1) { - // Un-terminated comments are treated as text - break; - } - // If the comment has content... - if (j > i + htmlCommentBegin.length) { - const content = text.slice(i + htmlCommentBegin.length, j); - const lastLf = text.lastIndexOf("\n", i) + 1; - const preText = text.slice(lastLf, i); - const isBlock = preText.trim().length === 0; - const couldBeTable = startsWithPipeRe.test(preText); - const spansTableCells = couldBeTable && content.includes("\n"); - const isValid = isBlock || - !(spansTableCells || - content.startsWith(">") || - content.startsWith("->") || - content.endsWith("-") || - content.includes("--")); - // If a valid block/inline comment... - if (isValid) { - const clearedContent = content - .replace(notSpaceCrLfRe, safeCommentCharacter) - .replace(trailingSpaceRe, replaceTrailingSpace); - text = - text.slice(0, i + htmlCommentBegin.length) + - clearedContent + - text.slice(j); - } - } - i = j + htmlCommentEnd.length; + var i = 0; + while ((i = text.indexOf(htmlCommentBegin, i)) !== -1) { + var j = text.indexOf(htmlCommentEnd, i + 2); + if (j === -1) { + // Un-terminated comments are treated as text + break; } - return text; + // If the comment has content... + if (j > i + htmlCommentBegin.length) { + var content = text.slice(i + htmlCommentBegin.length, j); + var lastLf = text.lastIndexOf("\n", i) + 1; + var preText = text.slice(lastLf, i); + var isBlock = preText.trim().length === 0; + var couldBeTable = startsWithPipeRe.test(preText); + var spansTableCells = couldBeTable && content.includes("\n"); + var isValid = isBlock || !(spansTableCells || content.startsWith(">") || content.startsWith("->") || content.endsWith("-") || content.includes("--")); + // If a valid block/inline comment... + if (isValid) { + var clearedContent = content.replace(notSpaceCrLfRe, safeCommentCharacter).replace(trailingSpaceRe, replaceTrailingSpace); + text = text.slice(0, i + htmlCommentBegin.length) + clearedContent + text.slice(j); + } + } + i = j + htmlCommentEnd.length; + } + return text; }; + // Escapes a string for use in a RegExp module.exports.escapeForRegExp = function escapeForRegExp(str) { - return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"); + return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"); }; + // Un-escapes Markdown content (simple algorithm; not a parser) -const escapedMarkdownRe = /\\./g; -module.exports.unescapeMarkdown = - function unescapeMarkdown(markdown, replacement) { - return markdown.replace(escapedMarkdownRe, (match) => { - const char = match[1]; - if ("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~".includes(char)) { - return replacement || char; - } - return match; - }); - }; +var escapedMarkdownRe = /\\./g; +module.exports.unescapeMarkdown = function unescapeMarkdown(markdown, replacement) { + return markdown.replace(escapedMarkdownRe, function (match) { + var _char = match[1]; + if ("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~".includes(_char)) { + return replacement || _char; + } + return match; + }); +}; + /** * Return the string representation of a fence markup character. * * @param {string} markup Fence string. * @returns {string} String representation. */ -module.exports.fencedCodeBlockStyleFor = - function fencedCodeBlockStyleFor(markup) { - switch (markup[0]) { - case "~": - return "tilde"; - default: - return "backtick"; - } - }; +module.exports.fencedCodeBlockStyleFor = function fencedCodeBlockStyleFor(markup) { + switch (markup[0]) { + case "~": + return "tilde"; + default: + return "backtick"; + } +}; + /** * Return the string representation of a emphasis or strong markup character. * * @param {string} markup Emphasis or strong string. * @returns {string} String representation. */ -module.exports.emphasisOrStrongStyleFor = - function emphasisOrStrongStyleFor(markup) { - switch (markup[0]) { - case "*": - return "asterisk"; - default: - return "underscore"; - } - }; +module.exports.emphasisOrStrongStyleFor = function emphasisOrStrongStyleFor(markup) { + switch (markup[0]) { + case "*": + return "asterisk"; + default: + return "underscore"; + } +}; + /** * Return the number of characters of indent for a token. * @@ -249,20 +268,22 @@ module.exports.emphasisOrStrongStyleFor = * @returns {number} Characters of indent. */ function indentFor(token) { - const line = token.line.replace(/^[\s>]*(> |>)/, ""); - return line.length - line.trimStart().length; + var line = token.line.replace(/^[\s>]*(> |>)/, ""); + return line.length - line.trimStart().length; } module.exports.indentFor = indentFor; + // Returns the heading style for a heading token module.exports.headingStyleFor = function headingStyleFor(token) { - if ((token.map[1] - token.map[0]) === 1) { - if (/[^\\]#\s*$/.test(token.line)) { - return "atx_closed"; - } - return "atx"; + if (token.map[1] - token.map[0] === 1) { + if (/[^\\]#\s*$/.test(token.line)) { + return "atx_closed"; } - return "setext"; + return "atx"; + } + return "setext"; }; + /** * Return the string representation of an unordered list marker. * @@ -270,16 +291,17 @@ module.exports.headingStyleFor = function headingStyleFor(token) { * @returns {string} String representation. */ module.exports.unorderedListStyleFor = function unorderedListStyleFor(token) { - switch (token.markup) { - case "-": - return "dash"; - case "+": - return "plus"; - // case "*": - default: - return "asterisk"; - } + switch (token.markup) { + case "-": + return "dash"; + case "+": + return "plus"; + // case "*": + default: + return "asterisk"; + } }; + /** * Calls the provided function for each matching token. * @@ -289,13 +311,23 @@ module.exports.unorderedListStyleFor = function unorderedListStyleFor(token) { * @returns {void} */ function filterTokens(params, type, handler) { - for (const token of params.tokens) { - if (token.type === type) { - handler(token); - } + var _iterator = _createForOfIteratorHelper(params.tokens), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var token = _step.value; + if (token.type === type) { + handler(token); + } } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } } module.exports.filterTokens = filterTokens; + /** * Returns whether a token is a math block (created by markdown-it-texmath). * @@ -303,48 +335,59 @@ module.exports.filterTokens = filterTokens; * @returns {boolean} True iff token is a math block. */ function isMathBlock(token) { - return (((token.tag === "$$") || (token.tag === "math")) && - token.type.startsWith("math_block") && - !token.type.endsWith("_end")); + return (token.tag === "$$" || token.tag === "math") && token.type.startsWith("math_block") && !token.type.endsWith("_end"); } module.exports.isMathBlock = isMathBlock; + // Get line metadata array module.exports.getLineMetadata = function getLineMetadata(params) { - const lineMetadata = params.lines.map((line, index) => [line, index, false, 0, false, false, false, false]); - filterTokens(params, "fence", (token) => { - lineMetadata[token.map[0]][3] = 1; - lineMetadata[token.map[1] - 1][3] = -1; - for (let i = token.map[0] + 1; i < token.map[1] - 1; i++) { - lineMetadata[i][2] = true; - } - }); - filterTokens(params, "code_block", (token) => { - for (let i = token.map[0]; i < token.map[1]; i++) { - lineMetadata[i][2] = true; - } - }); - filterTokens(params, "table_open", (token) => { - for (let i = token.map[0]; i < token.map[1]; i++) { - lineMetadata[i][4] = true; - } - }); - filterTokens(params, "list_item_open", (token) => { - let count = 1; - for (let i = token.map[0]; i < token.map[1]; i++) { - lineMetadata[i][5] = count; - count++; - } - }); - filterTokens(params, "hr", (token) => { - lineMetadata[token.map[0]][6] = true; - }); - for (const token of params.tokens.filter(isMathBlock)) { - for (let i = token.map[0]; i < token.map[1]; i++) { - lineMetadata[i][7] = true; - } + var lineMetadata = params.lines.map(function (line, index) { + return [line, index, false, 0, false, false, false, false]; + }); + filterTokens(params, "fence", function (token) { + lineMetadata[token.map[0]][3] = 1; + lineMetadata[token.map[1] - 1][3] = -1; + for (var i = token.map[0] + 1; i < token.map[1] - 1; i++) { + lineMetadata[i][2] = true; + } + }); + filterTokens(params, "code_block", function (token) { + for (var i = token.map[0]; i < token.map[1]; i++) { + lineMetadata[i][2] = true; } - return lineMetadata; + }); + filterTokens(params, "table_open", function (token) { + for (var i = token.map[0]; i < token.map[1]; i++) { + lineMetadata[i][4] = true; + } + }); + filterTokens(params, "list_item_open", function (token) { + var count = 1; + for (var i = token.map[0]; i < token.map[1]; i++) { + lineMetadata[i][5] = count; + count++; + } + }); + filterTokens(params, "hr", function (token) { + lineMetadata[token.map[0]][6] = true; + }); + var _iterator2 = _createForOfIteratorHelper(params.tokens.filter(isMathBlock)), + _step2; + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var token = _step2.value; + for (var i = token.map[0]; i < token.map[1]; i++) { + lineMetadata[i][7] = true; + } + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + return lineMetadata; }; + /** * Calls the provided function for each line. * @@ -354,65 +397,80 @@ module.exports.getLineMetadata = function getLineMetadata(params) { * @returns {void} */ function forEachLine(lineMetadata, handler) { - for (const metadata of lineMetadata) { - handler(...metadata); + var _iterator3 = _createForOfIteratorHelper(lineMetadata), + _step3; + try { + for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { + var metadata = _step3.value; + handler.apply(void 0, _toConsumableArray(metadata)); } + } catch (err) { + _iterator3.e(err); + } finally { + _iterator3.f(); + } } module.exports.forEachLine = forEachLine; + // Returns (nested) lists as a flat array (in order) module.exports.flattenLists = function flattenLists(tokens) { - const flattenedLists = []; - const stack = []; - let current = null; - let nesting = 0; - const nestingStack = []; - let lastWithMap = { "map": [0, 1] }; - for (const token of tokens) { - if ((token.type === "bullet_list_open") || - (token.type === "ordered_list_open")) { - // Save current context and start a new one - stack.push(current); - current = { - "unordered": (token.type === "bullet_list_open"), - "parentsUnordered": !current || - (current.unordered && current.parentsUnordered), - "open": token, - "indent": indentFor(token), - "parentIndent": (current && current.indent) || 0, - "items": [], - "nesting": nesting, - "lastLineIndex": -1, - "insert": flattenedLists.length - }; - nesting++; - } - else if ((token.type === "bullet_list_close") || - (token.type === "ordered_list_close")) { - // Finalize current context and restore previous - current.lastLineIndex = lastWithMap.map[1]; - flattenedLists.splice(current.insert, 0, current); - delete current.insert; - current = stack.pop(); - nesting--; - } - else if (token.type === "list_item_open") { - // Add list item - current.items.push(token); - } - else if (token.type === "blockquote_open") { - nestingStack.push(nesting); - nesting = 0; - } - else if (token.type === "blockquote_close") { - nesting = nestingStack.pop() || 0; - } - if (token.map) { - // Track last token with map - lastWithMap = token; - } + var flattenedLists = []; + var stack = []; + var current = null; + var nesting = 0; + var nestingStack = []; + var lastWithMap = { + "map": [0, 1] + }; + var _iterator4 = _createForOfIteratorHelper(tokens), + _step4; + try { + for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { + var token = _step4.value; + if (token.type === "bullet_list_open" || token.type === "ordered_list_open") { + // Save current context and start a new one + stack.push(current); + current = { + "unordered": token.type === "bullet_list_open", + "parentsUnordered": !current || current.unordered && current.parentsUnordered, + "open": token, + "indent": indentFor(token), + "parentIndent": current && current.indent || 0, + "items": [], + "nesting": nesting, + "lastLineIndex": -1, + "insert": flattenedLists.length + }; + nesting++; + } else if (token.type === "bullet_list_close" || token.type === "ordered_list_close") { + // Finalize current context and restore previous + current.lastLineIndex = lastWithMap.map[1]; + flattenedLists.splice(current.insert, 0, current); + delete current.insert; + current = stack.pop(); + nesting--; + } else if (token.type === "list_item_open") { + // Add list item + current.items.push(token); + } else if (token.type === "blockquote_open") { + nestingStack.push(nesting); + nesting = 0; + } else if (token.type === "blockquote_close") { + nesting = nestingStack.pop() || 0; + } + if (token.map) { + // Track last token with map + lastWithMap = token; + } } - return flattenedLists; + } catch (err) { + _iterator4.e(err); + } finally { + _iterator4.f(); + } + return flattenedLists; }; + /** * Calls the provided function for each specified inline child token. * @@ -422,28 +480,48 @@ module.exports.flattenLists = function flattenLists(tokens) { * @returns {void} */ function forEachInlineChild(params, type, handler) { - filterTokens(params, "inline", (token) => { - for (const child of token.children.filter((c) => c.type === type)) { - handler(child, token); - } - }); + filterTokens(params, "inline", function (token) { + var _iterator5 = _createForOfIteratorHelper(token.children.filter(function (c) { + return c.type === type; + })), + _step5; + try { + for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { + var child = _step5.value; + handler(child, token); + } + } catch (err) { + _iterator5.e(err); + } finally { + _iterator5.f(); + } + }); } module.exports.forEachInlineChild = forEachInlineChild; + // Calls the provided function for each heading's content module.exports.forEachHeading = function forEachHeading(params, handler) { - let heading = null; - for (const token of params.tokens) { - if (token.type === "heading_open") { - heading = token; - } - else if (token.type === "heading_close") { - heading = null; - } - else if ((token.type === "inline") && heading) { - handler(heading, token.content, token); - } + var heading = null; + var _iterator6 = _createForOfIteratorHelper(params.tokens), + _step6; + try { + for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { + var token = _step6.value; + if (token.type === "heading_open") { + heading = token; + } else if (token.type === "heading_close") { + heading = null; + } else if (token.type === "inline" && heading) { + handler(heading, token.content, token); + } } + } catch (err) { + _iterator6.e(err); + } finally { + _iterator6.f(); + } }; + /** * Calls the provided function for each inline code span's content. * @@ -453,43 +531,48 @@ module.exports.forEachHeading = function forEachHeading(params, handler) { * @returns {void} */ function forEachInlineCodeSpan(input, handler) { - const backtickRe = /`+/g; - let match = null; - const backticksLengthAndIndex = []; - while ((match = backtickRe.exec(input)) !== null) { - backticksLengthAndIndex.push([match[0].length, match.index]); - } - const newLinesIndex = []; - while ((match = newLineRe.exec(input)) !== null) { - newLinesIndex.push(match.index); - } - let lineIndex = 0; - let lineStartIndex = 0; - let k = 0; - for (let i = 0; i < backticksLengthAndIndex.length - 1; i++) { - const [startLength, startIndex] = backticksLengthAndIndex[i]; - if ((startIndex === 0) || (input[startIndex - 1] !== "\\")) { - for (let j = i + 1; j < backticksLengthAndIndex.length; j++) { - const [endLength, endIndex] = backticksLengthAndIndex[j]; - if (startLength === endLength) { - for (; k < newLinesIndex.length; k++) { - const newLineIndex = newLinesIndex[k]; - if (startIndex < newLineIndex) { - break; - } - lineIndex++; - lineStartIndex = newLineIndex + 1; - } - const columnIndex = startIndex - lineStartIndex + startLength; - handler(input.slice(startIndex + startLength, endIndex), lineIndex, columnIndex, startLength); - i = j; - break; - } + var backtickRe = /`+/g; + var match = null; + var backticksLengthAndIndex = []; + while ((match = backtickRe.exec(input)) !== null) { + backticksLengthAndIndex.push([match[0].length, match.index]); + } + var newLinesIndex = []; + while ((match = newLineRe.exec(input)) !== null) { + newLinesIndex.push(match.index); + } + var lineIndex = 0; + var lineStartIndex = 0; + var k = 0; + for (var i = 0; i < backticksLengthAndIndex.length - 1; i++) { + var _backticksLengthAndIn = _slicedToArray(backticksLengthAndIndex[i], 2), + startLength = _backticksLengthAndIn[0], + startIndex = _backticksLengthAndIn[1]; + if (startIndex === 0 || input[startIndex - 1] !== "\\") { + for (var j = i + 1; j < backticksLengthAndIndex.length; j++) { + var _backticksLengthAndIn2 = _slicedToArray(backticksLengthAndIndex[j], 2), + endLength = _backticksLengthAndIn2[0], + endIndex = _backticksLengthAndIn2[1]; + if (startLength === endLength) { + for (; k < newLinesIndex.length; k++) { + var newLineIndex = newLinesIndex[k]; + if (startIndex < newLineIndex) { + break; } - } + lineIndex++; + lineStartIndex = newLineIndex + 1; + } + var columnIndex = startIndex - lineStartIndex + startLength; + handler(input.slice(startIndex + startLength, endIndex), lineIndex, columnIndex, startLength); + i = j; + break; + } + } } + } } module.exports.forEachInlineCodeSpan = forEachInlineCodeSpan; + /** * Adds ellipsis to the left/right/middle of the specified text. * @@ -499,21 +582,19 @@ module.exports.forEachInlineCodeSpan = forEachInlineCodeSpan; * @returns {string} Ellipsified text. */ function ellipsify(text, start, end) { - if (text.length <= 30) { - // Nothing to do - } - else if (start && end) { - text = text.slice(0, 15) + "..." + text.slice(-15); - } - else if (end) { - text = "..." + text.slice(-30); - } - else { - text = text.slice(0, 30) + "..."; - } - return text; + if (text.length <= 30) { + // Nothing to do + } else if (start && end) { + text = text.slice(0, 15) + "..." + text.slice(-15); + } else if (end) { + text = "..." + text.slice(-30); + } else { + text = text.slice(0, 30) + "..."; + } + return text; } module.exports.ellipsify = ellipsify; + /** * Adds a generic error object via the onError callback. * @@ -526,27 +607,29 @@ module.exports.ellipsify = ellipsify; * @returns {void} */ function addError(onError, lineNumber, detail, context, range, fixInfo) { - onError({ - lineNumber, - detail, - context, - range, - fixInfo - }); + onError({ + lineNumber: lineNumber, + detail: detail, + context: context, + range: range, + fixInfo: fixInfo + }); } module.exports.addError = addError; + // Adds an error object with details conditionally via the onError callback module.exports.addErrorDetailIf = function addErrorDetailIf(onError, lineNumber, expected, actual, detail, context, range, fixInfo) { - if (expected !== actual) { - addError(onError, lineNumber, "Expected: " + expected + "; Actual: " + actual + - (detail ? "; " + detail : ""), context, range, fixInfo); - } + if (expected !== actual) { + addError(onError, lineNumber, "Expected: " + expected + "; Actual: " + actual + (detail ? "; " + detail : ""), context, range, fixInfo); + } }; + // Adds an error object with context via the onError callback module.exports.addErrorContext = function addErrorContext(onError, lineNumber, context, left, right, range, fixInfo) { - context = ellipsify(context, left, right); - addError(onError, lineNumber, undefined, context, range, fixInfo); + context = ellipsify(context, left, right); + addError(onError, lineNumber, undefined, context, range, fixInfo); }; + /** * Returns an array of code block and span content ranges. * @@ -554,32 +637,42 @@ module.exports.addErrorContext = function addErrorContext(onError, lineNumber, c * @param {Object} lineMetadata Line metadata object. * @returns {number[][]} Array of ranges (lineIndex, columnIndex, length). */ -module.exports.codeBlockAndSpanRanges = (params, lineMetadata) => { - const exclusions = []; - // Add code block ranges (excludes fences) - forEachLine(lineMetadata, (line, lineIndex, inCode, onFence) => { - if (inCode && !onFence) { - exclusions.push([lineIndex, 0, line.length]); - } - }); - // Add code span ranges (excludes ticks) - filterTokens(params, "inline", (token) => { - if (token.children.some((child) => child.type === "code_inline")) { - const tokenLines = params.lines.slice(token.map[0], token.map[1]); - forEachInlineCodeSpan(tokenLines.join("\n"), (code, lineIndex, columnIndex) => { - const codeLines = code.split(newLineRe); - for (const [i, line] of codeLines.entries()) { - exclusions.push([ - token.lineNumber - 1 + lineIndex + i, - i ? 0 : columnIndex, - line.length - ]); - } - }); - } - }); - return exclusions; +module.exports.codeBlockAndSpanRanges = function (params, lineMetadata) { + var exclusions = []; + // Add code block ranges (excludes fences) + forEachLine(lineMetadata, function (line, lineIndex, inCode, onFence) { + if (inCode && !onFence) { + exclusions.push([lineIndex, 0, line.length]); + } + }); + // Add code span ranges (excludes ticks) + filterTokens(params, "inline", function (token) { + if (token.children.some(function (child) { + return child.type === "code_inline"; + })) { + var tokenLines = params.lines.slice(token.map[0], token.map[1]); + forEachInlineCodeSpan(tokenLines.join("\n"), function (code, lineIndex, columnIndex) { + var codeLines = code.split(newLineRe); + var _iterator7 = _createForOfIteratorHelper(codeLines.entries()), + _step7; + try { + for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) { + var _step7$value = _slicedToArray(_step7.value, 2), + i = _step7$value[0], + line = _step7$value[1]; + exclusions.push([token.lineNumber - 1 + lineIndex + i, i ? 0 : columnIndex, line.length]); + } + } catch (err) { + _iterator7.e(err); + } finally { + _iterator7.f(); + } + }); + } + }); + return exclusions; }; + /** * Returns an array of HTML element ranges. * @@ -587,44 +680,44 @@ module.exports.codeBlockAndSpanRanges = (params, lineMetadata) => { * @param {Object} lineMetadata Line metadata object. * @returns {number[][]} Array of ranges (lineIndex, columnIndex, length). */ -module.exports.htmlElementRanges = (params, lineMetadata) => { - const exclusions = []; - // Match with htmlElementRe - forEachLine(lineMetadata, (line, lineIndex, inCode) => { - let match = null; - // eslint-disable-next-line no-unmodified-loop-condition - while (!inCode && ((match = htmlElementRe.exec(line)) !== null)) { - exclusions.push([lineIndex, match.index, match[0].length]); - } - }); - // Match with html_inline - forEachInlineChild(params, "html_inline", (token, parent) => { - const parentContent = parent.content; - let tokenContent = token.content; - const parentIndex = parentContent.indexOf(tokenContent); - let deltaLines = 0; - let indent = 0; - for (let i = parentIndex - 1; i >= 0; i--) { - if (parentContent[i] === "\n") { - deltaLines++; - } - else if (deltaLines === 0) { - indent++; - } - } - let lineIndex = token.lineNumber - 1 + deltaLines; - do { - const index = tokenContent.indexOf("\n"); - const length = (index === -1) ? tokenContent.length : index; - exclusions.push([lineIndex, indent, length]); - tokenContent = tokenContent.slice(length + 1); - lineIndex++; - indent = 0; - } while (tokenContent.length > 0); - }); - // Return results - return exclusions; +module.exports.htmlElementRanges = function (params, lineMetadata) { + var exclusions = []; + // Match with htmlElementRe + forEachLine(lineMetadata, function (line, lineIndex, inCode) { + var match = null; + // eslint-disable-next-line no-unmodified-loop-condition + while (!inCode && (match = htmlElementRe.exec(line)) !== null) { + exclusions.push([lineIndex, match.index, match[0].length]); + } + }); + // Match with html_inline + forEachInlineChild(params, "html_inline", function (token, parent) { + var parentContent = parent.content; + var tokenContent = token.content; + var parentIndex = parentContent.indexOf(tokenContent); + var deltaLines = 0; + var indent = 0; + for (var i = parentIndex - 1; i >= 0; i--) { + if (parentContent[i] === "\n") { + deltaLines++; + } else if (deltaLines === 0) { + indent++; + } + } + var lineIndex = token.lineNumber - 1 + deltaLines; + do { + var index = tokenContent.indexOf("\n"); + var length = index === -1 ? tokenContent.length : index; + exclusions.push([lineIndex, indent, length]); + tokenContent = tokenContent.slice(length + 1); + lineIndex++; + indent = 0; + } while (tokenContent.length > 0); + }); + // Return results + return exclusions; }; + /** * Determines whether the specified range is within another range. * @@ -634,29 +727,34 @@ module.exports.htmlElementRanges = (params, lineMetadata) => { * @param {number} length Length to check. * @returns {boolean} True iff the specified range is within. */ -const withinAnyRange = (ranges, lineIndex, index, length) => (!ranges.every((span) => ((lineIndex !== span[0]) || - (index < span[1]) || - (index + length > span[1] + span[2])))); +var withinAnyRange = function withinAnyRange(ranges, lineIndex, index, length) { + return !ranges.every(function (span) { + return lineIndex !== span[0] || index < span[1] || index + length > span[1] + span[2]; + }); +}; module.exports.withinAnyRange = withinAnyRange; + // Returns a range object for a line by applying a RegExp module.exports.rangeFromRegExp = function rangeFromRegExp(line, regexp) { - let range = null; - const match = line.match(regexp); - if (match) { - const column = match.index + 1; - const length = match[0].length; - range = [column, length]; - } - return range; + var range = null; + var match = line.match(regexp); + if (match) { + var column = match.index + 1; + var length = match[0].length; + range = [column, length]; + } + return range; }; + // Determines if the front matter includes a title -module.exports.frontMatterHasTitle = - function frontMatterHasTitle(frontMatterLines, frontMatterTitlePattern) { - const ignoreFrontMatter = (frontMatterTitlePattern !== undefined) && !frontMatterTitlePattern; - const frontMatterTitleRe = new RegExp(String(frontMatterTitlePattern || "^\\s*\"?title\"?\\s*[:=]"), "i"); - return !ignoreFrontMatter && - frontMatterLines.some((line) => frontMatterTitleRe.test(line)); - }; +module.exports.frontMatterHasTitle = function frontMatterHasTitle(frontMatterLines, frontMatterTitlePattern) { + var ignoreFrontMatter = frontMatterTitlePattern !== undefined && !frontMatterTitlePattern; + var frontMatterTitleRe = new RegExp(String(frontMatterTitlePattern || "^\\s*\"?title\"?\\s*[:=]"), "i"); + return !ignoreFrontMatter && frontMatterLines.some(function (line) { + return frontMatterTitleRe.test(line); + }); +}; + /** * Calls the provided function for each link. * @@ -665,81 +763,74 @@ module.exports.frontMatterHasTitle = * @returns {void} */ function forEachLink(line, handler) { - // Helper to find matching close symbol for link text/destination - const findClosingSymbol = (index) => { - const begin = line[index]; - const end = (begin === "[") ? "]" : ")"; - let nesting = 0; - let escaping = false; - let pointy = false; - for (let i = index + 1; i < line.length; i++) { - const current = line[i]; - if (current === "\\") { - escaping = !escaping; - } - else if (!escaping && (current === begin)) { - nesting++; - } - else if (!escaping && (current === end)) { - if (nesting > 0) { - nesting--; - } - else if (!pointy) { - // Return index after matching close symbol - return i + 1; - } - } - else if ((i === index + 1) && (begin === "(") && (current === "<")) { - pointy = true; - } - else if (!escaping && pointy && current === ">") { - pointy = false; - nesting = 0; - } - else { - escaping = false; - } - } - // No match found - return -1; - }; - // Scan line for unescaped "[" character - let escaping = false; - for (let i = 0; i < line.length; i++) { - const current = line[i]; - if (current === "\\") { - escaping = !escaping; - } - else if (!escaping && (current === "[")) { - // Scan for matching close "]" of link text - const textEnd = findClosingSymbol(i); - if (textEnd !== -1) { - if ((line[textEnd] === "(") || (line[textEnd] === "[")) { - // Scan for matching close ")" or "]" of link destination - const destEnd = findClosingSymbol(textEnd); - if (destEnd !== -1) { - // Call handler with link text and destination - const link = line.slice(i, destEnd); - const text = line.slice(i, textEnd); - const dest = line.slice(textEnd, destEnd); - handler(i, link, text, dest); - i = destEnd; - } - } - if (i < textEnd) { - // Call handler with link text only - const text = line.slice(i, textEnd); - handler(i, text, text); - i = textEnd; - } - } - } - else { - escaping = false; - } + // Helper to find matching close symbol for link text/destination + var findClosingSymbol = function findClosingSymbol(index) { + var begin = line[index]; + var end = begin === "[" ? "]" : ")"; + var nesting = 0; + var escaping = false; + var pointy = false; + for (var i = index + 1; i < line.length; i++) { + var current = line[i]; + if (current === "\\") { + escaping = !escaping; + } else if (!escaping && current === begin) { + nesting++; + } else if (!escaping && current === end) { + if (nesting > 0) { + nesting--; + } else if (!pointy) { + // Return index after matching close symbol + return i + 1; + } + } else if (i === index + 1 && begin === "(" && current === "<") { + pointy = true; + } else if (!escaping && pointy && current === ">") { + pointy = false; + nesting = 0; + } else { + escaping = false; + } + } + // No match found + return -1; + }; + // Scan line for unescaped "[" character + var escaping = false; + for (var i = 0; i < line.length; i++) { + var current = line[i]; + if (current === "\\") { + escaping = !escaping; + } else if (!escaping && current === "[") { + // Scan for matching close "]" of link text + var textEnd = findClosingSymbol(i); + if (textEnd !== -1) { + if (line[textEnd] === "(" || line[textEnd] === "[") { + // Scan for matching close ")" or "]" of link destination + var destEnd = findClosingSymbol(textEnd); + if (destEnd !== -1) { + // Call handler with link text and destination + var link = line.slice(i, destEnd); + var text = line.slice(i, textEnd); + var dest = line.slice(textEnd, destEnd); + handler(i, link, text, dest); + i = destEnd; + } + } + if (i < textEnd) { + // Call handler with link text only + var _text = line.slice(i, textEnd); + handler(i, _text, _text); + i = textEnd; + } + } + } else { + escaping = false; } + } } module.exports.forEachLink = forEachLink; + /** * Returns a list of emphasis markers in code spans and links. * @@ -747,42 +838,72 @@ module.exports.forEachLink = forEachLink; * @returns {number[][]} List of markers. */ function emphasisMarkersInContent(params) { - const { lines } = params; - const byLine = new Array(lines.length); - // Search links - for (const [tokenLineIndex, tokenLine] of lines.entries()) { - const inLine = []; - forEachLink(tokenLine, (index, match) => { - let markerMatch = null; - while ((markerMatch = emphasisMarkersRe.exec(match))) { - inLine.push(index + markerMatch.index); - } - }); - byLine[tokenLineIndex] = inLine; + var lines = params.lines; + var byLine = new Array(lines.length); + // Search links + var _iterator8 = _createForOfIteratorHelper(lines.entries()), + _step8; + try { + var _loop = function _loop() { + var _step8$value = _slicedToArray(_step8.value, 2), + tokenLineIndex = _step8$value[0], + tokenLine = _step8$value[1]; + var inLine = []; + forEachLink(tokenLine, function (index, match) { + var markerMatch = null; + while (markerMatch = emphasisMarkersRe.exec(match)) { + inLine.push(index + markerMatch.index); + } + }); + byLine[tokenLineIndex] = inLine; + }; + for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) { + _loop(); } // Search code spans - filterTokens(params, "inline", (token) => { - const { children, lineNumber, map } = token; - if (children.some((child) => child.type === "code_inline")) { - const tokenLines = lines.slice(map[0], map[1]); - forEachInlineCodeSpan(tokenLines.join("\n"), (code, lineIndex, column, tickCount) => { - const codeLines = code.split(newLineRe); - for (const [codeLineIndex, codeLine] of codeLines.entries()) { - const byLineIndex = lineNumber - 1 + lineIndex + codeLineIndex; - const inLine = byLine[byLineIndex]; - const codeLineOffset = codeLineIndex ? 0 : column - 1 + tickCount; - let match = null; - while ((match = emphasisMarkersRe.exec(codeLine))) { - inLine.push(codeLineOffset + match.index); - } - byLine[byLineIndex] = inLine; - } - }); - } - }); - return byLine; + } catch (err) { + _iterator8.e(err); + } finally { + _iterator8.f(); + } + filterTokens(params, "inline", function (token) { + var children = token.children, + lineNumber = token.lineNumber, + map = token.map; + if (children.some(function (child) { + return child.type === "code_inline"; + })) { + var tokenLines = lines.slice(map[0], map[1]); + forEachInlineCodeSpan(tokenLines.join("\n"), function (code, lineIndex, column, tickCount) { + var codeLines = code.split(newLineRe); + var _iterator9 = _createForOfIteratorHelper(codeLines.entries()), + _step9; + try { + for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) { + var _step9$value = _slicedToArray(_step9.value, 2), + codeLineIndex = _step9$value[0], + codeLine = _step9$value[1]; + var byLineIndex = lineNumber - 1 + lineIndex + codeLineIndex; + var inLine = byLine[byLineIndex]; + var codeLineOffset = codeLineIndex ? 0 : column - 1 + tickCount; + var match = null; + while (match = emphasisMarkersRe.exec(codeLine)) { + inLine.push(codeLineOffset + match.index); + } + byLine[byLineIndex] = inLine; + } + } catch (err) { + _iterator9.e(err); + } finally { + _iterator9.f(); + } + }); + } + }); + return byLine; } module.exports.emphasisMarkersInContent = emphasisMarkersInContent; + /** * Returns an object with information about reference links and images. * @@ -790,139 +911,136 @@ module.exports.emphasisMarkersInContent = emphasisMarkersInContent; * @returns {Object} Reference link/image data. */ function getReferenceLinkImageData(lineMetadata) { - // Initialize return values - const references = new Map(); - const shortcuts = new Map(); - const definitions = new Map(); - const duplicateDefinitions = []; - const definitionLineIndices = []; - // Define helper functions - const normalizeLabel = (s) => s.toLowerCase().trim().replace(/\s+/g, " "); - const exclusions = []; - const excluded = (match) => withinAnyRange(exclusions, 0, match.index, match[0].length - (match[3] || "").length); - // Convert input to single-line so multi-line links/images are easier - const lineOffsets = []; - let currentOffset = 0; - const contentLines = []; - forEachLine(lineMetadata, (line, lineIndex, inCode) => { - lineOffsets[lineIndex] = currentOffset; - if (!inCode) { - line = line.replace(blockquotePrefixRe, ""); - if (line.trim().length === 0) { - // Allow RegExp to detect the end of a block - line = "\0"; - } - contentLines.push(line); - currentOffset += line.length + 1; - } - }); - lineOffsets.push(currentOffset); - const contentLine = contentLines.join(" "); - // Determine single-line exclusions for inline code spans - forEachInlineCodeSpan(contentLine, (code, lineIndex, columnIndex) => { - exclusions.push([0, columnIndex, code.length]); - }); - // Identify all link/image reference definitions - forEachLine(lineMetadata, (line, lineIndex, inCode) => { - if (!inCode) { - const linkReferenceDefinitionMatch = linkReferenceDefinitionRe.exec(line); - if (linkReferenceDefinitionMatch) { - const label = normalizeLabel(linkReferenceDefinitionMatch[1]); - if (definitions.has(label)) { - duplicateDefinitions.push([label, lineIndex]); - } - else { - definitions.set(label, lineIndex); - } - const labelLength = linkReferenceDefinitionMatch[0].length; - exclusions.push([0, lineOffsets[lineIndex], labelLength]); - const hasDefinition = line.slice(labelLength).trim().length > 0; - definitionLineIndices.push(lineIndex); - if (!hasDefinition) { - definitionLineIndices.push(lineIndex + 1); - } - } - } - }); - // Identify all link and image references - let lineIndex = 0; - const pendingContents = [ - { - "content": contentLine, - "contentLineIndex": 0, - "contentIndex": 0, - "topLevel": true - } - ]; - let pendingContent = null; - while ((pendingContent = pendingContents.shift())) { - const { content, contentLineIndex, contentIndex, topLevel } = pendingContent; - let referenceLinkMatch = null; - while ((referenceLinkMatch = referenceLinkRe.exec(content)) !== null) { - const [matchString, matchText, matchLabel] = referenceLinkMatch; - if (!matchString.startsWith("\\") && - !matchString.startsWith("!\\") && - !matchText.endsWith("\\") && - !(matchLabel || "").endsWith("\\") && - !(topLevel && excluded(referenceLinkMatch))) { - const shortcutLink = (matchLabel === undefined); - const collapsedLink = (!shortcutLink && (matchLabel.length === 0)); - const label = normalizeLabel((shortcutLink || collapsedLink) ? matchText : matchLabel); - if (label.length > 0) { - const referenceindex = referenceLinkMatch.index; - if (topLevel) { - // Calculate line index - while (lineOffsets[lineIndex + 1] <= referenceindex) { - lineIndex++; - } - } - else { - // Use provided line index - lineIndex = contentLineIndex; - } - const referenceIndex = referenceindex + - (topLevel ? -lineOffsets[lineIndex] : contentIndex); - const referenceDatum = [ - lineIndex, - referenceIndex, - matchString.length, - matchText.length, - (matchLabel || "").length - ]; - if (shortcutLink) { - // Track separately due to ambiguity in "text [text] text" - const shortcutData = shortcuts.get(label) || []; - shortcutData.push(referenceDatum); - shortcuts.set(label, shortcutData); - } - else { - // Track reference and location - const referenceData = references.get(label) || []; - referenceData.push(referenceDatum); - references.set(label, referenceData); - } - // Check for links embedded in brackets - if (!matchString.startsWith("!")) { - pendingContents.push({ - "content": matchText, - "contentLineIndex": lineIndex, - "contentIndex": referenceIndex + 1, - "topLevel": false - }); - } - } - } + // Initialize return values + var references = new Map(); + var shortcuts = new Map(); + var definitions = new Map(); + var duplicateDefinitions = []; + var definitionLineIndices = []; + // Define helper functions + var normalizeLabel = function normalizeLabel(s) { + return s.toLowerCase().trim().replace(/\s+/g, " "); + }; + var exclusions = []; + var excluded = function excluded(match) { + return withinAnyRange(exclusions, 0, match.index, match[0].length - (match[3] || "").length); + }; + // Convert input to single-line so multi-line links/images are easier + var lineOffsets = []; + var currentOffset = 0; + var contentLines = []; + forEachLine(lineMetadata, function (line, lineIndex, inCode) { + lineOffsets[lineIndex] = currentOffset; + if (!inCode) { + line = line.replace(blockquotePrefixRe, ""); + if (line.trim().length === 0) { + // Allow RegExp to detect the end of a block + line = "\0"; + } + contentLines.push(line); + currentOffset += line.length + 1; + } + }); + lineOffsets.push(currentOffset); + var contentLine = contentLines.join(" "); + // Determine single-line exclusions for inline code spans + forEachInlineCodeSpan(contentLine, function (code, lineIndex, columnIndex) { + exclusions.push([0, columnIndex, code.length]); + }); + // Identify all link/image reference definitions + forEachLine(lineMetadata, function (line, lineIndex, inCode) { + if (!inCode) { + var linkReferenceDefinitionMatch = linkReferenceDefinitionRe.exec(line); + if (linkReferenceDefinitionMatch) { + var label = normalizeLabel(linkReferenceDefinitionMatch[1]); + if (definitions.has(label)) { + duplicateDefinitions.push([label, lineIndex]); + } else { + definitions.set(label, lineIndex); + } + var labelLength = linkReferenceDefinitionMatch[0].length; + exclusions.push([0, lineOffsets[lineIndex], labelLength]); + var hasDefinition = line.slice(labelLength).trim().length > 0; + definitionLineIndices.push(lineIndex); + if (!hasDefinition) { + definitionLineIndices.push(lineIndex + 1); + } + } + } + }); + // Identify all link and image references + var lineIndex = 0; + var pendingContents = [{ + "content": contentLine, + "contentLineIndex": 0, + "contentIndex": 0, + "topLevel": true + }]; + var pendingContent = null; + while (pendingContent = pendingContents.shift()) { + var _pendingContent = pendingContent, + content = _pendingContent.content, + contentLineIndex = _pendingContent.contentLineIndex, + contentIndex = _pendingContent.contentIndex, + topLevel = _pendingContent.topLevel; + var referenceLinkMatch = null; + while ((referenceLinkMatch = referenceLinkRe.exec(content)) !== null) { + var _referenceLinkMatch = referenceLinkMatch, + _referenceLinkMatch2 = _slicedToArray(_referenceLinkMatch, 3), + matchString = _referenceLinkMatch2[0], + matchText = _referenceLinkMatch2[1], + matchLabel = _referenceLinkMatch2[2]; + if (!matchString.startsWith("\\") && !matchString.startsWith("!\\") && !matchText.endsWith("\\") && !(matchLabel || "").endsWith("\\") && !(topLevel && excluded(referenceLinkMatch))) { + var shortcutLink = matchLabel === undefined; + var collapsedLink = !shortcutLink && matchLabel.length === 0; + var label = normalizeLabel(shortcutLink || collapsedLink ? matchText : matchLabel); + if (label.length > 0) { + var referenceindex = referenceLinkMatch.index; + if (topLevel) { + // Calculate line index + while (lineOffsets[lineIndex + 1] <= referenceindex) { + lineIndex++; + } + } else { + // Use provided line index + lineIndex = contentLineIndex; + } + var referenceIndex = referenceindex + (topLevel ? -lineOffsets[lineIndex] : contentIndex); + var referenceDatum = [lineIndex, referenceIndex, matchString.length, matchText.length, (matchLabel || "").length]; + if (shortcutLink) { + // Track separately due to ambiguity in "text [text] text" + var shortcutData = shortcuts.get(label) || []; + shortcutData.push(referenceDatum); + shortcuts.set(label, shortcutData); + } else { + // Track reference and location + var referenceData = references.get(label) || []; + referenceData.push(referenceDatum); + references.set(label, referenceData); + } + // Check for links embedded in brackets + if (!matchString.startsWith("!")) { + pendingContents.push({ + "content": matchText, + "contentLineIndex": lineIndex, + "contentIndex": referenceIndex + 1, + "topLevel": false + }); + } } + } } - return { - references, - shortcuts, - definitions, - duplicateDefinitions, - definitionLineIndices - }; + } + return { + references: references, + shortcuts: shortcuts, + definitions: definitions, + duplicateDefinitions: duplicateDefinitions, + definitionLineIndices: definitionLineIndices + }; } module.exports.getReferenceLinkImageData = getReferenceLinkImageData; + /** * Gets the most common line ending, falling back to the platform default. * @@ -931,40 +1049,47 @@ module.exports.getReferenceLinkImageData = getReferenceLinkImageData; * @returns {string} Preferred line ending. */ function getPreferredLineEnding(input, os) { - let cr = 0; - let lf = 0; - let crlf = 0; - const endings = input.match(newLineRe) || []; - for (const ending of endings) { - // eslint-disable-next-line default-case - switch (ending) { - case "\r": - cr++; - break; - case "\n": - lf++; - break; - case "\r\n": - crlf++; - break; - } + var cr = 0; + var lf = 0; + var crlf = 0; + var endings = input.match(newLineRe) || []; + var _iterator10 = _createForOfIteratorHelper(endings), + _step10; + try { + for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) { + var ending = _step10.value; + // eslint-disable-next-line default-case + switch (ending) { + case "\r": + cr++; + break; + case "\n": + lf++; + break; + case "\r\n": + crlf++; + break; + } } - let preferredLineEnding = null; - if (!cr && !lf && !crlf) { - preferredLineEnding = (os && os.EOL) || "\n"; - } - else if ((lf >= crlf) && (lf >= cr)) { - preferredLineEnding = "\n"; - } - else if (crlf >= cr) { - preferredLineEnding = "\r\n"; - } - else { - preferredLineEnding = "\r"; - } - return preferredLineEnding; + } catch (err) { + _iterator10.e(err); + } finally { + _iterator10.f(); + } + var preferredLineEnding = null; + if (!cr && !lf && !crlf) { + preferredLineEnding = os && os.EOL || "\n"; + } else if (lf >= crlf && lf >= cr) { + preferredLineEnding = "\n"; + } else if (crlf >= cr) { + preferredLineEnding = "\r\n"; + } else { + preferredLineEnding = "\r"; + } + return preferredLineEnding; } module.exports.getPreferredLineEnding = getPreferredLineEnding; + /** * Normalizes the fields of a RuleOnErrorFixInfo instance. * @@ -973,13 +1098,14 @@ module.exports.getPreferredLineEnding = getPreferredLineEnding; * @returns {Object} Normalized RuleOnErrorFixInfo instance. */ function normalizeFixInfo(fixInfo, lineNumber) { - return { - "lineNumber": fixInfo.lineNumber || lineNumber, - "editColumn": fixInfo.editColumn || 1, - "deleteCount": fixInfo.deleteCount || 0, - "insertText": fixInfo.insertText || "" - }; + return { + "lineNumber": fixInfo.lineNumber || lineNumber, + "editColumn": fixInfo.editColumn || 1, + "deleteCount": fixInfo.deleteCount || 0, + "insertText": fixInfo.insertText || "" + }; } + /** * Fixes the specified error on a line of Markdown content. * @@ -989,15 +1115,15 @@ function normalizeFixInfo(fixInfo, lineNumber) { * @returns {string | null} Fixed content. */ function applyFix(line, fixInfo, lineEnding) { - const { editColumn, deleteCount, insertText } = normalizeFixInfo(fixInfo); - const editIndex = editColumn - 1; - return (deleteCount === -1) ? - null : - line.slice(0, editIndex) + - insertText.replace(/\n/g, lineEnding || "\n") + - line.slice(editIndex + deleteCount); + var _normalizeFixInfo = normalizeFixInfo(fixInfo), + editColumn = _normalizeFixInfo.editColumn, + deleteCount = _normalizeFixInfo.deleteCount, + insertText = _normalizeFixInfo.insertText; + var editIndex = editColumn - 1; + return deleteCount === -1 ? null : line.slice(0, editIndex) + insertText.replace(/\n/g, lineEnding || "\n") + line.slice(editIndex + deleteCount); } module.exports.applyFix = applyFix; + /** * Applies as many fixes as possible to Markdown content. * @@ -1006,69 +1132,82 @@ module.exports.applyFix = applyFix; * @returns {string} Corrected content. */ function applyFixes(input, errors) { - const lineEnding = getPreferredLineEnding(input, __webpack_require__(/*! node:os */ "?0176")); - const lines = input.split(newLineRe); - // Normalize fixInfo objects - let fixInfos = errors - .filter((error) => error.fixInfo) - .map((error) => normalizeFixInfo(error.fixInfo, error.lineNumber)); - // Sort bottom-to-top, line-deletes last, right-to-left, long-to-short - fixInfos.sort((a, b) => { - const aDeletingLine = (a.deleteCount === -1); - const bDeletingLine = (b.deleteCount === -1); - return ((b.lineNumber - a.lineNumber) || - (aDeletingLine ? 1 : (bDeletingLine ? -1 : 0)) || - (b.editColumn - a.editColumn) || - (b.insertText.length - a.insertText.length)); - }); - // Remove duplicate entries (needed for following collapse step) - let lastFixInfo = {}; - fixInfos = fixInfos.filter((fixInfo) => { - const unique = ((fixInfo.lineNumber !== lastFixInfo.lineNumber) || - (fixInfo.editColumn !== lastFixInfo.editColumn) || - (fixInfo.deleteCount !== lastFixInfo.deleteCount) || - (fixInfo.insertText !== lastFixInfo.insertText)); - lastFixInfo = fixInfo; - return unique; - }); - // Collapse insert/no-delete and no-insert/delete for same line/column - lastFixInfo = { - "lineNumber": -1 - }; - for (const fixInfo of fixInfos) { - if ((fixInfo.lineNumber === lastFixInfo.lineNumber) && - (fixInfo.editColumn === lastFixInfo.editColumn) && - !fixInfo.insertText && - (fixInfo.deleteCount > 0) && - lastFixInfo.insertText && - !lastFixInfo.deleteCount) { - fixInfo.insertText = lastFixInfo.insertText; - lastFixInfo.lineNumber = 0; - } - lastFixInfo = fixInfo; + var lineEnding = getPreferredLineEnding(input, __webpack_require__(/*! node:os */ "?0176")); + var lines = input.split(newLineRe); + // Normalize fixInfo objects + var fixInfos = errors.filter(function (error) { + return error.fixInfo; + }).map(function (error) { + return normalizeFixInfo(error.fixInfo, error.lineNumber); + }); + // Sort bottom-to-top, line-deletes last, right-to-left, long-to-short + fixInfos.sort(function (a, b) { + var aDeletingLine = a.deleteCount === -1; + var bDeletingLine = b.deleteCount === -1; + return b.lineNumber - a.lineNumber || (aDeletingLine ? 1 : bDeletingLine ? -1 : 0) || b.editColumn - a.editColumn || b.insertText.length - a.insertText.length; + }); + // Remove duplicate entries (needed for following collapse step) + var lastFixInfo = {}; + fixInfos = fixInfos.filter(function (fixInfo) { + var unique = fixInfo.lineNumber !== lastFixInfo.lineNumber || fixInfo.editColumn !== lastFixInfo.editColumn || fixInfo.deleteCount !== lastFixInfo.deleteCount || fixInfo.insertText !== lastFixInfo.insertText; + lastFixInfo = fixInfo; + return unique; + }); + // Collapse insert/no-delete and no-insert/delete for same line/column + lastFixInfo = { + "lineNumber": -1 + }; + var _iterator11 = _createForOfIteratorHelper(fixInfos), + _step11; + try { + for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) { + var fixInfo = _step11.value; + if (fixInfo.lineNumber === lastFixInfo.lineNumber && fixInfo.editColumn === lastFixInfo.editColumn && !fixInfo.insertText && fixInfo.deleteCount > 0 && lastFixInfo.insertText && !lastFixInfo.deleteCount) { + fixInfo.insertText = lastFixInfo.insertText; + lastFixInfo.lineNumber = 0; + } + lastFixInfo = fixInfo; } - fixInfos = fixInfos.filter((fixInfo) => fixInfo.lineNumber); - // Apply all (remaining/updated) fixes - let lastLineIndex = -1; - let lastEditIndex = -1; - for (const fixInfo of fixInfos) { - const { lineNumber, editColumn, deleteCount } = fixInfo; - const lineIndex = lineNumber - 1; - const editIndex = editColumn - 1; - if ((lineIndex !== lastLineIndex) || - (deleteCount === -1) || - ((editIndex + deleteCount) <= - (lastEditIndex - ((deleteCount > 0) ? 0 : 1)))) { - // @ts-ignore - lines[lineIndex] = applyFix(lines[lineIndex], fixInfo, lineEnding); - } - lastLineIndex = lineIndex; - lastEditIndex = editIndex; + } catch (err) { + _iterator11.e(err); + } finally { + _iterator11.f(); + } + fixInfos = fixInfos.filter(function (fixInfo) { + return fixInfo.lineNumber; + }); + // Apply all (remaining/updated) fixes + var lastLineIndex = -1; + var lastEditIndex = -1; + var _iterator12 = _createForOfIteratorHelper(fixInfos), + _step12; + try { + for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) { + var _fixInfo = _step12.value; + var lineNumber = _fixInfo.lineNumber, + editColumn = _fixInfo.editColumn, + deleteCount = _fixInfo.deleteCount; + var lineIndex = lineNumber - 1; + var editIndex = editColumn - 1; + if (lineIndex !== lastLineIndex || deleteCount === -1 || editIndex + deleteCount <= lastEditIndex - (deleteCount > 0 ? 0 : 1)) { + // @ts-ignore + lines[lineIndex] = applyFix(lines[lineIndex], _fixInfo, lineEnding); + } + lastLineIndex = lineIndex; + lastEditIndex = editIndex; } // Return corrected input - return lines.filter((line) => line !== null).join(lineEnding); + } catch (err) { + _iterator12.e(err); + } finally { + _iterator12.f(); + } + return lines.filter(function (line) { + return line !== null; + }).join(lineEnding); } module.exports.applyFixes = applyFixes; + /** * Gets the range and fixInfo values for reporting an error if the expected * text is found on the specified line. @@ -1080,30 +1219,31 @@ module.exports.applyFixes = applyFixes; * @param {number} [instance] Instance on the line (1-based). * @returns {Object} Range and fixInfo wrapper. */ -module.exports.getRangeAndFixInfoIfFound = - (lines, lineIndex, search, replace, instance = 1) => { - let range = null; - let fixInfo = null; - let searchIndex = -1; - while (instance > 0) { - searchIndex = lines[lineIndex].indexOf(search, searchIndex + 1); - instance--; - } - if (searchIndex !== -1) { - const column = searchIndex + 1; - const length = search.length; - range = [column, length]; - fixInfo = { - "editColumn": column, - "deleteCount": length, - "insertText": replace - }; - } - return { - range, - fixInfo - }; +module.exports.getRangeAndFixInfoIfFound = function (lines, lineIndex, search, replace) { + var instance = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; + var range = null; + var fixInfo = null; + var searchIndex = -1; + while (instance > 0) { + searchIndex = lines[lineIndex].indexOf(search, searchIndex + 1); + instance--; + } + if (searchIndex !== -1) { + var column = searchIndex + 1; + var length = search.length; + range = [column, length]; + fixInfo = { + "editColumn": column, + "deleteCount": length, + "insertText": replace }; + } + return { + range: range, + fixInfo: fixInfo + }; +}; + /** * Gets the next (subsequent) child token if it is of the expected type. * @@ -1114,17 +1254,15 @@ module.exports.getRangeAndFixInfoIfFound = * @returns {Object} Next token. */ function getNextChildToken(parentToken, childToken, nextType, nextNextType) { - const { children } = parentToken; - const index = children.indexOf(childToken); - if ((index !== -1) && - (children.length > index + 2) && - (children[index + 1].type === nextType) && - (children[index + 2].type === nextNextType)) { - return children[index + 1]; - } - return null; + var children = parentToken.children; + var index = children.indexOf(childToken); + if (index !== -1 && children.length > index + 2 && children[index + 1].type === nextType && children[index + 2].type === nextNextType) { + return children[index + 1]; + } + return null; } module.exports.getNextChildToken = getNextChildToken; + /** * Expands a path with a tilde to an absolute path. * @@ -1133,10 +1271,11 @@ module.exports.getNextChildToken = getNextChildToken; * @returns {string} Absolute path (or original path). */ function expandTildePath(file, os) { - const homedir = os && os.homedir && os.homedir(); - return homedir ? file.replace(/^~($|\/|\\)/, `${homedir}$1`) : file; + var homedir = os && os.homedir && os.homedir(); + return homedir ? file.replace(/^~($|\/|\\)/, "".concat(homedir, "$1")) : file; } module.exports.expandTildePath = expandTildePath; + /** * RegExp.exec-style implementation of function expressions. * @@ -1146,48 +1285,36 @@ module.exports.expandTildePath = expandTildePath; * @returns {string[] | null} RegExp.exec-style [match] with an index property. */ function funcExpExec(funcExp, input) { - // Start or resume match + // Start or resume match + // @ts-ignore + var lastIndex = funcExp.lastIndex || 0; + var result = funcExp(input.slice(lastIndex)); + if (result) { + // Update lastIndex and return match + var _result = _slicedToArray(result, 2), + subIndex = _result[0], + length = _result[1]; + var index = lastIndex + subIndex; // @ts-ignore - const lastIndex = funcExp.lastIndex || 0; - const result = funcExp(input.slice(lastIndex)); - if (result) { - // Update lastIndex and return match - const [subIndex, length] = result; - const index = lastIndex + subIndex; - // @ts-ignore - funcExp.lastIndex = index + length; - const match = [input.slice(index, index + length)]; - // @ts-ignore - match.index = index; - return match; - } - // Reset lastIndex and return no match + funcExp.lastIndex = index + length; + var match = [input.slice(index, index + length)]; // @ts-ignore - funcExp.lastIndex = 0; - return null; + match.index = index; + return match; + } + // Reset lastIndex and return no match + // @ts-ignore + funcExp.lastIndex = 0; + return null; } module.exports.funcExpExec = funcExpExec; -const urlFeProtocolRe = /(?:http|ftp)s?:\/\//i; -const urlFeAutolinkTerminalsRe = / |$/; -const urlFeBareTerminalsRe = /[ ,!`'"\]]|$/; -const urlFeNonTerminalsRe = "-#/"; -const urlFePunctuationRe = /\p{Punctuation}/u; -const urlFePrefixToPostfix = new Map([ - [" ", " "], - ["`", "`"], - ["'", "'"], - ["\"", "\""], - ["‘", "’"], - ["“", "”"], - ["«", "»"], - ["*", "*"], - ["_", "_"], - ["(", ")"], - ["[", "]"], - ["{", "}"], - ["<", ">"], - [">", "<"] -]); +var urlFeProtocolRe = /(?:http|ftp)s?:\/\//i; +var urlFeAutolinkTerminalsRe = / |$/; +var urlFeBareTerminalsRe = /[ ,!`'"\]]|$/; +var urlFeNonTerminalsRe = "-#/"; +var urlFePunctuationRe = /(?:[!-#%-\*,-\/:;\?@\[-\]_\{\}\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061D-\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u09FD\u0A76\u0AF0\u0C77\u0C84\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1B7D\u1B7E\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E4F\u2E52-\u2E5D\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]|\uD800[\uDD00-\uDD02\uDF9F\uDFD0]|\uD801\uDD6F|\uD802[\uDC57\uDD1F\uDD3F\uDE50-\uDE58\uDE7F\uDEF0-\uDEF6\uDF39-\uDF3F\uDF99-\uDF9C]|\uD803[\uDEAD\uDF55-\uDF59\uDF86-\uDF89]|\uD804[\uDC47-\uDC4D\uDCBB\uDCBC\uDCBE-\uDCC1\uDD40-\uDD43\uDD74\uDD75\uDDC5-\uDDC8\uDDCD\uDDDB\uDDDD-\uDDDF\uDE38-\uDE3D\uDEA9]|\uD805[\uDC4B-\uDC4F\uDC5A\uDC5B\uDC5D\uDCC6\uDDC1-\uDDD7\uDE41-\uDE43\uDE60-\uDE6C\uDEB9\uDF3C-\uDF3E]|\uD806[\uDC3B\uDD44-\uDD46\uDDE2\uDE3F-\uDE46\uDE9A-\uDE9C\uDE9E-\uDEA2\uDF00-\uDF09]|\uD807[\uDC41-\uDC45\uDC70\uDC71\uDEF7\uDEF8\uDF43-\uDF4F\uDFFF]|\uD809[\uDC70-\uDC74]|\uD80B[\uDFF1\uDFF2]|\uD81A[\uDE6E\uDE6F\uDEF5\uDF37-\uDF3B\uDF44]|\uD81B[\uDE97-\uDE9A\uDFE2]|\uD82F\uDC9F|\uD836[\uDE87-\uDE8B]|\uD83A[\uDD5E\uDD5F])/; +var urlFePrefixToPostfix = new Map([[" ", " "], ["`", "`"], ["'", "'"], ["\"", "\""], ["‘", "’"], ["“", "”"], ["«", "»"], ["*", "*"], ["_", "_"], ["(", ")"], ["[", "]"], ["{", "}"], ["<", ">"], [">", "<"]]); + /** * Function expression that matches URLs. * @@ -1195,53 +1322,49 @@ const urlFePrefixToPostfix = new Map([ * @returns {Array | null} [index, length] of URL or null. */ function urlFe(input) { - // Find start of URL by searching for protocol - const match = input.match(urlFeProtocolRe); - if (match) { - // Look for matching pre/postfix characters (ex: <...>) - const start = match.index || 0; - const length = match[0].length; - const prefix = input[start - 1] || " "; - const postfix = urlFePrefixToPostfix.get(prefix); - // @ts-ignore - let endPostfix = input.indexOf(postfix, start + length); - if (endPostfix === -1) { - endPostfix = input.length; - } - // Look for characters that terminate a URL - const terminalsRe = (prefix === "<") ? urlFeAutolinkTerminalsRe : urlFeBareTerminalsRe; - const endTerminal = start + input.slice(start).search(terminalsRe); - // Determine tentative end of URL - let end = Math.min(endPostfix, endTerminal); - if (prefix === " ") { - // If the URL used " " as pre/postfix characters, trim the end - if (input[end - 1] === ")") { - // Trim any ")" beyond the last "(...)" pair - const lastOpenParen = input.lastIndexOf("(", end - 2); - if (lastOpenParen <= start) { - end--; - } - else { - const nextCloseParen = input.indexOf(")", lastOpenParen + 1); - end = nextCloseParen + 1; - } - } - else { - // Trim unwanted punctuation - while (!urlFeNonTerminalsRe.includes(input[end - 1]) && - urlFePunctuationRe.test(input[end - 1])) { - end--; - } - } - } - return [start, end - start]; + // Find start of URL by searching for protocol + var match = input.match(urlFeProtocolRe); + if (match) { + // Look for matching pre/postfix characters (ex: <...>) + var start = match.index || 0; + var length = match[0].length; + var prefix = input[start - 1] || " "; + var postfix = urlFePrefixToPostfix.get(prefix); + // @ts-ignore + var endPostfix = input.indexOf(postfix, start + length); + if (endPostfix === -1) { + endPostfix = input.length; } - // No match - return null; + // Look for characters that terminate a URL + var terminalsRe = prefix === "<" ? urlFeAutolinkTerminalsRe : urlFeBareTerminalsRe; + var endTerminal = start + input.slice(start).search(terminalsRe); + // Determine tentative end of URL + var end = Math.min(endPostfix, endTerminal); + if (prefix === " ") { + // If the URL used " " as pre/postfix characters, trim the end + if (input[end - 1] === ")") { + // Trim any ")" beyond the last "(...)" pair + var lastOpenParen = input.lastIndexOf("(", end - 2); + if (lastOpenParen <= start) { + end--; + } else { + var nextCloseParen = input.indexOf(")", lastOpenParen + 1); + end = nextCloseParen + 1; + } + } else { + // Trim unwanted punctuation + while (!urlFeNonTerminalsRe.includes(input[end - 1]) && urlFePunctuationRe.test(input[end - 1])) { + end--; + } + } + } + return [start, end - start]; + } + // No match + return null; } module.exports.urlFe = urlFe; - /***/ }), /***/ "markdown-it": @@ -1314,12 +1437,13 @@ module.exports = markdownit; "use strict"; // @ts-check + + module.exports = { - "library": __webpack_require__(/*! .. */ "../lib/markdownlint.js"), - "helpers": __webpack_require__(/*! ../helpers */ "../helpers/helpers.js") + "library": __webpack_require__(/*! .. */ "../lib/markdownlint.js"), + "helpers": __webpack_require__(/*! ../helpers */ "../helpers/helpers.js") }; - /***/ }), /***/ "../lib/cache.js": @@ -1331,25 +1455,42 @@ module.exports = { "use strict"; // @ts-check -const map = new Map(); -module.exports.set = (keyValuePairs) => { - for (const [key, value] of Object.entries(keyValuePairs)) { - map.set(key, value); - } -}; -module.exports.clear = () => map.clear(); -module.exports.codeBlockAndSpanRanges = - () => map.get("codeBlockAndSpanRanges"); -module.exports.flattenedLists = - () => map.get("flattenedLists"); -module.exports.htmlElementRanges = - () => map.get("htmlElementRanges"); -module.exports.lineMetadata = - () => map.get("lineMetadata"); -module.exports.referenceLinkImageData = - () => map.get("referenceLinkImageData"); +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } +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."); } +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); } +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; } +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; } } +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } +var map = new Map(); +module.exports.set = function (keyValuePairs) { + for (var _i = 0, _Object$entries = Object.entries(keyValuePairs); _i < _Object$entries.length; _i++) { + var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), + key = _Object$entries$_i[0], + value = _Object$entries$_i[1]; + map.set(key, value); + } +}; +module.exports.clear = function () { + return map.clear(); +}; +module.exports.codeBlockAndSpanRanges = function () { + return map.get("codeBlockAndSpanRanges"); +}; +module.exports.flattenedLists = function () { + return map.get("flattenedLists"); +}; +module.exports.htmlElementRanges = function () { + return map.get("htmlElementRanges"); +}; +module.exports.lineMetadata = function () { + return map.get("lineMetadata"); +}; +module.exports.referenceLinkImageData = function () { + return map.get("referenceLinkImageData"); +}; + /***/ }), /***/ "../lib/constants.js": @@ -1361,18 +1502,13 @@ module.exports.referenceLinkImageData = "use strict"; // @ts-check + + module.exports.deprecatedRuleNames = ["MD002", "MD006"]; -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" -]; +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"]; module.exports.homepage = "https://github.com/DavidAnson/markdownlint"; module.exports.version = "0.27.0"; - /***/ }), /***/ "../lib/markdownlint.js": @@ -1384,17 +1520,40 @@ module.exports.version = "0.27.0"; "use strict"; // @ts-check -const path = __webpack_require__(/*! node:path */ "?9a52"); -const { promisify } = __webpack_require__(/*! node:util */ "?39e5"); -const markdownIt = __webpack_require__(/*! markdown-it */ "markdown-it"); -const { deprecatedRuleNames } = __webpack_require__(/*! ./constants */ "../lib/constants.js"); -const rules = __webpack_require__(/*! ./rules */ "../lib/rules.js"); -const helpers = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const cache = __webpack_require__(/*! ./cache */ "../lib/cache.js"); + + +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; } +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; } +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; } +function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } +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); } +function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } +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."); } +function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } +function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } +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); } +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } +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."); } +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; } } +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } +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; } } }; } +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); } +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; } +var path = __webpack_require__(/*! node:path */ "?9a52"); +var _require = __webpack_require__(/*! node:util */ "?39e5"), + promisify = _require.promisify; +var markdownIt = __webpack_require__(/*! markdown-it */ "markdown-it"); +var _require2 = __webpack_require__(/*! ./constants */ "../lib/constants.js"), + deprecatedRuleNames = _require2.deprecatedRuleNames; +var rules = __webpack_require__(/*! ./rules */ "../lib/rules.js"); +var helpers = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); +var cache = __webpack_require__(/*! ./cache */ "../lib/cache.js"); + // @ts-ignore // eslint-disable-next-line camelcase, max-len, no-inline-comments, no-undef -const dynamicRequire = (typeof require === "undefined") ? __webpack_require__("../lib sync recursive") : /* c8 ignore next */ require; +var dynamicRequire = typeof require === "undefined" ? __webpack_require__("../lib sync recursive") : /* c8 ignore next */require; // Capture native require implementation for dynamic loading of modules + /** * Validate the list of rules for structure and reuse. * @@ -1403,72 +1562,94 @@ const dynamicRequire = (typeof require === "undefined") ? __webpack_require__(". * @returns {Error | null} Error message if validation fails. */ function validateRuleList(ruleList, synchronous) { - let result = null; - if (ruleList.length === rules.length) { - // No need to validate if only using built-in rules - return result; + var result = null; + if (ruleList.length === rules.length) { + // No need to validate if only using built-in rules + return result; + } + var allIds = {}; + var _iterator = _createForOfIteratorHelper(ruleList.entries()), + _step; + try { + var _loop = function _loop() { + var _step$value = _slicedToArray(_step.value, 2), + index = _step$value[0], + rule = _step$value[1]; + var customIndex = index - rules.length; + // eslint-disable-next-line no-inner-declarations, jsdoc/require-jsdoc + function newError(property) { + return new Error("Property '" + property + "' of custom rule at index " + customIndex + " is incorrect."); + } + for (var _i2 = 0, _arr2 = ["names", "tags"]; _i2 < _arr2.length; _i2++) { + var property = _arr2[_i2]; + var value = rule[property]; + if (!result && (!value || !Array.isArray(value) || value.length === 0 || !value.every(helpers.isString) || value.some(helpers.isEmptyString))) { + result = newError(property); + } + } + for (var _i3 = 0, _arr3 = [["description", "string"], ["function", "function"]]; _i3 < _arr3.length; _i3++) { + var propertyInfo = _arr3[_i3]; + var _property = propertyInfo[0]; + var _value = rule[_property]; + if (!result && (!_value || _typeof(_value) !== propertyInfo[1])) { + result = newError(_property); + } + } + if (!result && rule.information && Object.getPrototypeOf(rule.information) !== URL.prototype) { + result = newError("information"); + } + if (!result && rule.asynchronous !== undefined && typeof rule.asynchronous !== "boolean") { + result = newError("asynchronous"); + } + if (!result && rule.asynchronous && synchronous) { + result = new Error("Custom rule " + rule.names.join("/") + " at index " + customIndex + " is asynchronous and can not be used in a synchronous context."); + } + if (!result) { + var _iterator2 = _createForOfIteratorHelper(rule.names), + _step2; + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var name = _step2.value; + var nameUpper = name.toUpperCase(); + if (!result && allIds[nameUpper] !== undefined) { + result = new Error("Name '" + name + "' of custom rule at index " + customIndex + " is already used as a name or tag."); + } + allIds[nameUpper] = true; + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + var _iterator3 = _createForOfIteratorHelper(rule.tags), + _step3; + try { + for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { + var tag = _step3.value; + var tagUpper = tag.toUpperCase(); + if (!result && allIds[tagUpper]) { + result = new Error("Tag '" + tag + "' of custom rule at index " + customIndex + " is already used as a name."); + } + allIds[tagUpper] = false; + } + } catch (err) { + _iterator3.e(err); + } finally { + _iterator3.f(); + } + } + }; + for (_iterator.s(); !(_step = _iterator.n()).done;) { + _loop(); } - const allIds = {}; - for (const [index, rule] of ruleList.entries()) { - const customIndex = index - rules.length; - // eslint-disable-next-line no-inner-declarations, jsdoc/require-jsdoc - function newError(property) { - return new Error("Property '" + property + "' of custom rule at index " + - customIndex + " is incorrect."); - } - for (const property of ["names", "tags"]) { - const value = rule[property]; - if (!result && - (!value || !Array.isArray(value) || (value.length === 0) || - !value.every(helpers.isString) || value.some(helpers.isEmptyString))) { - result = newError(property); - } - } - for (const propertyInfo of [ - ["description", "string"], - ["function", "function"] - ]) { - const property = propertyInfo[0]; - const value = rule[property]; - if (!result && (!value || (typeof value !== propertyInfo[1]))) { - result = newError(property); - } - } - if (!result && - rule.information && - (Object.getPrototypeOf(rule.information) !== URL.prototype)) { - result = newError("information"); - } - if (!result && - (rule.asynchronous !== undefined) && - (typeof rule.asynchronous !== "boolean")) { - result = newError("asynchronous"); - } - if (!result && rule.asynchronous && synchronous) { - result = new Error("Custom rule " + rule.names.join("/") + " at index " + customIndex + - " is asynchronous and can not be used in a synchronous context."); - } - if (!result) { - for (const name of rule.names) { - const nameUpper = name.toUpperCase(); - if (!result && (allIds[nameUpper] !== undefined)) { - result = new Error("Name '" + name + "' of custom rule at index " + - customIndex + " is already used as a name or tag."); - } - allIds[nameUpper] = true; - } - for (const tag of rule.tags) { - const tagUpper = tag.toUpperCase(); - if (!result && allIds[tagUpper]) { - result = new Error("Tag '" + tag + "' of custom rule at index " + - customIndex + " is already used as a name."); - } - allIds[tagUpper] = false; - } - } - } - return result; + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + return result; } + /** * Creates a LintResults instance with toString for pretty display. * @@ -1476,62 +1657,83 @@ function validateRuleList(ruleList, synchronous) { * @returns {LintResults} New LintResults instance. */ function newResults(ruleList) { - const lintResults = {}; - // eslint-disable-next-line jsdoc/require-jsdoc - function toString(useAlias) { - let ruleNameToRule = null; - const results = []; - const keys = Object.keys(lintResults); - keys.sort(); - for (const file of keys) { - const fileResults = lintResults[file]; - if (Array.isArray(fileResults)) { - for (const result of fileResults) { - const ruleMoniker = result.ruleNames ? - result.ruleNames.join("/") : - (result.ruleName + "/" + result.ruleAlias); - results.push(file + ": " + - result.lineNumber + ": " + - ruleMoniker + " " + - result.ruleDescription + - (result.errorDetail ? - " [" + result.errorDetail + "]" : - "") + - (result.errorContext ? - " [Context: \"" + result.errorContext + "\"]" : - "")); - } - } - else { - if (!ruleNameToRule) { - ruleNameToRule = {}; - for (const rule of ruleList) { - const ruleName = rule.names[0].toUpperCase(); - ruleNameToRule[ruleName] = rule; - } - } - for (const [ruleName, ruleResults] of Object.entries(fileResults)) { - const rule = ruleNameToRule[ruleName.toUpperCase()]; - for (const lineNumber of ruleResults) { - // @ts-ignore - const nameIndex = Math.min(useAlias ? 1 : 0, rule.names.length - 1); - const result = file + ": " + - lineNumber + ": " + - // @ts-ignore - rule.names[nameIndex] + " " + - // @ts-ignore - rule.description; - results.push(result); - } - } - } - } - return results.join("\n"); + var lintResults = {}; + // eslint-disable-next-line jsdoc/require-jsdoc + function toString(useAlias) { + var ruleNameToRule = null; + var results = []; + var keys = Object.keys(lintResults); + keys.sort(); + for (var _i4 = 0, _keys = keys; _i4 < _keys.length; _i4++) { + var file = _keys[_i4]; + var fileResults = lintResults[file]; + if (Array.isArray(fileResults)) { + var _iterator4 = _createForOfIteratorHelper(fileResults), + _step4; + try { + for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { + var result = _step4.value; + var ruleMoniker = result.ruleNames ? result.ruleNames.join("/") : result.ruleName + "/" + result.ruleAlias; + results.push(file + ": " + result.lineNumber + ": " + ruleMoniker + " " + result.ruleDescription + (result.errorDetail ? " [" + result.errorDetail + "]" : "") + (result.errorContext ? " [Context: \"" + result.errorContext + "\"]" : "")); + } + } catch (err) { + _iterator4.e(err); + } finally { + _iterator4.f(); + } + } else { + if (!ruleNameToRule) { + ruleNameToRule = {}; + var _iterator5 = _createForOfIteratorHelper(ruleList), + _step5; + try { + for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { + var rule = _step5.value; + var ruleName = rule.names[0].toUpperCase(); + ruleNameToRule[ruleName] = rule; + } + } catch (err) { + _iterator5.e(err); + } finally { + _iterator5.f(); + } + } + for (var _i5 = 0, _Object$entries = Object.entries(fileResults); _i5 < _Object$entries.length; _i5++) { + var _Object$entries$_i = _slicedToArray(_Object$entries[_i5], 2), + _ruleName = _Object$entries$_i[0], + ruleResults = _Object$entries$_i[1]; + var _rule = ruleNameToRule[_ruleName.toUpperCase()]; + var _iterator6 = _createForOfIteratorHelper(ruleResults), + _step6; + try { + for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { + var lineNumber = _step6.value; + // @ts-ignore + var nameIndex = Math.min(useAlias ? 1 : 0, _rule.names.length - 1); + var _result = file + ": " + lineNumber + ": " + + // @ts-ignore + _rule.names[nameIndex] + " " + + // @ts-ignore + _rule.description; + results.push(_result); + } + } catch (err) { + _iterator6.e(err); + } finally { + _iterator6.f(); + } + } + } } - Object.defineProperty(lintResults, "toString", { "value": toString }); - // @ts-ignore - return lintResults; + return results.join("\n"); + } + Object.defineProperty(lintResults, "toString", { + "value": toString + }); + // @ts-ignore + return lintResults; } + /** * Remove front matter (if present at beginning of content). * @@ -1540,24 +1742,24 @@ function newResults(ruleList) { * @returns {Object} Trimmed content and front matter lines. */ function removeFrontMatter(content, frontMatter) { - let frontMatterLines = []; - if (frontMatter) { - const frontMatterMatch = content.match(frontMatter); - if (frontMatterMatch && !frontMatterMatch.index) { - const contentMatched = frontMatterMatch[0]; - content = content.slice(contentMatched.length); - frontMatterLines = contentMatched.split(helpers.newLineRe); - if ((frontMatterLines.length > 0) && - (frontMatterLines[frontMatterLines.length - 1] === "")) { - frontMatterLines.length--; - } - } + var frontMatterLines = []; + if (frontMatter) { + var frontMatterMatch = content.match(frontMatter); + if (frontMatterMatch && !frontMatterMatch.index) { + var contentMatched = frontMatterMatch[0]; + content = content.slice(contentMatched.length); + frontMatterLines = contentMatched.split(helpers.newLineRe); + if (frontMatterLines.length > 0 && frontMatterLines[frontMatterLines.length - 1] === "") { + frontMatterLines.length--; + } } - return { - "content": content, - "frontMatterLines": frontMatterLines - }; + } + return { + "content": content, + "frontMatterLines": frontMatterLines + }; } + /** * Freeze all freeze-able members of a token and its children. * @@ -1565,23 +1767,42 @@ function removeFrontMatter(content, frontMatter) { * @returns {void} */ function freezeToken(token) { - if (token.attrs) { - for (const attr of token.attrs) { - Object.freeze(attr); - } - Object.freeze(token.attrs); - } - if (token.children) { - for (const child of token.children) { - freezeToken(child); - } - Object.freeze(token.children); + if (token.attrs) { + var _iterator7 = _createForOfIteratorHelper(token.attrs), + _step7; + try { + for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) { + var attr = _step7.value; + Object.freeze(attr); + } + } catch (err) { + _iterator7.e(err); + } finally { + _iterator7.f(); } - if (token.map) { - Object.freeze(token.map); + Object.freeze(token.attrs); + } + if (token.children) { + var _iterator8 = _createForOfIteratorHelper(token.children), + _step8; + try { + for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) { + var child = _step8.value; + freezeToken(child); + } + } catch (err) { + _iterator8.e(err); + } finally { + _iterator8.f(); } - Object.freeze(token); + Object.freeze(token.children); + } + if (token.map) { + Object.freeze(token.map); + } + Object.freeze(token); } + /** * Annotate tokens with line/lineNumber and freeze them. * @@ -1590,51 +1811,73 @@ function freezeToken(token) { * @returns {void} */ function annotateAndFreezeTokens(tokens, lines) { - let trMap = null; - for (const token of tokens) { - // Provide missing maps for table content - if (token.type === "tr_open") { - trMap = token.map; - } - else if (token.type === "tr_close") { - trMap = null; - } - if (!token.map && trMap) { - token.map = [...trMap]; - } - // Update token metadata - if (token.map) { - token.line = lines[token.map[0]]; - token.lineNumber = token.map[0] + 1; - // Trim bottom of token to exclude whitespace lines - while (token.map[1] && !((lines[token.map[1] - 1] || "").trim())) { - token.map[1]--; - } - } - // Annotate children with lineNumber - if (token.children) { - const codeSpanExtraLines = []; - if (token.children.some((child) => child.type === "code_inline")) { - helpers.forEachInlineCodeSpan(token.content, (code) => { - codeSpanExtraLines.push(code.split(helpers.newLineRe).length - 1); - }); - } - let lineNumber = token.lineNumber; - for (const child of token.children) { - child.lineNumber = lineNumber; - child.line = lines[lineNumber - 1]; - if ((child.type === "softbreak") || (child.type === "hardbreak")) { - lineNumber++; - } - else if (child.type === "code_inline") { - lineNumber += codeSpanExtraLines.shift(); - } - } - } - freezeToken(token); + var trMap = null; + var _iterator9 = _createForOfIteratorHelper(tokens), + _step9; + try { + var _loop2 = function _loop2() { + var token = _step9.value; + // Provide missing maps for table content + if (token.type === "tr_open") { + trMap = token.map; + } else if (token.type === "tr_close") { + trMap = null; + } + if (!token.map && trMap) { + token.map = _toConsumableArray(trMap); + } + // Update token metadata + if (token.map) { + token.line = lines[token.map[0]]; + token.lineNumber = token.map[0] + 1; + // Trim bottom of token to exclude whitespace lines + while (token.map[1] && !(lines[token.map[1] - 1] || "").trim()) { + token.map[1]--; + } + } + // Annotate children with lineNumber + if (token.children) { + var codeSpanExtraLines = []; + if (token.children.some(function (child) { + return child.type === "code_inline"; + })) { + helpers.forEachInlineCodeSpan(token.content, function (code) { + codeSpanExtraLines.push(code.split(helpers.newLineRe).length - 1); + }); + } + var lineNumber = token.lineNumber; + var _iterator10 = _createForOfIteratorHelper(token.children), + _step10; + try { + for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) { + var child = _step10.value; + child.lineNumber = lineNumber; + child.line = lines[lineNumber - 1]; + if (child.type === "softbreak" || child.type === "hardbreak") { + lineNumber++; + } else if (child.type === "code_inline") { + lineNumber += codeSpanExtraLines.shift(); + } + } + } catch (err) { + _iterator10.e(err); + } finally { + _iterator10.f(); + } + } + freezeToken(token); + }; + for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) { + _loop2(); } - Object.freeze(tokens); + } catch (err) { + _iterator9.e(err); + } finally { + _iterator9.f(); + } + Object.freeze(tokens); } + /** * Map rule names/tags to canonical rule name. * @@ -1642,25 +1885,47 @@ function annotateAndFreezeTokens(tokens, lines) { * @returns {Object.} Map of alias to rule name. */ function mapAliasToRuleNames(ruleList) { - const aliasToRuleNames = {}; - // const tagToRuleNames = {}; - for (const rule of ruleList) { - const ruleName = rule.names[0].toUpperCase(); - // The following is useful for updating README.md: - // console.log( - // "* **[" + ruleName + "](doc/Rules.md#" + ruleName.toLowerCase() + - // ")** *" + rule.names.slice(1).join("/") + "* - " + rule.description); - for (const name of rule.names) { - const nameUpper = name.toUpperCase(); - aliasToRuleNames[nameUpper] = [ruleName]; - } - for (const tag of rule.tags) { - const tagUpper = tag.toUpperCase(); - const ruleNames = aliasToRuleNames[tagUpper] || []; - ruleNames.push(ruleName); - aliasToRuleNames[tagUpper] = ruleNames; - // tagToRuleNames[tag] = ruleName; - } + var aliasToRuleNames = {}; + // const tagToRuleNames = {}; + var _iterator11 = _createForOfIteratorHelper(ruleList), + _step11; + try { + for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) { + var rule = _step11.value; + var ruleName = rule.names[0].toUpperCase(); + // The following is useful for updating README.md: + // console.log( + // "* **[" + ruleName + "](doc/Rules.md#" + ruleName.toLowerCase() + + // ")** *" + rule.names.slice(1).join("/") + "* - " + rule.description); + var _iterator12 = _createForOfIteratorHelper(rule.names), + _step12; + try { + for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) { + var name = _step12.value; + var nameUpper = name.toUpperCase(); + aliasToRuleNames[nameUpper] = [ruleName]; + } + } catch (err) { + _iterator12.e(err); + } finally { + _iterator12.f(); + } + var _iterator13 = _createForOfIteratorHelper(rule.tags), + _step13; + try { + for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) { + var tag = _step13.value; + var tagUpper = tag.toUpperCase(); + var ruleNames = aliasToRuleNames[tagUpper] || []; + ruleNames.push(ruleName); + aliasToRuleNames[tagUpper] = ruleNames; + // tagToRuleNames[tag] = ruleName; + } + } catch (err) { + _iterator13.e(err); + } finally { + _iterator13.f(); + } } // The following is useful for updating README.md: // Object.keys(tagToRuleNames).sort().forEach(function forTag(tag) { @@ -1668,8 +1933,14 @@ function mapAliasToRuleNames(ruleList) { // aliasToRuleNames[tag.toUpperCase()].join(", ")); // }); // @ts-ignore - return aliasToRuleNames; + } catch (err) { + _iterator11.e(err); + } finally { + _iterator11.f(); + } + return aliasToRuleNames; } + /** * Apply (and normalize) configuration object. * @@ -1680,33 +1951,63 @@ function mapAliasToRuleNames(ruleList) { * @returns {Configuration} Effective configuration. */ function getEffectiveConfig(ruleList, config, aliasToRuleNames) { - const defaultKey = Object.keys(config).filter((key) => key.toUpperCase() === "DEFAULT"); - const ruleDefault = (defaultKey.length === 0) || !!config[defaultKey[0]]; - const effectiveConfig = {}; - for (const rule of ruleList) { - const ruleName = rule.names[0].toUpperCase(); - effectiveConfig[ruleName] = ruleDefault; + var defaultKey = Object.keys(config).filter(function (key) { + return key.toUpperCase() === "DEFAULT"; + }); + var ruleDefault = defaultKey.length === 0 || !!config[defaultKey[0]]; + var effectiveConfig = {}; + var _iterator14 = _createForOfIteratorHelper(ruleList), + _step14; + try { + for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) { + var rule = _step14.value; + var _ruleName2 = rule.names[0].toUpperCase(); + effectiveConfig[_ruleName2] = ruleDefault; } - for (const ruleName of deprecatedRuleNames) { - effectiveConfig[ruleName] = false; + } catch (err) { + _iterator14.e(err); + } finally { + _iterator14.f(); + } + var _iterator15 = _createForOfIteratorHelper(deprecatedRuleNames), + _step15; + try { + for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) { + var _ruleName3 = _step15.value; + effectiveConfig[_ruleName3] = false; } - for (const key of Object.keys(config)) { - let value = config[key]; - if (value) { - if (!(value instanceof Object)) { - value = {}; - } - } - else { - value = false; - } - const keyUpper = key.toUpperCase(); - for (const ruleName of (aliasToRuleNames[keyUpper] || [])) { - effectiveConfig[ruleName] = value; - } + } catch (err) { + _iterator15.e(err); + } finally { + _iterator15.f(); + } + for (var _i6 = 0, _Object$keys = Object.keys(config); _i6 < _Object$keys.length; _i6++) { + var key = _Object$keys[_i6]; + var value = config[key]; + if (value) { + if (!(value instanceof Object)) { + value = {}; + } + } else { + value = false; } - return effectiveConfig; + var keyUpper = key.toUpperCase(); + var _iterator16 = _createForOfIteratorHelper(aliasToRuleNames[keyUpper] || []), + _step16; + try { + for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) { + var ruleName = _step16.value; + effectiveConfig[ruleName] = value; + } + } catch (err) { + _iterator16.e(err); + } finally { + _iterator16.f(); + } + } + return effectiveConfig; } + /** * Parse the content of a configuration file. * @@ -1716,30 +2017,30 @@ function getEffectiveConfig(ruleList, config, aliasToRuleNames) { * @returns {Object} Configuration object and error message. */ function parseConfiguration(name, content, parsers) { - let config = null; - let message = ""; - const errors = []; - let index = 0; - // Try each parser - (parsers || [JSON.parse]).every((parser) => { - try { - config = parser(content); - } - catch (error) { - errors.push(`Parser ${index++}: ${error.message}`); - } - return !config; - }); - // Message if unable to parse - if (!config) { - errors.unshift(`Unable to parse '${name}'`); - message = errors.join("; "); + var config = null; + var message = ""; + var errors = []; + var index = 0; + // Try each parser + (parsers || [JSON.parse]).every(function (parser) { + try { + config = parser(content); + } catch (error) { + errors.push("Parser ".concat(index++, ": ").concat(error.message)); } - return { - config, - message - }; + return !config; + }); + // Message if unable to parse + if (!config) { + errors.unshift("Unable to parse '".concat(name, "'")); + message = errors.join("; "); + } + return { + config: config, + message: message + }; } + /** * Create a mapping of enabled rules per line. * @@ -1754,105 +2055,142 @@ function parseConfiguration(name, content, parsers) { * @returns {Object} Effective configuration and enabled rules per line number. */ function getEnabledRulesPerLineNumber(ruleList, lines, frontMatterLines, noInlineConfig, config, configParsers, aliasToRuleNames) { - // Shared variables - let enabledRules = {}; - let capturedRules = {}; - const allRuleNames = []; - const enabledRulesPerLineNumber = new Array(1 + frontMatterLines.length); - // Helper functions - // eslint-disable-next-line jsdoc/require-jsdoc - function handleInlineConfig(input, forEachMatch, forEachLine) { - for (const [lineIndex, line] of input.entries()) { - if (!noInlineConfig) { - let match = null; - while ((match = helpers.inlineCommentStartRe.exec(line))) { - const action = match[2].toUpperCase(); - const startIndex = match.index + match[1].length; - const endIndex = line.indexOf("-->", startIndex); - if (endIndex === -1) { - break; - } - const parameter = line.slice(startIndex, endIndex); - forEachMatch(action, parameter, lineIndex + 1); - } - } - if (forEachLine) { - forEachLine(); - } - } + // Shared variables + var enabledRules = {}; + var capturedRules = {}; + var allRuleNames = []; + var enabledRulesPerLineNumber = new Array(1 + frontMatterLines.length); + // Helper functions + // eslint-disable-next-line jsdoc/require-jsdoc + function handleInlineConfig(input, forEachMatch, forEachLine) { + var _iterator17 = _createForOfIteratorHelper(input.entries()), + _step17; + try { + for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) { + var _step17$value = _slicedToArray(_step17.value, 2), + lineIndex = _step17$value[0], + line = _step17$value[1]; + if (!noInlineConfig) { + var match = null; + while (match = helpers.inlineCommentStartRe.exec(line)) { + var action = match[2].toUpperCase(); + var startIndex = match.index + match[1].length; + var endIndex = line.indexOf("-->", startIndex); + if (endIndex === -1) { + break; + } + var parameter = line.slice(startIndex, endIndex); + forEachMatch(action, parameter, lineIndex + 1); + } + } + if (forEachLine) { + forEachLine(); + } + } + } catch (err) { + _iterator17.e(err); + } finally { + _iterator17.f(); } - // eslint-disable-next-line jsdoc/require-jsdoc - function configureFile(action, parameter) { - if (action === "CONFIGURE-FILE") { - const { "config": parsed } = parseConfiguration("CONFIGURE-FILE", parameter, configParsers); - if (parsed) { - config = Object.assign(Object.assign({}, config), parsed); - } - } + } + // eslint-disable-next-line jsdoc/require-jsdoc + function configureFile(action, parameter) { + if (action === "CONFIGURE-FILE") { + var _parseConfiguration = parseConfiguration("CONFIGURE-FILE", parameter, configParsers), + parsed = _parseConfiguration["config"]; + if (parsed) { + config = _objectSpread(_objectSpread({}, config), parsed); + } } - // eslint-disable-next-line jsdoc/require-jsdoc - function applyEnableDisable(action, parameter, state) { - state = Object.assign({}, state); - const enabled = (action.startsWith("ENABLE")); - const trimmed = parameter && parameter.trim(); - const items = trimmed ? trimmed.toUpperCase().split(/\s+/) : allRuleNames; - for (const nameUpper of items) { - for (const ruleName of (aliasToRuleNames[nameUpper] || [])) { - state[ruleName] = enabled; - } - } - return state; + } + // eslint-disable-next-line jsdoc/require-jsdoc + function applyEnableDisable(action, parameter, state) { + state = _objectSpread({}, state); + var enabled = action.startsWith("ENABLE"); + var trimmed = parameter && parameter.trim(); + var items = trimmed ? trimmed.toUpperCase().split(/\s+/) : allRuleNames; + var _iterator18 = _createForOfIteratorHelper(items), + _step18; + try { + for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) { + var nameUpper = _step18.value; + var _iterator19 = _createForOfIteratorHelper(aliasToRuleNames[nameUpper] || []), + _step19; + try { + for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) { + var ruleName = _step19.value; + state[ruleName] = enabled; + } + } catch (err) { + _iterator19.e(err); + } finally { + _iterator19.f(); + } + } + } catch (err) { + _iterator18.e(err); + } finally { + _iterator18.f(); } - // eslint-disable-next-line jsdoc/require-jsdoc - function enableDisableFile(action, parameter) { - if ((action === "ENABLE-FILE") || (action === "DISABLE-FILE")) { - enabledRules = applyEnableDisable(action, parameter, enabledRules); - } + return state; + } + // eslint-disable-next-line jsdoc/require-jsdoc + function enableDisableFile(action, parameter) { + if (action === "ENABLE-FILE" || action === "DISABLE-FILE") { + enabledRules = applyEnableDisable(action, parameter, enabledRules); } - // eslint-disable-next-line jsdoc/require-jsdoc - function captureRestoreEnableDisable(action, parameter) { - if (action === "CAPTURE") { - capturedRules = enabledRules; - } - else if (action === "RESTORE") { - enabledRules = capturedRules; - } - else if ((action === "ENABLE") || (action === "DISABLE")) { - enabledRules = applyEnableDisable(action, parameter, enabledRules); - } + } + // eslint-disable-next-line jsdoc/require-jsdoc + function captureRestoreEnableDisable(action, parameter) { + if (action === "CAPTURE") { + capturedRules = enabledRules; + } else if (action === "RESTORE") { + enabledRules = capturedRules; + } else if (action === "ENABLE" || action === "DISABLE") { + enabledRules = applyEnableDisable(action, parameter, enabledRules); } - // eslint-disable-next-line jsdoc/require-jsdoc - function updateLineState() { - enabledRulesPerLineNumber.push(enabledRules); + } + // eslint-disable-next-line jsdoc/require-jsdoc + function updateLineState() { + enabledRulesPerLineNumber.push(enabledRules); + } + // eslint-disable-next-line jsdoc/require-jsdoc + function disableLineNextLine(action, parameter, lineNumber) { + var disableLine = action === "DISABLE-LINE"; + var disableNextLine = action === "DISABLE-NEXT-LINE"; + if (disableLine || disableNextLine) { + var nextLineNumber = frontMatterLines.length + lineNumber + (disableNextLine ? 1 : 0); + enabledRulesPerLineNumber[nextLineNumber] = applyEnableDisable(action, parameter, enabledRulesPerLineNumber[nextLineNumber] || {}); } - // eslint-disable-next-line jsdoc/require-jsdoc - function disableLineNextLine(action, parameter, lineNumber) { - const disableLine = (action === "DISABLE-LINE"); - const disableNextLine = (action === "DISABLE-NEXT-LINE"); - if (disableLine || disableNextLine) { - const nextLineNumber = frontMatterLines.length + lineNumber + (disableNextLine ? 1 : 0); - enabledRulesPerLineNumber[nextLineNumber] = - applyEnableDisable(action, parameter, enabledRulesPerLineNumber[nextLineNumber] || {}); - } - } - // Handle inline comments - handleInlineConfig([lines.join("\n")], configureFile); - const effectiveConfig = getEffectiveConfig(ruleList, config, aliasToRuleNames); - for (const rule of ruleList) { - const ruleName = rule.names[0].toUpperCase(); - allRuleNames.push(ruleName); - enabledRules[ruleName] = !!effectiveConfig[ruleName]; + } + // Handle inline comments + handleInlineConfig([lines.join("\n")], configureFile); + var effectiveConfig = getEffectiveConfig(ruleList, config, aliasToRuleNames); + var _iterator20 = _createForOfIteratorHelper(ruleList), + _step20; + try { + for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) { + var rule = _step20.value; + var ruleName = rule.names[0].toUpperCase(); + allRuleNames.push(ruleName); + enabledRules[ruleName] = !!effectiveConfig[ruleName]; } - capturedRules = enabledRules; - handleInlineConfig(lines, enableDisableFile); - handleInlineConfig(lines, captureRestoreEnableDisable, updateLineState); - handleInlineConfig(lines, disableLineNextLine); - // Return results - return { - effectiveConfig, - enabledRulesPerLineNumber - }; + } catch (err) { + _iterator20.e(err); + } finally { + _iterator20.f(); + } + capturedRules = enabledRules; + handleInlineConfig(lines, enableDisableFile); + handleInlineConfig(lines, captureRestoreEnableDisable, updateLineState); + handleInlineConfig(lines, disableLineNextLine); + // Return results + return { + effectiveConfig: effectiveConfig, + enabledRulesPerLineNumber: enabledRulesPerLineNumber + }; } + /** * Lints a string containing Markdown content. * @@ -1870,232 +2208,240 @@ function getEnabledRulesPerLineNumber(ruleList, lines, frontMatterLines, noInlin * @returns {void} */ function lintContent(ruleList, name, content, md, config, configParsers, frontMatter, handleRuleFailures, noInlineConfig, resultVersion, callback) { - // Remove UTF-8 byte order marker (if present) - content = content.replace(/^\uFEFF/, ""); - // Remove front matter - const removeFrontMatterResult = removeFrontMatter(content, frontMatter); - const { frontMatterLines } = removeFrontMatterResult; - content = removeFrontMatterResult.content; - // Get enabled rules per line (with HTML comments present) - const { effectiveConfig, enabledRulesPerLineNumber } = getEnabledRulesPerLineNumber(ruleList, content.split(helpers.newLineRe), frontMatterLines, noInlineConfig, config, configParsers, mapAliasToRuleNames(ruleList)); - // Hide the content of HTML comments from rules, etc. - content = helpers.clearHtmlCommentText(content); - // Parse content into tokens and lines - const tokens = md.parse(content, {}); - const lines = content.split(helpers.newLineRe); - annotateAndFreezeTokens(tokens, lines); - // Create (frozen) parameters for rules - const paramsBase = { - name, - tokens, - "lines": Object.freeze(lines), - "frontMatterLines": Object.freeze(frontMatterLines) - }; - const lineMetadata = helpers.getLineMetadata(paramsBase); - const codeBlockAndSpanRanges = helpers.codeBlockAndSpanRanges(paramsBase, lineMetadata); - const flattenedLists = helpers.flattenLists(paramsBase.tokens); - const htmlElementRanges = helpers.htmlElementRanges(paramsBase, lineMetadata); - const referenceLinkImageData = helpers.getReferenceLinkImageData(lineMetadata); - cache.set({ - codeBlockAndSpanRanges, - flattenedLists, - htmlElementRanges, - lineMetadata, - referenceLinkImageData + // Remove UTF-8 byte order marker (if present) + content = content.replace(/^\uFEFF/, ""); + // Remove front matter + var removeFrontMatterResult = removeFrontMatter(content, frontMatter); + var frontMatterLines = removeFrontMatterResult.frontMatterLines; + content = removeFrontMatterResult.content; + // Get enabled rules per line (with HTML comments present) + var _getEnabledRulesPerLi = getEnabledRulesPerLineNumber(ruleList, content.split(helpers.newLineRe), frontMatterLines, noInlineConfig, config, configParsers, mapAliasToRuleNames(ruleList)), + effectiveConfig = _getEnabledRulesPerLi.effectiveConfig, + enabledRulesPerLineNumber = _getEnabledRulesPerLi.enabledRulesPerLineNumber; + // Hide the content of HTML comments from rules, etc. + content = helpers.clearHtmlCommentText(content); + // Parse content into tokens and lines + var tokens = md.parse(content, {}); + var lines = content.split(helpers.newLineRe); + annotateAndFreezeTokens(tokens, lines); + // Create (frozen) parameters for rules + var paramsBase = { + name: name, + tokens: tokens, + "lines": Object.freeze(lines), + "frontMatterLines": Object.freeze(frontMatterLines) + }; + var lineMetadata = helpers.getLineMetadata(paramsBase); + var codeBlockAndSpanRanges = helpers.codeBlockAndSpanRanges(paramsBase, lineMetadata); + var flattenedLists = helpers.flattenLists(paramsBase.tokens); + var htmlElementRanges = helpers.htmlElementRanges(paramsBase, lineMetadata); + var referenceLinkImageData = helpers.getReferenceLinkImageData(lineMetadata); + cache.set({ + codeBlockAndSpanRanges: codeBlockAndSpanRanges, + flattenedLists: flattenedLists, + htmlElementRanges: htmlElementRanges, + lineMetadata: lineMetadata, + referenceLinkImageData: referenceLinkImageData + }); + // Function to run for each rule + var results = []; + // eslint-disable-next-line jsdoc/require-jsdoc + function forRule(rule) { + // Configure rule + var ruleName = rule.names[0].toUpperCase(); + var params = _objectSpread(_objectSpread({}, paramsBase), {}, { + "config": effectiveConfig[ruleName] }); - // Function to run for each rule - let results = []; // eslint-disable-next-line jsdoc/require-jsdoc - function forRule(rule) { - // Configure rule - const ruleName = rule.names[0].toUpperCase(); - const params = Object.assign(Object.assign({}, paramsBase), { "config": effectiveConfig[ruleName] }); - // eslint-disable-next-line jsdoc/require-jsdoc - function throwError(property) { - throw new Error("Property '" + property + "' of onError parameter is incorrect."); - } - // eslint-disable-next-line jsdoc/require-jsdoc - function onError(errorInfo) { - if (!errorInfo || - !helpers.isNumber(errorInfo.lineNumber) || - (errorInfo.lineNumber < 1) || - (errorInfo.lineNumber > lines.length)) { - throwError("lineNumber"); - } - const lineNumber = errorInfo.lineNumber + frontMatterLines.length; - if (!enabledRulesPerLineNumber[lineNumber][ruleName]) { - return; - } - if (errorInfo.detail && - !helpers.isString(errorInfo.detail)) { - throwError("detail"); - } - if (errorInfo.context && - !helpers.isString(errorInfo.context)) { - throwError("context"); - } - 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))) { - throwError("range"); - } - const fixInfo = errorInfo.fixInfo; - const cleanFixInfo = {}; - if (fixInfo) { - if (!helpers.isObject(fixInfo)) { - throwError("fixInfo"); - } - if (fixInfo.lineNumber !== undefined) { - if ((!helpers.isNumber(fixInfo.lineNumber) || - (fixInfo.lineNumber < 1) || - (fixInfo.lineNumber > lines.length))) { - throwError("fixInfo.lineNumber"); - } - cleanFixInfo.lineNumber = - fixInfo.lineNumber + frontMatterLines.length; - } - const effectiveLineNumber = fixInfo.lineNumber || errorInfo.lineNumber; - if (fixInfo.editColumn !== undefined) { - if ((!helpers.isNumber(fixInfo.editColumn) || - (fixInfo.editColumn < 1) || - (fixInfo.editColumn > - lines[effectiveLineNumber - 1].length + 1))) { - throwError("fixInfo.editColumn"); - } - cleanFixInfo.editColumn = fixInfo.editColumn; - } - if (fixInfo.deleteCount !== undefined) { - if ((!helpers.isNumber(fixInfo.deleteCount) || - (fixInfo.deleteCount < -1) || - (fixInfo.deleteCount > - lines[effectiveLineNumber - 1].length))) { - throwError("fixInfo.deleteCount"); - } - cleanFixInfo.deleteCount = fixInfo.deleteCount; - } - if (fixInfo.insertText !== undefined) { - if (!helpers.isString(fixInfo.insertText)) { - throwError("fixInfo.insertText"); - } - cleanFixInfo.insertText = fixInfo.insertText; - } - } - results.push({ - lineNumber, - "ruleName": rule.names[0], - "ruleNames": rule.names, - "ruleDescription": rule.description, - "ruleInformation": rule.information ? rule.information.href : null, - "errorDetail": errorInfo.detail || null, - "errorContext": errorInfo.context || null, - "errorRange": errorInfo.range ? [...errorInfo.range] : null, - "fixInfo": fixInfo ? cleanFixInfo : null - }); - } - // Call (possibly external) rule function to report errors - const catchCallsOnError = (error) => onError({ - "lineNumber": 1, - "detail": `This rule threw an exception: ${error.message || error}` - }); - const invokeRuleFunction = () => rule.function(params, onError); - if (rule.asynchronous) { - // Asynchronous rule, ensure it returns a Promise - const ruleFunctionPromise = Promise.resolve().then(invokeRuleFunction); - return handleRuleFailures ? - ruleFunctionPromise.catch(catchCallsOnError) : - ruleFunctionPromise; - } - // Synchronous rule - try { - invokeRuleFunction(); - } - catch (error) { - if (handleRuleFailures) { - catchCallsOnError(error); - } - else { - throw error; - } - } - return null; + function throwError(property) { + throw new Error("Property '" + property + "' of onError parameter is incorrect."); } // eslint-disable-next-line jsdoc/require-jsdoc - function formatResults() { - // Sort results by rule name by line number - results.sort((a, b) => (a.ruleName.localeCompare(b.ruleName) || - a.lineNumber - b.lineNumber)); - if (resultVersion < 3) { - // Remove fixInfo and multiple errors for the same rule and line number - const noPrevious = { - "ruleName": null, - "lineNumber": -1 - }; - results = results.filter((error, index, array) => { - delete error.fixInfo; - const previous = array[index - 1] || noPrevious; - return ((error.ruleName !== previous.ruleName) || - (error.lineNumber !== previous.lineNumber)); - }); - } - if (resultVersion === 0) { - // Return a dictionary of rule->[line numbers] - const dictionary = {}; - for (const error of results) { - const ruleLines = dictionary[error.ruleName] || []; - ruleLines.push(error.lineNumber); - dictionary[error.ruleName] = ruleLines; - } - // @ts-ignore - results = dictionary; - } - else if (resultVersion === 1) { - // Use ruleAlias instead of ruleNames - for (const error of results) { - error.ruleAlias = error.ruleNames[1] || error.ruleName; - delete error.ruleNames; - } - } - else { - // resultVersion 2 or 3: Remove unwanted ruleName - for (const error of results) { - delete error.ruleName; - } - } - return results; + function onError(errorInfo) { + if (!errorInfo || !helpers.isNumber(errorInfo.lineNumber) || errorInfo.lineNumber < 1 || errorInfo.lineNumber > lines.length) { + throwError("lineNumber"); + } + var lineNumber = errorInfo.lineNumber + frontMatterLines.length; + if (!enabledRulesPerLineNumber[lineNumber][ruleName]) { + return; + } + if (errorInfo.detail && !helpers.isString(errorInfo.detail)) { + throwError("detail"); + } + if (errorInfo.context && !helpers.isString(errorInfo.context)) { + throwError("context"); + } + 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)) { + throwError("range"); + } + var fixInfo = errorInfo.fixInfo; + var cleanFixInfo = {}; + if (fixInfo) { + if (!helpers.isObject(fixInfo)) { + throwError("fixInfo"); + } + if (fixInfo.lineNumber !== undefined) { + if (!helpers.isNumber(fixInfo.lineNumber) || fixInfo.lineNumber < 1 || fixInfo.lineNumber > lines.length) { + throwError("fixInfo.lineNumber"); + } + cleanFixInfo.lineNumber = fixInfo.lineNumber + frontMatterLines.length; + } + var effectiveLineNumber = fixInfo.lineNumber || errorInfo.lineNumber; + if (fixInfo.editColumn !== undefined) { + if (!helpers.isNumber(fixInfo.editColumn) || fixInfo.editColumn < 1 || fixInfo.editColumn > lines[effectiveLineNumber - 1].length + 1) { + throwError("fixInfo.editColumn"); + } + cleanFixInfo.editColumn = fixInfo.editColumn; + } + if (fixInfo.deleteCount !== undefined) { + if (!helpers.isNumber(fixInfo.deleteCount) || fixInfo.deleteCount < -1 || fixInfo.deleteCount > lines[effectiveLineNumber - 1].length) { + throwError("fixInfo.deleteCount"); + } + cleanFixInfo.deleteCount = fixInfo.deleteCount; + } + if (fixInfo.insertText !== undefined) { + if (!helpers.isString(fixInfo.insertText)) { + throwError("fixInfo.insertText"); + } + cleanFixInfo.insertText = fixInfo.insertText; + } + } + results.push({ + lineNumber: lineNumber, + "ruleName": rule.names[0], + "ruleNames": rule.names, + "ruleDescription": rule.description, + "ruleInformation": rule.information ? rule.information.href : null, + "errorDetail": errorInfo.detail || null, + "errorContext": errorInfo.context || null, + "errorRange": errorInfo.range ? _toConsumableArray(errorInfo.range) : null, + "fixInfo": fixInfo ? cleanFixInfo : null + }); } - // Run all rules - const ruleListAsync = ruleList.filter((rule) => rule.asynchronous); - const ruleListSync = ruleList.filter((rule) => !rule.asynchronous); - const ruleListAsyncFirst = [ - ...ruleListAsync, - ...ruleListSync - ]; - const callbackSuccess = () => callback(null, formatResults()); - const callbackError = (error) => callback(error instanceof Error ? error : new Error(error)); + // Call (possibly external) rule function to report errors + var catchCallsOnError = function catchCallsOnError(error) { + return onError({ + "lineNumber": 1, + "detail": "This rule threw an exception: ".concat(error.message || error) + }); + }; + var invokeRuleFunction = function invokeRuleFunction() { + return rule["function"](params, onError); + }; + if (rule.asynchronous) { + // Asynchronous rule, ensure it returns a Promise + var ruleFunctionPromise = Promise.resolve().then(invokeRuleFunction); + return handleRuleFailures ? ruleFunctionPromise["catch"](catchCallsOnError) : ruleFunctionPromise; + } + // Synchronous rule try { - const ruleResults = ruleListAsyncFirst.map(forRule); - if (ruleListAsync.length > 0) { - Promise.all(ruleResults.slice(0, ruleListAsync.length)) - .then(callbackSuccess) - .catch(callbackError); - } - else { - callbackSuccess(); - } + invokeRuleFunction(); + } catch (error) { + if (handleRuleFailures) { + catchCallsOnError(error); + } else { + throw error; + } } - catch (error) { - callbackError(error); + return null; + } + // eslint-disable-next-line jsdoc/require-jsdoc + function formatResults() { + // Sort results by rule name by line number + results.sort(function (a, b) { + return a.ruleName.localeCompare(b.ruleName) || a.lineNumber - b.lineNumber; + }); + if (resultVersion < 3) { + // Remove fixInfo and multiple errors for the same rule and line number + var noPrevious = { + "ruleName": null, + "lineNumber": -1 + }; + results = results.filter(function (error, index, array) { + delete error.fixInfo; + var previous = array[index - 1] || noPrevious; + return error.ruleName !== previous.ruleName || error.lineNumber !== previous.lineNumber; + }); } - finally { - cache.clear(); + if (resultVersion === 0) { + // Return a dictionary of rule->[line numbers] + var dictionary = {}; + var _iterator21 = _createForOfIteratorHelper(results), + _step21; + try { + for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) { + var error = _step21.value; + var ruleLines = dictionary[error.ruleName] || []; + ruleLines.push(error.lineNumber); + dictionary[error.ruleName] = ruleLines; + } + // @ts-ignore + } catch (err) { + _iterator21.e(err); + } finally { + _iterator21.f(); + } + results = dictionary; + } else if (resultVersion === 1) { + // Use ruleAlias instead of ruleNames + var _iterator22 = _createForOfIteratorHelper(results), + _step22; + try { + for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) { + var _error = _step22.value; + _error.ruleAlias = _error.ruleNames[1] || _error.ruleName; + delete _error.ruleNames; + } + } catch (err) { + _iterator22.e(err); + } finally { + _iterator22.f(); + } + } else { + // resultVersion 2 or 3: Remove unwanted ruleName + var _iterator23 = _createForOfIteratorHelper(results), + _step23; + try { + for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) { + var _error2 = _step23.value; + delete _error2.ruleName; + } + } catch (err) { + _iterator23.e(err); + } finally { + _iterator23.f(); + } } + return results; + } + // Run all rules + var ruleListAsync = ruleList.filter(function (rule) { + return rule.asynchronous; + }); + var ruleListSync = ruleList.filter(function (rule) { + return !rule.asynchronous; + }); + var ruleListAsyncFirst = [].concat(_toConsumableArray(ruleListAsync), _toConsumableArray(ruleListSync)); + var callbackSuccess = function callbackSuccess() { + return callback(null, formatResults()); + }; + var callbackError = function callbackError(error) { + return callback(error instanceof Error ? error : new Error(error)); + }; + try { + var ruleResults = ruleListAsyncFirst.map(forRule); + if (ruleListAsync.length > 0) { + Promise.all(ruleResults.slice(0, ruleListAsync.length)).then(callbackSuccess)["catch"](callbackError); + } else { + callbackSuccess(); + } + } catch (error) { + callbackError(error); + } finally { + cache.clear(); + } } + /** * Lints a file containing Markdown content. * @@ -2114,21 +2460,21 @@ function lintContent(ruleList, name, content, md, config, configParsers, frontMa * @returns {void} */ function lintFile(ruleList, file, md, config, configParsers, frontMatter, handleRuleFailures, noInlineConfig, resultVersion, fs, synchronous, callback) { - // eslint-disable-next-line jsdoc/require-jsdoc - function lintContentWrapper(err, content) { - if (err) { - return callback(err); - } - return lintContent(ruleList, file, content, md, config, configParsers, frontMatter, handleRuleFailures, noInlineConfig, resultVersion, callback); - } - // Make a/synchronous call to read file - if (synchronous) { - lintContentWrapper(null, fs.readFileSync(file, "utf8")); - } - else { - fs.readFile(file, "utf8", lintContentWrapper); + // eslint-disable-next-line jsdoc/require-jsdoc + function lintContentWrapper(err, content) { + if (err) { + return callback(err); } + return lintContent(ruleList, file, content, md, config, configParsers, frontMatter, handleRuleFailures, noInlineConfig, resultVersion, callback); + } + // Make a/synchronous call to read file + if (synchronous) { + lintContentWrapper(null, fs.readFileSync(file, "utf8")); + } else { + fs.readFile(file, "utf8", lintContentWrapper); + } } + /** * Lint files and strings specified in the Options object. * @@ -2138,99 +2484,106 @@ function lintFile(ruleList, file, md, config, configParsers, frontMatter, handle * @returns {void} */ function lintInput(options, synchronous, callback) { - // Normalize inputs - options = options || {}; - callback = callback || function noop() { }; - // eslint-disable-next-line unicorn/prefer-spread - const ruleList = rules.concat(options.customRules || []); - const ruleErr = validateRuleList(ruleList, synchronous); - if (ruleErr) { - callback(ruleErr); - return; + // Normalize inputs + options = options || {}; + callback = callback || function noop() {}; + // eslint-disable-next-line unicorn/prefer-spread + var ruleList = rules.concat(options.customRules || []); + var ruleErr = validateRuleList(ruleList, synchronous); + if (ruleErr) { + callback(ruleErr); + return; + } + var files = []; + if (Array.isArray(options.files)) { + files = _toConsumableArray(options.files); + } else if (options.files) { + files = [String(options.files)]; + } + var strings = options.strings || {}; + var stringsKeys = Object.keys(strings); + var config = options.config || { + "default": true + }; + var configParsers = options.configParsers || null; + var frontMatter = options.frontMatter === undefined ? helpers.frontMatterRe : options.frontMatter; + var handleRuleFailures = !!options.handleRuleFailures; + var noInlineConfig = !!options.noInlineConfig; + var resultVersion = options.resultVersion === undefined ? 3 : options.resultVersion; + var md = markdownIt({ + "html": true + }); + var markdownItPlugins = options.markdownItPlugins || []; + var _iterator24 = _createForOfIteratorHelper(markdownItPlugins), + _step24; + try { + for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) { + var plugin = _step24.value; + // @ts-ignore + md.use.apply(md, _toConsumableArray(plugin)); } - let files = []; - if (Array.isArray(options.files)) { - files = [...options.files]; - } - else if (options.files) { - files = [String(options.files)]; - } - const strings = options.strings || {}; - const stringsKeys = Object.keys(strings); - const config = options.config || { "default": true }; - const configParsers = options.configParsers || null; - const frontMatter = (options.frontMatter === undefined) ? - helpers.frontMatterRe : options.frontMatter; - const handleRuleFailures = !!options.handleRuleFailures; - const noInlineConfig = !!options.noInlineConfig; - const resultVersion = (options.resultVersion === undefined) ? - 3 : options.resultVersion; - const md = markdownIt({ "html": true }); - const markdownItPlugins = options.markdownItPlugins || []; - for (const plugin of markdownItPlugins) { - // @ts-ignore - md.use(...plugin); - } - const fs = options.fs || __webpack_require__(/*! node:fs */ "?d0ee"); - const results = newResults(ruleList); - let done = false; - let concurrency = 0; + } catch (err) { + _iterator24.e(err); + } finally { + _iterator24.f(); + } + var fs = options.fs || __webpack_require__(/*! node:fs */ "?d0ee"); + var results = newResults(ruleList); + var done = false; + var concurrency = 0; + // eslint-disable-next-line jsdoc/require-jsdoc + function lintWorker() { + var currentItem = null; // eslint-disable-next-line jsdoc/require-jsdoc - function lintWorker() { - let currentItem = null; - // eslint-disable-next-line jsdoc/require-jsdoc - function lintWorkerCallback(err, result) { - concurrency--; - if (err) { - done = true; - return callback(err); - } - results[currentItem] = result; - if (!synchronous) { - lintWorker(); - } - return null; - } - if (done) { - // Abort for error or nothing left to do - } - else if (files.length > 0) { - // Lint next file - concurrency++; - currentItem = files.shift(); - lintFile(ruleList, currentItem, md, config, configParsers, frontMatter, handleRuleFailures, noInlineConfig, resultVersion, fs, synchronous, lintWorkerCallback); - } - else if ((currentItem = stringsKeys.shift())) { - // Lint next string - concurrency++; - lintContent(ruleList, currentItem, strings[currentItem] || "", md, config, configParsers, frontMatter, handleRuleFailures, noInlineConfig, resultVersion, lintWorkerCallback); - } - else if (concurrency === 0) { - // Finish - done = true; - return callback(null, results); - } - return null; + function lintWorkerCallback(err, result) { + concurrency--; + if (err) { + done = true; + return callback(err); + } + results[currentItem] = result; + if (!synchronous) { + lintWorker(); + } + return null; } - if (synchronous) { - while (!done) { - lintWorker(); - } + if (done) { + // Abort for error or nothing left to do + } else if (files.length > 0) { + // Lint next file + concurrency++; + currentItem = files.shift(); + lintFile(ruleList, currentItem, md, config, configParsers, frontMatter, handleRuleFailures, noInlineConfig, resultVersion, fs, synchronous, lintWorkerCallback); + } else if (currentItem = stringsKeys.shift()) { + // Lint next string + concurrency++; + lintContent(ruleList, currentItem, strings[currentItem] || "", md, config, configParsers, frontMatter, handleRuleFailures, noInlineConfig, resultVersion, lintWorkerCallback); + } else if (concurrency === 0) { + // Finish + done = true; + return callback(null, results); } - else { - // Testing on a Raspberry Pi 4 Model B with an artificial 5ms file access - // delay suggests that a concurrency factor of 8 can eliminate the impact - // of that delay (i.e., total time is the same as with no delay). - lintWorker(); - lintWorker(); - lintWorker(); - lintWorker(); - lintWorker(); - lintWorker(); - lintWorker(); - lintWorker(); + return null; + } + if (synchronous) { + while (!done) { + lintWorker(); } + } else { + // Testing on a Raspberry Pi 4 Model B with an artificial 5ms file access + // delay suggests that a concurrency factor of 8 can eliminate the impact + // of that delay (i.e., total time is the same as with no delay). + lintWorker(); + lintWorker(); + lintWorker(); + lintWorker(); + lintWorker(); + lintWorker(); + lintWorker(); + lintWorker(); + } } + /** * Lint specified Markdown files. * @@ -2239,9 +2592,10 @@ function lintInput(options, synchronous, callback) { * @returns {void} */ function markdownlint(options, callback) { - return lintInput(options, false, callback); + return lintInput(options, false, callback); } -const markdownlintPromisify = promisify && promisify(markdownlint); +var markdownlintPromisify = promisify && promisify(markdownlint); + /** * Lint specified Markdown files. * @@ -2249,9 +2603,10 @@ const markdownlintPromisify = promisify && promisify(markdownlint); * @returns {Promise} Results object. */ function markdownlintPromise(options) { - // @ts-ignore - return markdownlintPromisify(options); + // @ts-ignore + return markdownlintPromisify(options); } + /** * Lint specified Markdown files synchronously. * @@ -2259,16 +2614,17 @@ function markdownlintPromise(options) { * @returns {LintResults} Results object. */ function markdownlintSync(options) { - let results = {}; - lintInput(options, true, function callback(error, res) { - if (error) { - throw error; - } - results = res; - }); - // @ts-ignore - return results; + var results = {}; + lintInput(options, true, function callback(error, res) { + if (error) { + throw error; + } + results = res; + }); + // @ts-ignore + return results; } + /** * Resolve referenced "extends" path in a configuration file * using path.resolve() with require.resolve() as a fallback. @@ -2281,21 +2637,23 @@ function markdownlintSync(options) { * @returns {void} */ function resolveConfigExtends(configFile, referenceId, fs, callback) { - const configFileDirname = path.dirname(configFile); - const resolvedExtendsFile = path.resolve(configFileDirname, referenceId); - fs.access(resolvedExtendsFile, (err) => { - if (err) { - // Not a file, try require.resolve - try { - return callback(null, dynamicRequire.resolve(referenceId, { "paths": [configFileDirname] })); - } - catch (_a) { - // Unable to resolve, use resolvedExtendsFile - } - } - return callback(null, resolvedExtendsFile); - }); + var configFileDirname = path.dirname(configFile); + var resolvedExtendsFile = path.resolve(configFileDirname, referenceId); + fs.access(resolvedExtendsFile, function (err) { + if (err) { + // Not a file, try require.resolve + try { + return callback(null, dynamicRequire.resolve(referenceId, { + "paths": [configFileDirname] + })); + } catch (_unused) { + // Unable to resolve, use resolvedExtendsFile + } + } + return callback(null, resolvedExtendsFile); + }); } + /** * Resolve referenced "extends" path in a configuration file * using path.resolve() with require.resolve() as a fallback. @@ -2306,23 +2664,24 @@ function resolveConfigExtends(configFile, referenceId, fs, callback) { * @returns {string} Resolved path to file. */ function resolveConfigExtendsSync(configFile, referenceId, fs) { - const configFileDirname = path.dirname(configFile); - const resolvedExtendsFile = path.resolve(configFileDirname, referenceId); - try { - fs.accessSync(resolvedExtendsFile); - return resolvedExtendsFile; - } - catch (_a) { - // Not a file, try require.resolve - } - try { - return dynamicRequire.resolve(referenceId, { "paths": [configFileDirname] }); - } - catch (_b) { - // Unable to resolve, return resolvedExtendsFile - } + var configFileDirname = path.dirname(configFile); + var resolvedExtendsFile = path.resolve(configFileDirname, referenceId); + try { + fs.accessSync(resolvedExtendsFile); return resolvedExtendsFile; + } catch (_unused2) { + // Not a file, try require.resolve + } + try { + return dynamicRequire.resolve(referenceId, { + "paths": [configFileDirname] + }); + } catch (_unused3) { + // Unable to resolve, return resolvedExtendsFile + } + return resolvedExtendsFile; } + /** * Read specified configuration file. * @@ -2334,56 +2693,60 @@ function resolveConfigExtendsSync(configFile, referenceId, fs) { * @returns {void} */ function readConfig(file, parsers, fs, callback) { - if (!callback) { - if (fs) { - callback = fs; - fs = null; - } - else { - // @ts-ignore - callback = parsers; - // @ts-ignore - parsers = null; - } + if (!callback) { + if (fs) { + callback = fs; + fs = null; + } else { + // @ts-ignore + callback = parsers; + // @ts-ignore + parsers = null; } - if (!fs) { - fs = __webpack_require__(/*! node:fs */ "?d0ee"); + } + if (!fs) { + fs = __webpack_require__(/*! node:fs */ "?d0ee"); + } + // Read file + var os = __webpack_require__(/*! node:os */ "?e6c4"); + file = helpers.expandTildePath(file, os); + fs.readFile(file, "utf8", function (err, content) { + if (err) { + // @ts-ignore + return callback(err); } - // Read file - const os = __webpack_require__(/*! node:os */ "?e6c4"); - file = helpers.expandTildePath(file, os); - fs.readFile(file, "utf8", (err, content) => { - if (err) { - // @ts-ignore - return callback(err); - } - // Try to parse file + // Try to parse file + // @ts-ignore + var _parseConfiguration2 = parseConfiguration(file, content, parsers), + config = _parseConfiguration2.config, + message = _parseConfiguration2.message; + if (!config) { + // @ts-ignore + return callback(new Error(message)); + } + // Extend configuration + var configExtends = config["extends"]; + if (configExtends) { + delete config["extends"]; + return resolveConfigExtends(file, helpers.expandTildePath(configExtends, os), fs, function (_, resolvedExtends) { + return readConfig( // @ts-ignore - const { config, message } = parseConfiguration(file, content, parsers); - if (!config) { - // @ts-ignore - return callback(new Error(message)); - } - // Extend configuration - const configExtends = config.extends; - if (configExtends) { - delete config.extends; - return resolveConfigExtends(file, helpers.expandTildePath(configExtends, os), fs, (_, resolvedExtends) => readConfig( + resolvedExtends, parsers, fs, function (errr, extendsConfig) { + if (errr) { // @ts-ignore - resolvedExtends, parsers, fs, (errr, extendsConfig) => { - if (errr) { - // @ts-ignore - return callback(errr); - } - // @ts-ignore - return callback(null, Object.assign(Object.assign({}, extendsConfig), config)); - })); - } - // @ts-ignore - return callback(null, config); - }); + return callback(errr); + } + // @ts-ignore + return callback(null, _objectSpread(_objectSpread({}, extendsConfig), config)); + }); + }); + } + // @ts-ignore + return callback(null, config); + }); } -const readConfigPromisify = promisify && promisify(readConfig); +var readConfigPromisify = promisify && promisify(readConfig); + /** * Read specified configuration file. * @@ -2393,9 +2756,10 @@ const readConfigPromisify = promisify && promisify(readConfig); * @returns {Promise} Configuration object. */ function readConfigPromise(file, parsers, fs) { - // @ts-ignore - return readConfigPromisify(file, parsers, fs); + // @ts-ignore + return readConfigPromisify(file, parsers, fs); } + /** * Read specified configuration file synchronously. * @@ -2406,46 +2770,243 @@ function readConfigPromise(file, parsers, fs) { * @throws An Error if processing fails. */ function readConfigSync(file, parsers, fs) { - if (!fs) { - fs = __webpack_require__(/*! node:fs */ "?d0ee"); - } - // Read file - const os = __webpack_require__(/*! node:os */ "?e6c4"); - file = helpers.expandTildePath(file, os); - const content = fs.readFileSync(file, "utf8"); - // Try to parse file - const { config, message } = parseConfiguration(file, content, parsers); - if (!config) { - throw new Error(message); - } - // Extend configuration - const configExtends = config.extends; - if (configExtends) { - delete config.extends; - const resolvedExtends = resolveConfigExtendsSync(file, helpers.expandTildePath(configExtends, os), fs); - return Object.assign(Object.assign({}, readConfigSync(resolvedExtends, parsers, fs)), config); - } - return config; + if (!fs) { + fs = __webpack_require__(/*! node:fs */ "?d0ee"); + } + // Read file + var os = __webpack_require__(/*! node:os */ "?e6c4"); + file = helpers.expandTildePath(file, os); + var content = fs.readFileSync(file, "utf8"); + // Try to parse file + var _parseConfiguration3 = parseConfiguration(file, content, parsers), + config = _parseConfiguration3.config, + message = _parseConfiguration3.message; + if (!config) { + throw new Error(message); + } + // Extend configuration + var configExtends = config["extends"]; + if (configExtends) { + delete config["extends"]; + var resolvedExtends = resolveConfigExtendsSync(file, helpers.expandTildePath(configExtends, os), fs); + return _objectSpread(_objectSpread({}, readConfigSync(resolvedExtends, parsers, fs)), config); + } + return config; } + /** * Gets the (semantic) version of the library. * * @returns {string} SemVer string. */ function getVersion() { - return (__webpack_require__(/*! ./constants */ "../lib/constants.js").version); + return (__webpack_require__(/*! ./constants */ "../lib/constants.js").version); } + // Export a/synchronous/Promise APIs markdownlint.sync = markdownlintSync; markdownlint.readConfig = readConfig; markdownlint.readConfigSync = readConfigSync; markdownlint.getVersion = getVersion; markdownlint.promises = { - "markdownlint": markdownlintPromise, - "readConfig": readConfigPromise + "markdownlint": markdownlintPromise, + "readConfig": readConfigPromise }; module.exports = markdownlint; +// Type declarations + +/** + * Function to implement rule logic. + * + * @callback RuleFunction + * @param {RuleParams} params Rule parameters. + * @param {RuleOnError} onError Error-reporting callback. + * @returns {void} + */ + +/** + * Rule parameters. + * + * @typedef {Object} RuleParams + * @property {string} name File/string name. + * @property {MarkdownItToken[]} tokens Token objects from markdown-it. + * @property {string[]} lines File/string lines. + * @property {string[]} frontMatterLines Front matter lines. + * @property {RuleConfiguration} config Rule configuration. + */ + +/** + * Markdown-It token. + * + * @typedef {Object} MarkdownItToken + * @property {string[][]} attrs HTML attributes. + * @property {boolean} block Block-level token. + * @property {MarkdownItToken[]} children Child nodes. + * @property {string} content Tag contents. + * @property {boolean} hidden Ignore element. + * @property {string} info Fence info. + * @property {number} level Nesting level. + * @property {number[]} map Beginning/ending line numbers. + * @property {string} markup Markup text. + * @property {Object} meta Arbitrary data. + * @property {number} nesting Level change. + * @property {string} tag HTML tag name. + * @property {string} type Token type. + * @property {number} lineNumber Line number (1-based). + * @property {string} line Line content. + */ + +/** + * Error-reporting callback. + * + * @callback RuleOnError + * @param {RuleOnErrorInfo} onErrorInfo Error information. + * @returns {void} + */ + +/** + * Fix information for RuleOnError callback. + * + * @typedef {Object} RuleOnErrorInfo + * @property {number} lineNumber Line number (1-based). + * @property {string} [detail] Detail about the error. + * @property {string} [context] Context for the error. + * @property {number[]} [range] Column number (1-based) and length. + * @property {RuleOnErrorFixInfo} [fixInfo] Fix information. + */ + +/** + * Fix information for RuleOnErrorInfo. + * + * @typedef {Object} RuleOnErrorFixInfo + * @property {number} [lineNumber] Line number (1-based). + * @property {number} [editColumn] Column of the fix (1-based). + * @property {number} [deleteCount] Count of characters to delete. + * @property {string} [insertText] Text to insert (after deleting). + */ + +/** + * Rule definition. + * + * @typedef {Object} Rule + * @property {string[]} names Rule name(s). + * @property {string} description Rule description. + * @property {URL} [information] Link to more information. + * @property {string[]} tags Rule tag(s). + * @property {boolean} [asynchronous] True if asynchronous. + * @property {RuleFunction} function Rule implementation. + */ + +/** + * Configuration options. + * + * @typedef {Object} Options + * @property {Configuration} [config] Configuration object. + * @property {ConfigurationParser[]} [configParsers] Configuration parsers. + * @property {Rule[] | Rule} [customRules] Custom rules. + * @property {string[] | string} [files] Files to lint. + * @property {RegExp} [frontMatter] Front matter pattern. + * @property {Object} [fs] File system implementation. + * @property {boolean} [handleRuleFailures] True to catch exceptions. + * @property {Plugin[]} [markdownItPlugins] Additional plugins. + * @property {boolean} [noInlineConfig] True to ignore HTML directives. + * @property {number} [resultVersion] Results object version. + * @property {Object.} [strings] Strings to lint. + */ + +/** + * A markdown-it plugin. + * + * @typedef {Array} Plugin + */ + +/** + * Function to pretty-print lint results. + * + * @callback ToStringCallback + * @param {boolean} [ruleAliases] True to use rule aliases. + * @returns {string} + */ + +/** + * Lint results (for resultVersion 3). + * + * @typedef {Object.} LintResults + * @property {ToStringCallback} toString String representation. + */ + +/** + * Lint error. + * + * @typedef {Object} LintError + * @property {number} lineNumber Line number (1-based). + * @property {string[]} ruleNames Rule name(s). + * @property {string} ruleDescription Rule description. + * @property {string} ruleInformation Link to more information. + * @property {string} errorDetail Detail about the error. + * @property {string} errorContext Context for the error. + * @property {number[]} errorRange Column number (1-based) and length. + * @property {FixInfo} [fixInfo] Fix information. + */ + +/** + * Fix information. + * + * @typedef {Object} FixInfo + * @property {number} [lineNumber] Line number (1-based). + * @property {number} [editColumn] Column of the fix (1-based). + * @property {number} [deleteCount] Count of characters to delete. + * @property {string} [insertText] Text to insert (after deleting). + */ + +/** + * Called with the result of the lint function. + * + * @callback LintCallback + * @param {Error | null} err Error object or null. + * @param {LintResults} [results] Lint results. + * @returns {void} + */ + +/** + * Configuration object for linting rules. For a detailed schema, see + * {@link ../schema/markdownlint-config-schema.json}. + * + * @typedef {Object.} Configuration + */ + +/** + * Rule configuration object. + * + * @typedef {boolean | Object} RuleConfiguration Rule configuration. + */ + +/** + * Parses a configuration string and returns a configuration object. + * + * @callback ConfigurationParser + * @param {string} text Configuration string. + * @returns {Configuration} + */ + +/** + * Called with the result of the readConfig function. + * + * @callback ReadConfigCallback + * @param {Error | null} err Error object or null. + * @param {Configuration} [config] Configuration object. + * @returns {void} + */ + +/** + * Called with the result of the resolveConfigExtends function. + * + * @callback ResolveConfigExtendsCallback + * @param {Error | null} err Error object or null. + * @param {string} [path] Resolved path to file. + * @returns {void} + */ /***/ }), @@ -2458,24 +3019,27 @@ module.exports = markdownlint; "use strict"; // @ts-check -const { addErrorDetailIf, filterTokens } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); + + +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorDetailIf = _require.addErrorDetailIf, + filterTokens = _require.filterTokens; module.exports = { - "names": ["MD001", "heading-increment", "header-increment"], - "description": "Heading levels should only increment by one level at a time", - "tags": ["headings", "headers"], - "function": function MD001(params, onError) { - let prevLevel = 0; - filterTokens(params, "heading_open", function forToken(token) { - const level = Number.parseInt(token.tag.slice(1), 10); - if (prevLevel && (level > prevLevel)) { - addErrorDetailIf(onError, token.lineNumber, "h" + (prevLevel + 1), "h" + level); - } - prevLevel = level; - }); - } + "names": ["MD001", "heading-increment", "header-increment"], + "description": "Heading levels should only increment by one level at a time", + "tags": ["headings", "headers"], + "function": function MD001(params, onError) { + var prevLevel = 0; + filterTokens(params, "heading_open", function forToken(token) { + var level = Number.parseInt(token.tag.slice(1), 10); + if (prevLevel && level > prevLevel) { + addErrorDetailIf(onError, token.lineNumber, "h" + (prevLevel + 1), "h" + level); + } + prevLevel = level; + }); + } }; - /***/ }), /***/ "../lib/md002.js": @@ -2487,25 +3051,27 @@ module.exports = { "use strict"; // @ts-check -const { addErrorDetailIf } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); + + +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorDetailIf = _require.addErrorDetailIf; module.exports = { - "names": ["MD002", "first-heading-h1", "first-header-h1"], - "description": "First heading should be a top-level heading", - "tags": ["headings", "headers"], - "function": function MD002(params, onError) { - const level = Number(params.config.level || 1); - const tag = "h" + level; - params.tokens.every(function forToken(token) { - if (token.type === "heading_open") { - addErrorDetailIf(onError, token.lineNumber, tag, token.tag); - return false; - } - return true; - }); - } + "names": ["MD002", "first-heading-h1", "first-header-h1"], + "description": "First heading should be a top-level heading", + "tags": ["headings", "headers"], + "function": function MD002(params, onError) { + var level = Number(params.config.level || 1); + var tag = "h" + level; + params.tokens.every(function forToken(token) { + if (token.type === "heading_open") { + addErrorDetailIf(onError, token.lineNumber, tag, token.tag); + return false; + } + return true; + }); + } }; - /***/ }), /***/ "../lib/md003.js": @@ -2517,42 +3083,41 @@ module.exports = { "use strict"; // @ts-check -const { addErrorDetailIf, filterTokens, headingStyleFor } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); + + +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorDetailIf = _require.addErrorDetailIf, + filterTokens = _require.filterTokens, + headingStyleFor = _require.headingStyleFor; module.exports = { - "names": ["MD003", "heading-style", "header-style"], - "description": "Heading style", - "tags": ["headings", "headers"], - "function": function MD003(params, onError) { - let style = String(params.config.style || "consistent"); - filterTokens(params, "heading_open", function forToken(token) { - const styleForToken = headingStyleFor(token); - if (style === "consistent") { - style = styleForToken; - } - if (styleForToken !== style) { - const h12 = /h[12]/.test(token.tag); - const setextWithAtx = (style === "setext_with_atx") && - ((h12 && (styleForToken === "setext")) || - (!h12 && (styleForToken === "atx"))); - const setextWithAtxClosed = (style === "setext_with_atx_closed") && - ((h12 && (styleForToken === "setext")) || - (!h12 && (styleForToken === "atx_closed"))); - if (!setextWithAtx && !setextWithAtxClosed) { - let expected = style; - if (style === "setext_with_atx") { - expected = h12 ? "setext" : "atx"; - } - else if (style === "setext_with_atx_closed") { - expected = h12 ? "setext" : "atx_closed"; - } - addErrorDetailIf(onError, token.lineNumber, expected, styleForToken); - } - } - }); - } + "names": ["MD003", "heading-style", "header-style"], + "description": "Heading style", + "tags": ["headings", "headers"], + "function": function MD003(params, onError) { + var style = String(params.config.style || "consistent"); + filterTokens(params, "heading_open", function forToken(token) { + var styleForToken = headingStyleFor(token); + if (style === "consistent") { + style = styleForToken; + } + if (styleForToken !== style) { + var h12 = /h[12]/.test(token.tag); + var setextWithAtx = style === "setext_with_atx" && (h12 && styleForToken === "setext" || !h12 && styleForToken === "atx"); + var setextWithAtxClosed = style === "setext_with_atx_closed" && (h12 && styleForToken === "setext" || !h12 && styleForToken === "atx_closed"); + if (!setextWithAtx && !setextWithAtxClosed) { + var expected = style; + if (style === "setext_with_atx") { + expected = h12 ? "setext" : "atx"; + } else if (style === "setext_with_atx_closed") { + expected = h12 ? "setext" : "atx_closed"; + } + addErrorDetailIf(onError, token.lineNumber, expected, styleForToken); + } + } + }); + } }; - /***/ }), /***/ "../lib/md004.js": @@ -2564,68 +3129,91 @@ module.exports = { "use strict"; // @ts-check -const { addErrorDetailIf, listItemMarkerRe, unorderedListStyleFor } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const { flattenedLists } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); -const expectedStyleToMarker = { - "dash": "-", - "plus": "+", - "asterisk": "*" + + +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; } } }; } +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); } +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; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorDetailIf = _require.addErrorDetailIf, + listItemMarkerRe = _require.listItemMarkerRe, + unorderedListStyleFor = _require.unorderedListStyleFor; +var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"), + flattenedLists = _require2.flattenedLists; +var expectedStyleToMarker = { + "dash": "-", + "plus": "+", + "asterisk": "*" }; -const differentItemStyle = { - "dash": "plus", - "plus": "asterisk", - "asterisk": "dash" +var differentItemStyle = { + "dash": "plus", + "plus": "asterisk", + "asterisk": "dash" }; -const validStyles = Object.keys(expectedStyleToMarker); +var validStyles = Object.keys(expectedStyleToMarker); module.exports = { - "names": ["MD004", "ul-style"], - "description": "Unordered list style", - "tags": ["bullet", "ul"], - "function": function MD004(params, onError) { - const style = String(params.config.style || "consistent"); - let expectedStyle = style; - const nestingStyles = []; - for (const list of flattenedLists()) { - if (list.unordered) { - if (expectedStyle === "consistent") { - expectedStyle = unorderedListStyleFor(list.items[0]); - } - for (const item of list.items) { - const itemStyle = unorderedListStyleFor(item); - if (style === "sublist") { - const nesting = list.nesting; - if (!nestingStyles[nesting]) { - nestingStyles[nesting] = - (itemStyle === nestingStyles[nesting - 1]) ? - differentItemStyle[itemStyle] : - itemStyle; - } - expectedStyle = nestingStyles[nesting]; - } - if (!validStyles.includes(expectedStyle)) { - expectedStyle = validStyles[0]; - } - let range = null; - let fixInfo = null; - const match = item.line.match(listItemMarkerRe); - if (match) { - const column = match.index + 1; - const length = match[0].length; - range = [column, length]; - fixInfo = { - "editColumn": match[1].length + 1, - "deleteCount": 1, - "insertText": expectedStyleToMarker[expectedStyle] - }; - } - addErrorDetailIf(onError, item.lineNumber, expectedStyle, itemStyle, null, null, range, fixInfo); + "names": ["MD004", "ul-style"], + "description": "Unordered list style", + "tags": ["bullet", "ul"], + "function": function MD004(params, onError) { + var style = String(params.config.style || "consistent"); + var expectedStyle = style; + var nestingStyles = []; + var _iterator = _createForOfIteratorHelper(flattenedLists()), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var list = _step.value; + if (list.unordered) { + if (expectedStyle === "consistent") { + expectedStyle = unorderedListStyleFor(list.items[0]); + } + var _iterator2 = _createForOfIteratorHelper(list.items), + _step2; + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var item = _step2.value; + var itemStyle = unorderedListStyleFor(item); + if (style === "sublist") { + var nesting = list.nesting; + if (!nestingStyles[nesting]) { + nestingStyles[nesting] = itemStyle === nestingStyles[nesting - 1] ? differentItemStyle[itemStyle] : itemStyle; } - } - } + expectedStyle = nestingStyles[nesting]; + } + if (!validStyles.includes(expectedStyle)) { + expectedStyle = validStyles[0]; + } + var range = null; + var fixInfo = null; + var match = item.line.match(listItemMarkerRe); + if (match) { + var column = match.index + 1; + var length = match[0].length; + range = [column, length]; + fixInfo = { + "editColumn": match[1].length + 1, + "deleteCount": 1, + "insertText": expectedStyleToMarker[expectedStyle] + }; + } + addErrorDetailIf(onError, item.lineNumber, expectedStyle, itemStyle, null, null, range, fixInfo); + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); } + } }; - /***/ }), /***/ "../lib/md005.js": @@ -2637,59 +3225,81 @@ module.exports = { "use strict"; // @ts-check -const { addError, addErrorDetailIf, indentFor, listItemMarkerRe, orderedListItemMarkerRe, rangeFromRegExp } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const { flattenedLists } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); + + +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; } } }; } +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); } +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; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addError = _require.addError, + addErrorDetailIf = _require.addErrorDetailIf, + indentFor = _require.indentFor, + listItemMarkerRe = _require.listItemMarkerRe, + orderedListItemMarkerRe = _require.orderedListItemMarkerRe, + rangeFromRegExp = _require.rangeFromRegExp; +var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"), + flattenedLists = _require2.flattenedLists; module.exports = { - "names": ["MD005", "list-indent"], - "description": "Inconsistent indentation for list items at the same level", - "tags": ["bullet", "ul", "indentation"], - "function": function MD005(params, onError) { - for (const list of flattenedLists()) { - const expectedIndent = list.indent; - let expectedEnd = 0; - let actualEnd = -1; - let endMatching = false; - for (const item of list.items) { - const { line, lineNumber } = item; - const actualIndent = indentFor(item); - let match = null; - if (list.unordered) { - addErrorDetailIf(onError, lineNumber, expectedIndent, actualIndent, null, null, rangeFromRegExp(line, listItemMarkerRe) - // No fixInfo; MD007 handles this scenario better - ); - } - else if ((match = orderedListItemMarkerRe.exec(line))) { - actualEnd = match[0].length; - expectedEnd = expectedEnd || actualEnd; - const markerLength = match[1].length + 1; - if ((expectedIndent !== actualIndent) || endMatching) { - if (expectedEnd === actualEnd) { - endMatching = true; - } - else { - const detail = endMatching ? - `Expected: (${expectedEnd}); Actual: (${actualEnd})` : - `Expected: ${expectedIndent}; Actual: ${actualIndent}`; - const expected = endMatching ? - expectedEnd - markerLength : - expectedIndent; - const actual = endMatching ? - actualEnd - markerLength : - actualIndent; - addError(onError, lineNumber, detail, null, rangeFromRegExp(line, listItemMarkerRe), { - "editColumn": Math.min(actual, expected) + 1, - "deleteCount": Math.max(actual - expected, 0), - "insertText": "".padEnd(Math.max(expected - actual, 0)) - }); - } - } + "names": ["MD005", "list-indent"], + "description": "Inconsistent indentation for list items at the same level", + "tags": ["bullet", "ul", "indentation"], + "function": function MD005(params, onError) { + var _iterator = _createForOfIteratorHelper(flattenedLists()), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var list = _step.value; + var expectedIndent = list.indent; + var expectedEnd = 0; + var actualEnd = -1; + var endMatching = false; + var _iterator2 = _createForOfIteratorHelper(list.items), + _step2; + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var item = _step2.value; + var line = item.line, + lineNumber = item.lineNumber; + var actualIndent = indentFor(item); + var match = null; + if (list.unordered) { + addErrorDetailIf(onError, lineNumber, expectedIndent, actualIndent, null, null, rangeFromRegExp(line, listItemMarkerRe) + // No fixInfo; MD007 handles this scenario better + ); + } else if (match = orderedListItemMarkerRe.exec(line)) { + actualEnd = match[0].length; + expectedEnd = expectedEnd || actualEnd; + var markerLength = match[1].length + 1; + if (expectedIndent !== actualIndent || endMatching) { + if (expectedEnd === actualEnd) { + endMatching = true; + } else { + var detail = endMatching ? "Expected: (".concat(expectedEnd, "); Actual: (").concat(actualEnd, ")") : "Expected: ".concat(expectedIndent, "; Actual: ").concat(actualIndent); + var expected = endMatching ? expectedEnd - markerLength : expectedIndent; + var actual = endMatching ? actualEnd - markerLength : actualIndent; + addError(onError, lineNumber, detail, null, rangeFromRegExp(line, listItemMarkerRe), { + "editColumn": Math.min(actual, expected) + 1, + "deleteCount": Math.max(actual - expected, 0), + "insertText": "".padEnd(Math.max(expected - actual, 0)) + }); } - } - } + } + } + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); } + } }; - /***/ }), /***/ "../lib/md006.js": @@ -2701,27 +3311,54 @@ module.exports = { "use strict"; // @ts-check -const { addErrorDetailIf, listItemMarkerRe, rangeFromRegExp } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const { flattenedLists } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); + + +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; } } }; } +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); } +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; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorDetailIf = _require.addErrorDetailIf, + listItemMarkerRe = _require.listItemMarkerRe, + rangeFromRegExp = _require.rangeFromRegExp; +var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"), + flattenedLists = _require2.flattenedLists; module.exports = { - "names": ["MD006", "ul-start-left"], - "description": "Consider starting bulleted lists at the beginning of the line", - "tags": ["bullet", "ul", "indentation"], - "function": function MD006(params, onError) { - for (const list of flattenedLists()) { - if (list.unordered && !list.nesting && (list.indent !== 0)) { - for (const item of list.items) { - const { lineNumber, line } = item; - addErrorDetailIf(onError, lineNumber, 0, list.indent, null, null, rangeFromRegExp(line, listItemMarkerRe), { - "deleteCount": line.length - line.trimStart().length - }); - } - } - } + "names": ["MD006", "ul-start-left"], + "description": "Consider starting bulleted lists at the beginning of the line", + "tags": ["bullet", "ul", "indentation"], + "function": function MD006(params, onError) { + var _iterator = _createForOfIteratorHelper(flattenedLists()), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var list = _step.value; + if (list.unordered && !list.nesting && list.indent !== 0) { + var _iterator2 = _createForOfIteratorHelper(list.items), + _step2; + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var item = _step2.value; + var lineNumber = item.lineNumber, + line = item.line; + addErrorDetailIf(onError, lineNumber, 0, list.indent, null, null, rangeFromRegExp(line, listItemMarkerRe), { + "deleteCount": line.length - line.trimStart().length + }); + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); } + } }; - /***/ }), /***/ "../lib/md007.js": @@ -2733,42 +3370,68 @@ module.exports = { "use strict"; // @ts-check -const { addErrorDetailIf, indentFor, listItemMarkerRe } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const { flattenedLists } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); + + +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; } } }; } +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); } +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; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorDetailIf = _require.addErrorDetailIf, + indentFor = _require.indentFor, + listItemMarkerRe = _require.listItemMarkerRe; +var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"), + flattenedLists = _require2.flattenedLists; module.exports = { - "names": ["MD007", "ul-indent"], - "description": "Unordered list indentation", - "tags": ["bullet", "ul", "indentation"], - "function": function MD007(params, onError) { - const indent = Number(params.config.indent || 2); - const startIndented = !!params.config.start_indented; - const startIndent = Number(params.config.start_indent || indent); - for (const list of flattenedLists()) { - if (list.unordered && list.parentsUnordered) { - for (const item of list.items) { - const { lineNumber, line } = item; - const expectedIndent = (startIndented ? startIndent : 0) + - (list.nesting * indent); - const actualIndent = indentFor(item); - let range = null; - let editColumn = 1; - const match = line.match(listItemMarkerRe); - if (match) { - range = [1, match[0].length]; - editColumn += match[1].length - actualIndent; - } - addErrorDetailIf(onError, lineNumber, expectedIndent, actualIndent, null, null, range, { - editColumn, - "deleteCount": actualIndent, - "insertText": "".padEnd(expectedIndent) - }); - } - } - } + "names": ["MD007", "ul-indent"], + "description": "Unordered list indentation", + "tags": ["bullet", "ul", "indentation"], + "function": function MD007(params, onError) { + var indent = Number(params.config.indent || 2); + var startIndented = !!params.config.start_indented; + var startIndent = Number(params.config.start_indent || indent); + var _iterator = _createForOfIteratorHelper(flattenedLists()), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var list = _step.value; + if (list.unordered && list.parentsUnordered) { + var _iterator2 = _createForOfIteratorHelper(list.items), + _step2; + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var item = _step2.value; + var lineNumber = item.lineNumber, + line = item.line; + var expectedIndent = (startIndented ? startIndent : 0) + list.nesting * indent; + var actualIndent = indentFor(item); + var range = null; + var editColumn = 1; + var match = line.match(listItemMarkerRe); + if (match) { + range = [1, match[0].length]; + editColumn += match[1].length - actualIndent; + } + addErrorDetailIf(onError, lineNumber, expectedIndent, actualIndent, null, null, range, { + editColumn: editColumn, + "deleteCount": actualIndent, + "insertText": "".padEnd(expectedIndent) + }); + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); } + } }; - /***/ }), /***/ "../lib/md009.js": @@ -2780,78 +3443,90 @@ module.exports = { "use strict"; // @ts-check -const { addError, filterTokens, forEachLine, includesSorted, numericSortAscending } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const { lineMetadata } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); + + +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; } } }; } +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); } +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; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addError = _require.addError, + filterTokens = _require.filterTokens, + forEachLine = _require.forEachLine, + includesSorted = _require.includesSorted, + numericSortAscending = _require.numericSortAscending; +var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"), + lineMetadata = _require2.lineMetadata; module.exports = { - "names": ["MD009", "no-trailing-spaces"], - "description": "Trailing spaces", - "tags": ["whitespace"], - "function": function MD009(params, onError) { - let brSpaces = params.config.br_spaces; - brSpaces = Number((brSpaces === undefined) ? 2 : brSpaces); - const listItemEmptyLines = !!params.config.list_item_empty_lines; - const strict = !!params.config.strict; - const listItemLineNumbers = []; - if (listItemEmptyLines) { - filterTokens(params, "list_item_open", (token) => { - for (let i = token.map[0]; i < token.map[1]; i++) { - listItemLineNumbers.push(i + 1); - } - }); - listItemLineNumbers.sort(numericSortAscending); + "names": ["MD009", "no-trailing-spaces"], + "description": "Trailing spaces", + "tags": ["whitespace"], + "function": function MD009(params, onError) { + var brSpaces = params.config.br_spaces; + brSpaces = Number(brSpaces === undefined ? 2 : brSpaces); + var listItemEmptyLines = !!params.config.list_item_empty_lines; + var strict = !!params.config.strict; + var listItemLineNumbers = []; + if (listItemEmptyLines) { + filterTokens(params, "list_item_open", function (token) { + for (var i = token.map[0]; i < token.map[1]; i++) { + listItemLineNumbers.push(i + 1); + } + }); + listItemLineNumbers.sort(numericSortAscending); + } + var paragraphLineNumbers = []; + var codeInlineLineNumbers = []; + if (strict) { + filterTokens(params, "paragraph_open", function (token) { + for (var i = token.map[0]; i < token.map[1] - 1; i++) { + paragraphLineNumbers.push(i + 1); + } + }); + var addLineNumberRange = function addLineNumberRange(start, end) { + for (var i = start; i < end; i++) { + codeInlineLineNumbers.push(i); + } + }; + filterTokens(params, "inline", function (token) { + var start = 0; + var _iterator = _createForOfIteratorHelper(token.children), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var child = _step.value; + if (start > 0) { + addLineNumberRange(start, child.lineNumber); + start = 0; + } + if (child.type === "code_inline") { + start = child.lineNumber; + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); } - const paragraphLineNumbers = []; - const codeInlineLineNumbers = []; - if (strict) { - filterTokens(params, "paragraph_open", (token) => { - for (let i = token.map[0]; i < token.map[1] - 1; i++) { - paragraphLineNumbers.push(i + 1); - } - }); - const addLineNumberRange = (start, end) => { - for (let i = start; i < end; i++) { - codeInlineLineNumbers.push(i); - } - }; - filterTokens(params, "inline", (token) => { - let start = 0; - for (const child of token.children) { - if (start > 0) { - addLineNumberRange(start, child.lineNumber); - start = 0; - } - if (child.type === "code_inline") { - start = child.lineNumber; - } - } - if (start > 0) { - addLineNumberRange(start, token.map[1]); - } - }); + if (start > 0) { + addLineNumberRange(start, token.map[1]); } - const expected = (brSpaces < 2) ? 0 : brSpaces; - forEachLine(lineMetadata(), (line, lineIndex, inCode) => { - const lineNumber = lineIndex + 1; - const trailingSpaces = line.length - line.trimEnd().length; - if (trailingSpaces && - !inCode && - !includesSorted(listItemLineNumbers, lineNumber) && - ((expected !== trailingSpaces) || - (strict && - (!includesSorted(paragraphLineNumbers, lineNumber) || - includesSorted(codeInlineLineNumbers, lineNumber))))) { - const column = line.length - trailingSpaces + 1; - addError(onError, lineNumber, "Expected: " + (expected === 0 ? "" : "0 or ") + - expected + "; Actual: " + trailingSpaces, undefined, [column, trailingSpaces], { - "editColumn": column, - "deleteCount": trailingSpaces - }); - } - }); + }); } + var expected = brSpaces < 2 ? 0 : brSpaces; + forEachLine(lineMetadata(), function (line, lineIndex, inCode) { + var lineNumber = lineIndex + 1; + var trailingSpaces = line.length - line.trimEnd().length; + if (trailingSpaces && !inCode && !includesSorted(listItemLineNumbers, lineNumber) && (expected !== trailingSpaces || strict && (!includesSorted(paragraphLineNumbers, lineNumber) || includesSorted(codeInlineLineNumbers, lineNumber)))) { + var column = line.length - trailingSpaces + 1; + addError(onError, lineNumber, "Expected: " + (expected === 0 ? "" : "0 or ") + expected + "; Actual: " + trailingSpaces, undefined, [column, trailingSpaces], { + "editColumn": column, + "deleteCount": trailingSpaces + }); + } + }); + } }; - /***/ }), /***/ "../lib/md010.js": @@ -2863,52 +3538,59 @@ module.exports = { "use strict"; // @ts-check -const { addError, filterTokens, forEachLine, withinAnyRange } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const { codeBlockAndSpanRanges, lineMetadata } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); -const tabRe = /\t+/g; + + +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addError = _require.addError, + filterTokens = _require.filterTokens, + forEachLine = _require.forEachLine, + withinAnyRange = _require.withinAnyRange; +var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"), + codeBlockAndSpanRanges = _require2.codeBlockAndSpanRanges, + lineMetadata = _require2.lineMetadata; +var tabRe = /\t+/g; module.exports = { - "names": ["MD010", "no-hard-tabs"], - "description": "Hard tabs", - "tags": ["whitespace", "hard_tab"], - "function": function MD010(params, onError) { - const codeBlocks = params.config.code_blocks; - const includeCode = (codeBlocks === undefined) ? true : !!codeBlocks; - const ignoreCodeLanguages = new Set((params.config.ignore_code_languages || []) - .map((language) => language.toLowerCase())); - const spacesPerTab = params.config.spaces_per_tab; - const spaceMultiplier = (spacesPerTab === undefined) ? - 1 : - Math.max(0, Number(spacesPerTab)); - const exclusions = includeCode ? [] : codeBlockAndSpanRanges(); - filterTokens(params, "fence", (token) => { - const language = token.info.trim().toLowerCase(); - if (ignoreCodeLanguages.has(language)) { - for (let i = token.map[0] + 1; i < token.map[1] - 1; i++) { - exclusions.push([i, 0, params.lines[i].length]); - } - } - }); - forEachLine(lineMetadata(), (line, lineIndex, inCode) => { - if (includeCode || !inCode) { - let match = null; - while ((match = tabRe.exec(line)) !== null) { - const { index } = match; - const column = index + 1; - const length = match[0].length; - if (!withinAnyRange(exclusions, lineIndex, index, length)) { - addError(onError, lineIndex + 1, "Column: " + column, null, [column, length], { - "editColumn": column, - "deleteCount": length, - "insertText": "".padEnd(length * spaceMultiplier) - }); - } - } - } - }); - } + "names": ["MD010", "no-hard-tabs"], + "description": "Hard tabs", + "tags": ["whitespace", "hard_tab"], + "function": function MD010(params, onError) { + var codeBlocks = params.config.code_blocks; + var includeCode = codeBlocks === undefined ? true : !!codeBlocks; + var ignoreCodeLanguages = new Set((params.config.ignore_code_languages || []).map(function (language) { + return language.toLowerCase(); + })); + var spacesPerTab = params.config.spaces_per_tab; + var spaceMultiplier = spacesPerTab === undefined ? 1 : Math.max(0, Number(spacesPerTab)); + var exclusions = includeCode ? [] : codeBlockAndSpanRanges(); + filterTokens(params, "fence", function (token) { + var language = token.info.trim().toLowerCase(); + if (ignoreCodeLanguages.has(language)) { + for (var i = token.map[0] + 1; i < token.map[1] - 1; i++) { + exclusions.push([i, 0, params.lines[i].length]); + } + } + }); + forEachLine(lineMetadata(), function (line, lineIndex, inCode) { + if (includeCode || !inCode) { + var match = null; + while ((match = tabRe.exec(line)) !== null) { + var _match = match, + index = _match.index; + var column = index + 1; + var length = match[0].length; + if (!withinAnyRange(exclusions, lineIndex, index, length)) { + addError(onError, lineIndex + 1, "Column: " + column, null, [column, length], { + "editColumn": column, + "deleteCount": length, + "insertText": "".padEnd(length * spaceMultiplier) + }); + } + } + } + }); + } }; - /***/ }), /***/ "../lib/md011.js": @@ -2920,38 +3602,53 @@ module.exports = { "use strict"; // @ts-check -const { addError, forEachLine, withinAnyRange } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const { codeBlockAndSpanRanges, lineMetadata } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); -const reversedLinkRe = /(^|[^\\])\(([^()]+)\)\[([^\]^][^\]]*)\](?!\()/g; + + +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } +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."); } +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); } +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; } +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; } } +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addError = _require.addError, + forEachLine = _require.forEachLine, + withinAnyRange = _require.withinAnyRange; +var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"), + codeBlockAndSpanRanges = _require2.codeBlockAndSpanRanges, + lineMetadata = _require2.lineMetadata; +var reversedLinkRe = /(^|[^\\])\(([^()]+)\)\[([^\]^][^\]]*)\](?!\()/g; module.exports = { - "names": ["MD011", "no-reversed-links"], - "description": "Reversed link syntax", - "tags": ["links"], - "function": function MD011(params, onError) { - const exclusions = codeBlockAndSpanRanges(); - forEachLine(lineMetadata(), (line, lineIndex, inCode, onFence) => { - if (!inCode && !onFence) { - let match = null; - while ((match = reversedLinkRe.exec(line)) !== null) { - const [reversedLink, preChar, linkText, linkDestination] = match; - const index = match.index + preChar.length; - const length = match[0].length - preChar.length; - if (!linkText.endsWith("\\") && - !linkDestination.endsWith("\\") && - !withinAnyRange(exclusions, lineIndex, index, length)) { - addError(onError, lineIndex + 1, reversedLink.slice(preChar.length), undefined, [index + 1, length], { - "editColumn": index + 1, - "deleteCount": length, - "insertText": `[${linkText}](${linkDestination})` - }); - } - } - } - }); - } + "names": ["MD011", "no-reversed-links"], + "description": "Reversed link syntax", + "tags": ["links"], + "function": function MD011(params, onError) { + var exclusions = codeBlockAndSpanRanges(); + forEachLine(lineMetadata(), function (line, lineIndex, inCode, onFence) { + if (!inCode && !onFence) { + var match = null; + while ((match = reversedLinkRe.exec(line)) !== null) { + var _match = match, + _match2 = _slicedToArray(_match, 4), + reversedLink = _match2[0], + preChar = _match2[1], + linkText = _match2[2], + linkDestination = _match2[3]; + var index = match.index + preChar.length; + var length = match[0].length - preChar.length; + if (!linkText.endsWith("\\") && !linkDestination.endsWith("\\") && !withinAnyRange(exclusions, lineIndex, index, length)) { + addError(onError, lineIndex + 1, reversedLink.slice(preChar.length), undefined, [index + 1, length], { + "editColumn": index + 1, + "deleteCount": length, + "insertText": "[".concat(linkText, "](").concat(linkDestination, ")") + }); + } + } + } + }); + } }; - /***/ }), /***/ "../lib/md012.js": @@ -2963,27 +3660,31 @@ module.exports = { "use strict"; // @ts-check -const { addErrorDetailIf, forEachLine } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const { lineMetadata } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); + + +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorDetailIf = _require.addErrorDetailIf, + forEachLine = _require.forEachLine; +var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"), + lineMetadata = _require2.lineMetadata; module.exports = { - "names": ["MD012", "no-multiple-blanks"], - "description": "Multiple consecutive blank lines", - "tags": ["whitespace", "blank_lines"], - "function": function MD012(params, onError) { - const maximum = Number(params.config.maximum || 1); - let count = 0; - forEachLine(lineMetadata(), (line, lineIndex, inCode) => { - count = (inCode || (line.trim().length > 0)) ? 0 : count + 1; - if (maximum < count) { - addErrorDetailIf(onError, lineIndex + 1, maximum, count, null, null, null, { - "deleteCount": -1 - }); - } + "names": ["MD012", "no-multiple-blanks"], + "description": "Multiple consecutive blank lines", + "tags": ["whitespace", "blank_lines"], + "function": function MD012(params, onError) { + var maximum = Number(params.config.maximum || 1); + var count = 0; + forEachLine(lineMetadata(), function (line, lineIndex, inCode) { + count = inCode || line.trim().length > 0 ? 0 : count + 1; + if (maximum < count) { + addErrorDetailIf(onError, lineIndex + 1, maximum, count, null, null, null, { + "deleteCount": -1 }); - } + } + }); + } }; - /***/ }), /***/ "../lib/md013.js": @@ -2995,87 +3696,97 @@ module.exports = { "use strict"; // @ts-check -const { addErrorDetailIf, filterTokens, forEachHeading, forEachLine, includesSorted } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const { lineMetadata, referenceLinkImageData } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); -const longLineRePrefix = "^.{"; -const longLineRePostfixRelaxed = "}.*\\s.*$"; -const longLineRePostfixStrict = "}.+$"; -const linkOrImageOnlyLineRe = /^[es]*(?:lT?L|I)[ES]*$/; -const sternModeRe = /^(?:[#>\s]*\s)?\S*$/; -const tokenTypeMap = { - "em_open": "e", - "em_close": "E", - "image": "I", - "link_open": "l", - "link_close": "L", - "strong_open": "s", - "strong_close": "S", - "text": "T" + + +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; } } }; } +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); } +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; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorDetailIf = _require.addErrorDetailIf, + filterTokens = _require.filterTokens, + forEachHeading = _require.forEachHeading, + forEachLine = _require.forEachLine, + includesSorted = _require.includesSorted; +var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"), + lineMetadata = _require2.lineMetadata, + referenceLinkImageData = _require2.referenceLinkImageData; +var longLineRePrefix = "^.{"; +var longLineRePostfixRelaxed = "}.*\\s.*$"; +var longLineRePostfixStrict = "}.+$"; +var linkOrImageOnlyLineRe = /^[es]*(?:lT?L|I)[ES]*$/; +var sternModeRe = /^(?:[#>\s]*\s)?\S*$/; +var tokenTypeMap = { + "em_open": "e", + "em_close": "E", + "image": "I", + "link_open": "l", + "link_close": "L", + "strong_open": "s", + "strong_close": "S", + "text": "T" }; module.exports = { - "names": ["MD013", "line-length"], - "description": "Line length", - "tags": ["line_length"], - "function": function MD013(params, onError) { - const lineLength = Number(params.config.line_length || 80); - const headingLineLength = Number(params.config.heading_line_length || lineLength); - const codeLineLength = Number(params.config.code_block_line_length || lineLength); - const strict = !!params.config.strict; - const stern = !!params.config.stern; - const longLineRePostfix = (strict || stern) ? longLineRePostfixStrict : longLineRePostfixRelaxed; - const longLineRe = new RegExp(longLineRePrefix + lineLength + longLineRePostfix); - const longHeadingLineRe = new RegExp(longLineRePrefix + headingLineLength + longLineRePostfix); - const longCodeLineRe = new RegExp(longLineRePrefix + codeLineLength + longLineRePostfix); - const codeBlocks = params.config.code_blocks; - const includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks; - const tables = params.config.tables; - const includeTables = (tables === undefined) ? true : !!tables; - let headings = params.config.headings; - if (headings === undefined) { - headings = params.config.headers; - } - const includeHeadings = (headings === undefined) ? true : !!headings; - const headingLineNumbers = []; - forEachHeading(params, (heading) => { - headingLineNumbers.push(heading.lineNumber); - }); - const linkOnlyLineNumbers = []; - filterTokens(params, "inline", (token) => { - let childTokenTypes = ""; - for (const child of token.children) { - if (child.type !== "text" || child.content !== "") { - childTokenTypes += tokenTypeMap[child.type] || "x"; - } - } - if (linkOrImageOnlyLineRe.test(childTokenTypes)) { - linkOnlyLineNumbers.push(token.lineNumber); - } - }); - const { definitionLineIndices } = referenceLinkImageData(); - forEachLine(lineMetadata(), (line, lineIndex, inCode, onFence, inTable) => { - const lineNumber = lineIndex + 1; - const isHeading = includesSorted(headingLineNumbers, lineNumber); - const length = inCode ? - codeLineLength : - (isHeading ? headingLineLength : lineLength); - const lengthRe = inCode ? - longCodeLineRe : - (isHeading ? longHeadingLineRe : longLineRe); - if ((includeCodeBlocks || !inCode) && - (includeTables || !inTable) && - (includeHeadings || !isHeading) && - !includesSorted(definitionLineIndices, lineIndex) && - (strict || - (!(stern && sternModeRe.test(line)) && - !includesSorted(linkOnlyLineNumbers, lineNumber))) && - lengthRe.test(line)) { - addErrorDetailIf(onError, lineNumber, length, line.length, null, null, [length + 1, line.length - length]); - } - }); + "names": ["MD013", "line-length"], + "description": "Line length", + "tags": ["line_length"], + "function": function MD013(params, onError) { + var lineLength = Number(params.config.line_length || 80); + var headingLineLength = Number(params.config.heading_line_length || lineLength); + var codeLineLength = Number(params.config.code_block_line_length || lineLength); + var strict = !!params.config.strict; + var stern = !!params.config.stern; + var longLineRePostfix = strict || stern ? longLineRePostfixStrict : longLineRePostfixRelaxed; + var longLineRe = new RegExp(longLineRePrefix + lineLength + longLineRePostfix); + var longHeadingLineRe = new RegExp(longLineRePrefix + headingLineLength + longLineRePostfix); + var longCodeLineRe = new RegExp(longLineRePrefix + codeLineLength + longLineRePostfix); + var codeBlocks = params.config.code_blocks; + var includeCodeBlocks = codeBlocks === undefined ? true : !!codeBlocks; + var tables = params.config.tables; + var includeTables = tables === undefined ? true : !!tables; + var headings = params.config.headings; + if (headings === undefined) { + headings = params.config.headers; } + var includeHeadings = headings === undefined ? true : !!headings; + var headingLineNumbers = []; + forEachHeading(params, function (heading) { + headingLineNumbers.push(heading.lineNumber); + }); + var linkOnlyLineNumbers = []; + filterTokens(params, "inline", function (token) { + var childTokenTypes = ""; + var _iterator = _createForOfIteratorHelper(token.children), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var child = _step.value; + if (child.type !== "text" || child.content !== "") { + childTokenTypes += tokenTypeMap[child.type] || "x"; + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + if (linkOrImageOnlyLineRe.test(childTokenTypes)) { + linkOnlyLineNumbers.push(token.lineNumber); + } + }); + var _referenceLinkImageDa = referenceLinkImageData(), + definitionLineIndices = _referenceLinkImageDa.definitionLineIndices; + forEachLine(lineMetadata(), function (line, lineIndex, inCode, onFence, inTable) { + var lineNumber = lineIndex + 1; + var isHeading = includesSorted(headingLineNumbers, lineNumber); + var length = inCode ? codeLineLength : isHeading ? headingLineLength : lineLength; + var lengthRe = inCode ? longCodeLineRe : isHeading ? longHeadingLineRe : longLineRe; + if ((includeCodeBlocks || !inCode) && (includeTables || !inTable) && (includeHeadings || !isHeading) && !includesSorted(definitionLineIndices, lineIndex) && (strict || !(stern && sternModeRe.test(line)) && !includesSorted(linkOnlyLineNumbers, lineNumber)) && lengthRe.test(line)) { + addErrorDetailIf(onError, lineNumber, length, line.length, null, null, [length + 1, line.length - length]); + } + }); + } }; - /***/ }), /***/ "../lib/md014.js": @@ -3087,48 +3798,71 @@ module.exports = { "use strict"; // @ts-check -const { addErrorContext, filterTokens } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const dollarCommandRe = /^(\s*)(\$\s+)/; + + +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } +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."); } +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; } } +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } +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; } } }; } +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); } +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; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorContext = _require.addErrorContext, + filterTokens = _require.filterTokens; +var dollarCommandRe = /^(\s*)(\$\s+)/; module.exports = { - "names": ["MD014", "commands-show-output"], - "description": "Dollar signs used before commands without showing output", - "tags": ["code"], - "function": function MD014(params, onError) { - for (const type of ["code_block", "fence"]) { - filterTokens(params, type, (token) => { - const margin = (token.type === "fence") ? 1 : 0; - const dollarInstances = []; - let allDollars = true; - for (let i = token.map[0] + margin; i < token.map[1] - margin; i++) { - const line = params.lines[i]; - const lineTrim = line.trim(); - if (lineTrim) { - const match = dollarCommandRe.exec(line); - if (match) { - const column = match[1].length + 1; - const length = match[2].length; - dollarInstances.push([i, lineTrim, column, length]); - } - else { - allDollars = false; - } - } - } - if (allDollars) { - for (const instance of dollarInstances) { - const [i, lineTrim, column, length] = instance; - addErrorContext(onError, i + 1, lineTrim, null, null, [column, length], { - "editColumn": column, - "deleteCount": length - }); - } - } - }); - } + "names": ["MD014", "commands-show-output"], + "description": "Dollar signs used before commands without showing output", + "tags": ["code"], + "function": function MD014(params, onError) { + for (var _i = 0, _arr = ["code_block", "fence"]; _i < _arr.length; _i++) { + var type = _arr[_i]; + filterTokens(params, type, function (token) { + var margin = token.type === "fence" ? 1 : 0; + var dollarInstances = []; + var allDollars = true; + for (var i = token.map[0] + margin; i < token.map[1] - margin; i++) { + var line = params.lines[i]; + var lineTrim = line.trim(); + if (lineTrim) { + var match = dollarCommandRe.exec(line); + if (match) { + var column = match[1].length + 1; + var length = match[2].length; + dollarInstances.push([i, lineTrim, column, length]); + } else { + allDollars = false; + } + } + } + if (allDollars) { + var _iterator = _createForOfIteratorHelper(dollarInstances), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var instance = _step.value; + var _instance = _slicedToArray(instance, 4), + _i2 = _instance[0], + _lineTrim = _instance[1], + _column = _instance[2], + _length = _instance[3]; + addErrorContext(onError, _i2 + 1, _lineTrim, null, null, [_column, _length], { + "editColumn": _column, + "deleteCount": _length + }); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + } + }); } + } }; - /***/ }), /***/ "../lib/md018.js": @@ -3140,29 +3874,30 @@ module.exports = { "use strict"; // @ts-check -const { addErrorContext, forEachLine } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const { lineMetadata } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); + + +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorContext = _require.addErrorContext, + forEachLine = _require.forEachLine; +var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"), + lineMetadata = _require2.lineMetadata; module.exports = { - "names": ["MD018", "no-missing-space-atx"], - "description": "No space after hash on atx style heading", - "tags": ["headings", "headers", "atx", "spaces"], - "function": function MD018(params, onError) { - forEachLine(lineMetadata(), (line, lineIndex, inCode) => { - if (!inCode && - /^#+[^# \t]/.test(line) && - !/#\s*$/.test(line) && - !line.startsWith("#️⃣")) { - const hashCount = /^#+/.exec(line)[0].length; - addErrorContext(onError, lineIndex + 1, line.trim(), null, null, [1, hashCount + 1], { - "editColumn": hashCount + 1, - "insertText": " " - }); - } + "names": ["MD018", "no-missing-space-atx"], + "description": "No space after hash on atx style heading", + "tags": ["headings", "headers", "atx", "spaces"], + "function": function MD018(params, onError) { + forEachLine(lineMetadata(), function (line, lineIndex, inCode) { + if (!inCode && /^#+[^# \t]/.test(line) && !/#\s*$/.test(line) && !line.startsWith("#️⃣")) { + var hashCount = /^#+/.exec(line)[0].length; + addErrorContext(onError, lineIndex + 1, line.trim(), null, null, [1, hashCount + 1], { + "editColumn": hashCount + 1, + "insertText": " " }); - } + } + }); + } }; - /***/ }), /***/ "../lib/md019.js": @@ -3174,29 +3909,42 @@ module.exports = { "use strict"; // @ts-check -const { addErrorContext, filterTokens, headingStyleFor } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); + + +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } +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."); } +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); } +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; } +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; } } +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorContext = _require.addErrorContext, + filterTokens = _require.filterTokens, + headingStyleFor = _require.headingStyleFor; module.exports = { - "names": ["MD019", "no-multiple-space-atx"], - "description": "Multiple spaces after hash on atx style heading", - "tags": ["headings", "headers", "atx", "spaces"], - "function": function MD019(params, onError) { - filterTokens(params, "heading_open", (token) => { - if (headingStyleFor(token) === "atx") { - const { line, lineNumber } = token; - const match = /^(#+)([ \t]{2,})\S/.exec(line); - if (match) { - const [, { "length": hashLength }, { "length": spacesLength }] = match; - addErrorContext(onError, lineNumber, line.trim(), null, null, [1, hashLength + spacesLength + 1], { - "editColumn": hashLength + 1, - "deleteCount": spacesLength - 1 - }); - } - } - }); - } + "names": ["MD019", "no-multiple-space-atx"], + "description": "Multiple spaces after hash on atx style heading", + "tags": ["headings", "headers", "atx", "spaces"], + "function": function MD019(params, onError) { + filterTokens(params, "heading_open", function (token) { + if (headingStyleFor(token) === "atx") { + var line = token.line, + lineNumber = token.lineNumber; + var match = /^(#+)([ \t]{2,})\S/.exec(line); + if (match) { + var _match = _slicedToArray(match, 3), + hashLength = _match[1]["length"], + spacesLength = _match[2]["length"]; + addErrorContext(onError, lineNumber, line.trim(), null, null, [1, hashLength + spacesLength + 1], { + "editColumn": hashLength + 1, + "deleteCount": spacesLength - 1 + }); + } + } + }); + } }; - /***/ }), /***/ "../lib/md020.js": @@ -3208,46 +3956,55 @@ module.exports = { "use strict"; // @ts-check -const { addErrorContext, forEachLine } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const { lineMetadata } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); + + +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } +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."); } +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); } +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; } +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; } } +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorContext = _require.addErrorContext, + forEachLine = _require.forEachLine; +var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"), + lineMetadata = _require2.lineMetadata; module.exports = { - "names": ["MD020", "no-missing-space-closed-atx"], - "description": "No space inside hashes on closed atx style heading", - "tags": ["headings", "headers", "atx_closed", "spaces"], - "function": function MD020(params, onError) { - forEachLine(lineMetadata(), (line, lineIndex, inCode) => { - if (!inCode) { - const match = /^(#+)([ \t]*)([^#]*?[^#\\])([ \t]*)((?:\\#)?)(#+)(\s*)$/.exec(line); - if (match) { - const [, leftHash, { "length": leftSpaceLength }, content, { "length": rightSpaceLength }, rightEscape, rightHash, { "length": trailSpaceLength }] = match; - const leftHashLength = leftHash.length; - const rightHashLength = rightHash.length; - const left = !leftSpaceLength; - const right = !rightSpaceLength || rightEscape; - const rightEscapeReplacement = rightEscape ? `${rightEscape} ` : ""; - if (left || right) { - const range = left ? - [ - 1, - leftHashLength + 1 - ] : - [ - line.length - trailSpaceLength - rightHashLength, - rightHashLength + 1 - ]; - addErrorContext(onError, lineIndex + 1, line.trim(), left, right, range, { - "editColumn": 1, - "deleteCount": line.length, - "insertText": `${leftHash} ${content} ${rightEscapeReplacement}${rightHash}` - }); - } - } - } - }); - } + "names": ["MD020", "no-missing-space-closed-atx"], + "description": "No space inside hashes on closed atx style heading", + "tags": ["headings", "headers", "atx_closed", "spaces"], + "function": function MD020(params, onError) { + forEachLine(lineMetadata(), function (line, lineIndex, inCode) { + if (!inCode) { + var match = /^(#+)([ \t]*)([^#]*?[^#\\])([ \t]*)((?:\\#)?)(#+)(\s*)$/.exec(line); + if (match) { + var _match = _slicedToArray(match, 8), + leftHash = _match[1], + leftSpaceLength = _match[2]["length"], + content = _match[3], + rightSpaceLength = _match[4]["length"], + rightEscape = _match[5], + rightHash = _match[6], + trailSpaceLength = _match[7]["length"]; + var leftHashLength = leftHash.length; + var rightHashLength = rightHash.length; + var left = !leftSpaceLength; + var right = !rightSpaceLength || rightEscape; + var rightEscapeReplacement = rightEscape ? "".concat(rightEscape, " ") : ""; + if (left || right) { + var range = left ? [1, leftHashLength + 1] : [line.length - trailSpaceLength - rightHashLength, rightHashLength + 1]; + addErrorContext(onError, lineIndex + 1, line.trim(), left, right, range, { + "editColumn": 1, + "deleteCount": line.length, + "insertText": "".concat(leftHash, " ").concat(content, " ").concat(rightEscapeReplacement).concat(rightHash) + }); + } + } + } + }); + } }; - /***/ }), /***/ "../lib/md021.js": @@ -3259,47 +4016,56 @@ module.exports = { "use strict"; // @ts-check -const { addErrorContext, filterTokens, headingStyleFor } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const closedAtxRe = /^(#+)([ \t]+)([^ \t]|[^ \t].*[^ \t])([ \t]+)(#+)(\s*)$/; + + +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } +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."); } +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); } +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; } +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; } } +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorContext = _require.addErrorContext, + filterTokens = _require.filterTokens, + headingStyleFor = _require.headingStyleFor; +var closedAtxRe = /^(#+)([ \t]+)([^ \t]|[^ \t].*[^ \t])([ \t]+)(#+)(\s*)$/; module.exports = { - "names": ["MD021", "no-multiple-space-closed-atx"], - "description": "Multiple spaces inside hashes on closed atx style heading", - "tags": ["headings", "headers", "atx_closed", "spaces"], - "function": function MD021(params, onError) { - filterTokens(params, "heading_open", (token) => { - if (headingStyleFor(token) === "atx_closed") { - const { line, lineNumber } = token; - const match = closedAtxRe.exec(line); - if (match) { - const [, leftHash, { "length": leftSpaceLength }, content, { "length": rightSpaceLength }, rightHash, { "length": trailSpaceLength }] = match; - const left = leftSpaceLength > 1; - const right = rightSpaceLength > 1; - if (left || right) { - const length = line.length; - const leftHashLength = leftHash.length; - const rightHashLength = rightHash.length; - const range = left ? - [ - 1, - leftHashLength + leftSpaceLength + 1 - ] : - [ - length - trailSpaceLength - rightHashLength - rightSpaceLength, - rightSpaceLength + rightHashLength + 1 - ]; - addErrorContext(onError, lineNumber, line.trim(), left, right, range, { - "editColumn": 1, - "deleteCount": length, - "insertText": `${leftHash} ${content} ${rightHash}` - }); - } - } - } - }); - } + "names": ["MD021", "no-multiple-space-closed-atx"], + "description": "Multiple spaces inside hashes on closed atx style heading", + "tags": ["headings", "headers", "atx_closed", "spaces"], + "function": function MD021(params, onError) { + filterTokens(params, "heading_open", function (token) { + if (headingStyleFor(token) === "atx_closed") { + var line = token.line, + lineNumber = token.lineNumber; + var match = closedAtxRe.exec(line); + if (match) { + var _match = _slicedToArray(match, 7), + leftHash = _match[1], + leftSpaceLength = _match[2]["length"], + content = _match[3], + rightSpaceLength = _match[4]["length"], + rightHash = _match[5], + trailSpaceLength = _match[6]["length"]; + var left = leftSpaceLength > 1; + var right = rightSpaceLength > 1; + if (left || right) { + var length = line.length; + var leftHashLength = leftHash.length; + var rightHashLength = rightHash.length; + var range = left ? [1, leftHashLength + leftSpaceLength + 1] : [length - trailSpaceLength - rightHashLength - rightSpaceLength, rightSpaceLength + rightHashLength + 1]; + addErrorContext(onError, lineNumber, line.trim(), left, right, range, { + "editColumn": 1, + "deleteCount": length, + "insertText": "".concat(leftHash, " ").concat(content, " ").concat(rightHash) + }); + } + } + } + }); + } }; - /***/ }), /***/ "../lib/md022.js": @@ -3311,49 +4077,61 @@ module.exports = { "use strict"; // @ts-check -const { addErrorDetailIf, blockquotePrefixRe, filterTokens, isBlankLine } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const getBlockQuote = (str, count) => ((str || "") - .match(blockquotePrefixRe)[0] - .trimEnd() - // eslint-disable-next-line unicorn/prefer-spread - .concat("\n") - .repeat(count)); + + +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } +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."); } +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); } +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; } +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; } } +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorDetailIf = _require.addErrorDetailIf, + blockquotePrefixRe = _require.blockquotePrefixRe, + filterTokens = _require.filterTokens, + isBlankLine = _require.isBlankLine; +var getBlockQuote = function getBlockQuote(str, count) { + return (str || "").match(blockquotePrefixRe)[0].trimEnd() + // eslint-disable-next-line unicorn/prefer-spread + .concat("\n").repeat(count); +}; module.exports = { - "names": ["MD022", "blanks-around-headings", "blanks-around-headers"], - "description": "Headings should be surrounded by blank lines", - "tags": ["headings", "headers", "blank_lines"], - "function": function MD022(params, onError) { - let linesAbove = params.config.lines_above; - linesAbove = Number((linesAbove === undefined) ? 1 : linesAbove); - let linesBelow = params.config.lines_below; - linesBelow = Number((linesBelow === undefined) ? 1 : linesBelow); - const { lines } = params; - filterTokens(params, "heading_open", (token) => { - const [topIndex, nextIndex] = token.map; - let actualAbove = 0; - for (let i = 0; i < linesAbove; i++) { - if (isBlankLine(lines[topIndex - i - 1])) { - actualAbove++; - } - } - addErrorDetailIf(onError, topIndex + 1, linesAbove, actualAbove, "Above", lines[topIndex].trim(), null, { - "insertText": getBlockQuote(lines[topIndex - 1], linesAbove - actualAbove) - }); - let actualBelow = 0; - for (let i = 0; i < linesBelow; i++) { - if (isBlankLine(lines[nextIndex + i])) { - actualBelow++; - } - } - addErrorDetailIf(onError, topIndex + 1, linesBelow, actualBelow, "Below", lines[topIndex].trim(), null, { - "lineNumber": nextIndex + 1, - "insertText": getBlockQuote(lines[nextIndex], linesBelow - actualBelow) - }); - }); - } + "names": ["MD022", "blanks-around-headings", "blanks-around-headers"], + "description": "Headings should be surrounded by blank lines", + "tags": ["headings", "headers", "blank_lines"], + "function": function MD022(params, onError) { + var linesAbove = params.config.lines_above; + linesAbove = Number(linesAbove === undefined ? 1 : linesAbove); + var linesBelow = params.config.lines_below; + linesBelow = Number(linesBelow === undefined ? 1 : linesBelow); + var lines = params.lines; + filterTokens(params, "heading_open", function (token) { + var _token$map = _slicedToArray(token.map, 2), + topIndex = _token$map[0], + nextIndex = _token$map[1]; + var actualAbove = 0; + for (var i = 0; i < linesAbove; i++) { + if (isBlankLine(lines[topIndex - i - 1])) { + actualAbove++; + } + } + addErrorDetailIf(onError, topIndex + 1, linesAbove, actualAbove, "Above", lines[topIndex].trim(), null, { + "insertText": getBlockQuote(lines[topIndex - 1], linesAbove - actualAbove) + }); + var actualBelow = 0; + for (var _i2 = 0; _i2 < linesBelow; _i2++) { + if (isBlankLine(lines[nextIndex + _i2])) { + actualBelow++; + } + } + addErrorDetailIf(onError, topIndex + 1, linesBelow, actualBelow, "Below", lines[topIndex].trim(), null, { + "lineNumber": nextIndex + 1, + "insertText": getBlockQuote(lines[nextIndex], linesBelow - actualBelow) + }); + }); + } }; - /***/ }), /***/ "../lib/md023.js": @@ -3365,33 +4143,45 @@ module.exports = { "use strict"; // @ts-check -const { addErrorContext, filterTokens } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const spaceBeforeHeadingRe = /^(\s+|[>\s]+\s\s)[^>\s]/; + + +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } +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."); } +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); } +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; } +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; } } +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorContext = _require.addErrorContext, + filterTokens = _require.filterTokens; +var spaceBeforeHeadingRe = /^(\s+|[>\s]+\s\s)[^>\s]/; module.exports = { - "names": ["MD023", "heading-start-left", "header-start-left"], - "description": "Headings must start at the beginning of the line", - "tags": ["headings", "headers", "spaces"], - "function": function MD023(params, onError) { - filterTokens(params, "heading_open", function forToken(token) { - const { lineNumber, line } = token; - const match = line.match(spaceBeforeHeadingRe); - if (match) { - const [prefixAndFirstChar, prefix] = match; - let deleteCount = prefix.length; - const prefixLengthNoSpace = prefix.trimEnd().length; - if (prefixLengthNoSpace) { - deleteCount -= prefixLengthNoSpace - 1; - } - addErrorContext(onError, lineNumber, line, null, null, [1, prefixAndFirstChar.length], { - "editColumn": prefixLengthNoSpace + 1, - "deleteCount": deleteCount - }); - } + "names": ["MD023", "heading-start-left", "header-start-left"], + "description": "Headings must start at the beginning of the line", + "tags": ["headings", "headers", "spaces"], + "function": function MD023(params, onError) { + filterTokens(params, "heading_open", function forToken(token) { + var lineNumber = token.lineNumber, + line = token.line; + var match = line.match(spaceBeforeHeadingRe); + if (match) { + var _match = _slicedToArray(match, 2), + prefixAndFirstChar = _match[0], + prefix = _match[1]; + var deleteCount = prefix.length; + var prefixLengthNoSpace = prefix.trimEnd().length; + if (prefixLengthNoSpace) { + deleteCount -= prefixLengthNoSpace - 1; + } + addErrorContext(onError, lineNumber, line, null, null, [1, prefixAndFirstChar.length], { + "editColumn": prefixLengthNoSpace + 1, + "deleteCount": deleteCount }); - } + } + }); + } }; - /***/ }), /***/ "../lib/md024.js": @@ -3403,41 +4193,42 @@ module.exports = { "use strict"; // @ts-check -const { addErrorContext, forEachHeading } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); + + +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorContext = _require.addErrorContext, + forEachHeading = _require.forEachHeading; module.exports = { - "names": ["MD024", "no-duplicate-heading", "no-duplicate-header"], - "description": "Multiple headings with the same content", - "tags": ["headings", "headers"], - "function": function MD024(params, onError) { - const siblingsOnly = !!params.config.siblings_only || - !!params.config.allow_different_nesting || false; - const knownContents = [null, []]; - let lastLevel = 1; - let knownContent = knownContents[lastLevel]; - forEachHeading(params, (heading, content) => { - if (siblingsOnly) { - const newLevel = heading.tag.slice(1); - while (lastLevel < newLevel) { - lastLevel++; - knownContents[lastLevel] = []; - } - while (lastLevel > newLevel) { - knownContents[lastLevel] = []; - lastLevel--; - } - knownContent = knownContents[newLevel]; - } - if (knownContent.includes(content)) { - addErrorContext(onError, heading.lineNumber, heading.line.trim()); - } - else { - knownContent.push(content); - } - }); - } + "names": ["MD024", "no-duplicate-heading", "no-duplicate-header"], + "description": "Multiple headings with the same content", + "tags": ["headings", "headers"], + "function": function MD024(params, onError) { + var siblingsOnly = !!params.config.siblings_only || !!params.config.allow_different_nesting || false; + var knownContents = [null, []]; + var lastLevel = 1; + var knownContent = knownContents[lastLevel]; + forEachHeading(params, function (heading, content) { + if (siblingsOnly) { + var newLevel = heading.tag.slice(1); + while (lastLevel < newLevel) { + lastLevel++; + knownContents[lastLevel] = []; + } + while (lastLevel > newLevel) { + knownContents[lastLevel] = []; + lastLevel--; + } + knownContent = knownContents[newLevel]; + } + if (knownContent.includes(content)) { + addErrorContext(onError, heading.lineNumber, heading.line.trim()); + } else { + knownContent.push(content); + } + }); + } }; - /***/ }), /***/ "../lib/md025.js": @@ -3449,30 +4240,33 @@ module.exports = { "use strict"; // @ts-check -const { addErrorContext, filterTokens, frontMatterHasTitle } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); + + +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorContext = _require.addErrorContext, + filterTokens = _require.filterTokens, + frontMatterHasTitle = _require.frontMatterHasTitle; module.exports = { - "names": ["MD025", "single-title", "single-h1"], - "description": "Multiple top-level headings in the same document", - "tags": ["headings", "headers"], - "function": function MD025(params, onError) { - const level = Number(params.config.level || 1); - const tag = "h" + level; - const foundFrontMatterTitle = frontMatterHasTitle(params.frontMatterLines, params.config.front_matter_title); - let hasTopLevelHeading = false; - filterTokens(params, "heading_open", function forToken(token) { - if (token.tag === tag) { - if (hasTopLevelHeading || foundFrontMatterTitle) { - addErrorContext(onError, token.lineNumber, token.line.trim()); - } - else if (token.lineNumber === 1) { - hasTopLevelHeading = true; - } - } - }); - } + "names": ["MD025", "single-title", "single-h1"], + "description": "Multiple top-level headings in the same document", + "tags": ["headings", "headers"], + "function": function MD025(params, onError) { + var level = Number(params.config.level || 1); + var tag = "h" + level; + var foundFrontMatterTitle = frontMatterHasTitle(params.frontMatterLines, params.config.front_matter_title); + var hasTopLevelHeading = false; + filterTokens(params, "heading_open", function forToken(token) { + if (token.tag === tag) { + if (hasTopLevelHeading || foundFrontMatterTitle) { + addErrorContext(onError, token.lineNumber, token.line.trim()); + } else if (token.lineNumber === 1) { + hasTopLevelHeading = true; + } + } + }); + } }; - /***/ }), /***/ "../lib/md026.js": @@ -3484,34 +4278,40 @@ module.exports = { "use strict"; // @ts-check -const { addError, allPunctuationNoQuestion, escapeForRegExp, forEachHeading } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const endOfLineHtmlEntityRe = /&#?[\da-zA-Z]+;$/; + + +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addError = _require.addError, + allPunctuationNoQuestion = _require.allPunctuationNoQuestion, + escapeForRegExp = _require.escapeForRegExp, + forEachHeading = _require.forEachHeading; +var endOfLineHtmlEntityRe = /&#?[\da-zA-Z]+;$/; module.exports = { - "names": ["MD026", "no-trailing-punctuation"], - "description": "Trailing punctuation in heading", - "tags": ["headings", "headers"], - "function": function MD026(params, onError) { - let punctuation = params.config.punctuation; - punctuation = String((punctuation === undefined) ? allPunctuationNoQuestion : punctuation); - const trailingPunctuationRe = new RegExp("\\s*[" + escapeForRegExp(punctuation) + "]+$"); - forEachHeading(params, (heading) => { - const { line, lineNumber } = heading; - const trimmedLine = line.replace(/([^\s#])[\s#]+$/, "$1"); - const match = trailingPunctuationRe.exec(trimmedLine); - if (match && !endOfLineHtmlEntityRe.test(trimmedLine)) { - const fullMatch = match[0]; - const column = match.index + 1; - const length = fullMatch.length; - addError(onError, lineNumber, `Punctuation: '${fullMatch}'`, null, [column, length], { - "editColumn": column, - "deleteCount": length - }); - } + "names": ["MD026", "no-trailing-punctuation"], + "description": "Trailing punctuation in heading", + "tags": ["headings", "headers"], + "function": function MD026(params, onError) { + var punctuation = params.config.punctuation; + punctuation = String(punctuation === undefined ? allPunctuationNoQuestion : punctuation); + var trailingPunctuationRe = new RegExp("\\s*[" + escapeForRegExp(punctuation) + "]+$"); + forEachHeading(params, function (heading) { + var line = heading.line, + lineNumber = heading.lineNumber; + var trimmedLine = line.replace(/([^\s#])[\s#]+$/, "$1"); + var match = trailingPunctuationRe.exec(trimmedLine); + if (match && !endOfLineHtmlEntityRe.test(trimmedLine)) { + var fullMatch = match[0]; + var column = match.index + 1; + var length = fullMatch.length; + addError(onError, lineNumber, "Punctuation: '".concat(fullMatch, "'"), null, [column, length], { + "editColumn": column, + "deleteCount": length }); - } + } + }); + } }; - /***/ }), /***/ "../lib/md027.js": @@ -3523,50 +4323,70 @@ module.exports = { "use strict"; // @ts-check -const { addErrorContext, newLineRe } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const spaceAfterBlockQuoteRe = /^((?:\s*>)+)(\s{2,})\S/; + + +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } +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."); } +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; } } +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } +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; } } }; } +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); } +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; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorContext = _require.addErrorContext, + newLineRe = _require.newLineRe; +var spaceAfterBlockQuoteRe = /^((?:\s*>)+)(\s{2,})\S/; module.exports = { - "names": ["MD027", "no-multiple-space-blockquote"], - "description": "Multiple spaces after blockquote symbol", - "tags": ["blockquote", "whitespace", "indentation"], - "function": function MD027(params, onError) { - let blockquoteNesting = 0; - let listItemNesting = 0; - for (const token of params.tokens) { - const { content, lineNumber, type } = token; - if (type === "blockquote_open") { - blockquoteNesting++; - } - else if (type === "blockquote_close") { - blockquoteNesting--; - } - else if (type === "list_item_open") { - listItemNesting++; - } - else if (type === "list_item_close") { - listItemNesting--; - } - else if ((type === "inline") && blockquoteNesting) { - const lineCount = content.split(newLineRe).length; - for (let i = 0; i < lineCount; i++) { - const line = params.lines[lineNumber + i - 1]; - const match = line.match(spaceAfterBlockQuoteRe); - if (match) { - const [fullMatch, { "length": blockquoteLength }, { "length": spaceLength }] = match; - if (!listItemNesting || (fullMatch[fullMatch.length - 1] === ">")) { - addErrorContext(onError, lineNumber + i, line, null, null, [1, fullMatch.length], { - "editColumn": blockquoteLength + 1, - "deleteCount": spaceLength - 1 - }); - } - } - } + "names": ["MD027", "no-multiple-space-blockquote"], + "description": "Multiple spaces after blockquote symbol", + "tags": ["blockquote", "whitespace", "indentation"], + "function": function MD027(params, onError) { + var blockquoteNesting = 0; + var listItemNesting = 0; + var _iterator = _createForOfIteratorHelper(params.tokens), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var token = _step.value; + var content = token.content, + lineNumber = token.lineNumber, + type = token.type; + if (type === "blockquote_open") { + blockquoteNesting++; + } else if (type === "blockquote_close") { + blockquoteNesting--; + } else if (type === "list_item_open") { + listItemNesting++; + } else if (type === "list_item_close") { + listItemNesting--; + } else if (type === "inline" && blockquoteNesting) { + var lineCount = content.split(newLineRe).length; + for (var i = 0; i < lineCount; i++) { + var line = params.lines[lineNumber + i - 1]; + var match = line.match(spaceAfterBlockQuoteRe); + if (match) { + var _match = _slicedToArray(match, 3), + fullMatch = _match[0], + blockquoteLength = _match[1]["length"], + spaceLength = _match[2]["length"]; + if (!listItemNesting || fullMatch[fullMatch.length - 1] === ">") { + addErrorContext(onError, lineNumber + i, line, null, null, [1, fullMatch.length], { + "editColumn": blockquoteLength + 1, + "deleteCount": spaceLength - 1 + }); + } } + } } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); } + } }; - /***/ }), /***/ "../lib/md028.js": @@ -3578,30 +4398,43 @@ module.exports = { "use strict"; // @ts-check -const { addError } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); + + +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; } } }; } +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); } +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; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addError = _require.addError; module.exports = { - "names": ["MD028", "no-blanks-blockquote"], - "description": "Blank line inside blockquote", - "tags": ["blockquote", "whitespace"], - "function": function MD028(params, onError) { - let prevToken = {}; - let prevLineNumber = null; - for (const token of params.tokens) { - if ((token.type === "blockquote_open") && - (prevToken.type === "blockquote_close")) { - for (let lineNumber = prevLineNumber; lineNumber < token.lineNumber; lineNumber++) { - addError(onError, lineNumber); - } - } - prevToken = token; - if (token.type === "blockquote_open") { - prevLineNumber = token.map[1] + 1; - } - } + "names": ["MD028", "no-blanks-blockquote"], + "description": "Blank line inside blockquote", + "tags": ["blockquote", "whitespace"], + "function": function MD028(params, onError) { + var prevToken = {}; + var prevLineNumber = null; + var _iterator = _createForOfIteratorHelper(params.tokens), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var token = _step.value; + if (token.type === "blockquote_open" && prevToken.type === "blockquote_close") { + for (var lineNumber = prevLineNumber; lineNumber < token.lineNumber; lineNumber++) { + addError(onError, lineNumber); + } + } + prevToken = token; + if (token.type === "blockquote_open") { + prevLineNumber = token.map[1] + 1; + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); } + } }; - /***/ }), /***/ "../lib/md029.js": @@ -3613,66 +4446,100 @@ module.exports = { "use strict"; // @ts-check -const { addErrorDetailIf, listItemMarkerRe, orderedListItemMarkerRe, rangeFromRegExp } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const { flattenedLists } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); -const listStyleExamples = { - "one": "1/1/1", - "ordered": "1/2/3", - "zero": "0/0/0" + + +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } +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."); } +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; } } +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } +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; } } }; } +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); } +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; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorDetailIf = _require.addErrorDetailIf, + listItemMarkerRe = _require.listItemMarkerRe, + orderedListItemMarkerRe = _require.orderedListItemMarkerRe, + rangeFromRegExp = _require.rangeFromRegExp; +var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"), + flattenedLists = _require2.flattenedLists; +var listStyleExamples = { + "one": "1/1/1", + "ordered": "1/2/3", + "zero": "0/0/0" }; module.exports = { - "names": ["MD029", "ol-prefix"], - "description": "Ordered list item prefix", - "tags": ["ol"], - "function": function MD029(params, onError) { - const style = String(params.config.style || "one_or_ordered"); - const filteredLists = flattenedLists().filter((list) => !list.unordered); - for (const list of filteredLists) { - const { items } = list; - let current = 1; - let incrementing = false; - // Check for incrementing number pattern 1/2/3 or 0/1/2 - if (items.length >= 2) { - const first = orderedListItemMarkerRe.exec(items[0].line); - const second = orderedListItemMarkerRe.exec(items[1].line); - if (first && second) { - const [, firstNumber] = first; - const [, secondNumber] = second; - if ((secondNumber !== "1") || (firstNumber === "0")) { - incrementing = true; - if (firstNumber === "0") { - current = 0; - } - } - } - } - // Determine effective style - let listStyle = style; - if (listStyle === "one_or_ordered") { - listStyle = incrementing ? "ordered" : "one"; - } - // Force expected value for 0/0/0 and 1/1/1 patterns - if (listStyle === "zero") { + "names": ["MD029", "ol-prefix"], + "description": "Ordered list item prefix", + "tags": ["ol"], + "function": function MD029(params, onError) { + var style = String(params.config.style || "one_or_ordered"); + var filteredLists = flattenedLists().filter(function (list) { + return !list.unordered; + }); + var _iterator = _createForOfIteratorHelper(filteredLists), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var list = _step.value; + var items = list.items; + var current = 1; + var incrementing = false; + // Check for incrementing number pattern 1/2/3 or 0/1/2 + if (items.length >= 2) { + var first = orderedListItemMarkerRe.exec(items[0].line); + var second = orderedListItemMarkerRe.exec(items[1].line); + if (first && second) { + var _first = _slicedToArray(first, 2), + firstNumber = _first[1]; + var _second = _slicedToArray(second, 2), + secondNumber = _second[1]; + if (secondNumber !== "1" || firstNumber === "0") { + incrementing = true; + if (firstNumber === "0") { current = 0; + } } - else if (listStyle === "one") { - current = 1; - } - // Validate each list item marker - for (const item of items) { - const match = orderedListItemMarkerRe.exec(item.line); - if (match) { - addErrorDetailIf(onError, item.lineNumber, String(current), match[1], "Style: " + listStyleExamples[listStyle], null, rangeFromRegExp(item.line, listItemMarkerRe)); - if (listStyle === "ordered") { - current++; - } - } - } + } + } + // Determine effective style + var listStyle = style; + if (listStyle === "one_or_ordered") { + listStyle = incrementing ? "ordered" : "one"; + } + // Force expected value for 0/0/0 and 1/1/1 patterns + if (listStyle === "zero") { + current = 0; + } else if (listStyle === "one") { + current = 1; } + // Validate each list item marker + var _iterator2 = _createForOfIteratorHelper(items), + _step2; + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var item = _step2.value; + var match = orderedListItemMarkerRe.exec(item.line); + if (match) { + addErrorDetailIf(onError, item.lineNumber, String(current), match[1], "Style: " + listStyleExamples[listStyle], null, rangeFromRegExp(item.line, listItemMarkerRe)); + if (listStyle === "ordered") { + current++; + } + } + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); } + } }; - /***/ }), /***/ "../lib/md030.js": @@ -3684,44 +4551,73 @@ module.exports = { "use strict"; // @ts-check -const { addErrorDetailIf } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const { flattenedLists } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); -module.exports = { - "names": ["MD030", "list-marker-space"], - "description": "Spaces after list markers", - "tags": ["ol", "ul", "whitespace"], - "function": function MD030(params, onError) { - const ulSingle = Number(params.config.ul_single || 1); - const olSingle = Number(params.config.ol_single || 1); - const ulMulti = Number(params.config.ul_multi || 1); - const olMulti = Number(params.config.ol_multi || 1); - for (const list of flattenedLists()) { - const lineCount = list.lastLineIndex - list.open.map[0]; - const allSingle = lineCount === list.items.length; - const expectedSpaces = list.unordered ? - (allSingle ? ulSingle : ulMulti) : - (allSingle ? olSingle : olMulti); - for (const item of list.items) { - const { line, lineNumber } = item; - const match = /^[\s>]*\S+(\s*)/.exec(line); - const [{ "length": matchLength }, { "length": actualSpaces }] = match; - if (matchLength < line.length) { - let fixInfo = null; - if (expectedSpaces !== actualSpaces) { - fixInfo = { - "editColumn": matchLength - actualSpaces + 1, - "deleteCount": actualSpaces, - "insertText": "".padEnd(expectedSpaces) - }; - } - addErrorDetailIf(onError, lineNumber, expectedSpaces, actualSpaces, null, null, [1, matchLength], fixInfo); - } - } - } + + +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } +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."); } +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; } } +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } +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; } } }; } +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); } +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; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorDetailIf = _require.addErrorDetailIf; +var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"), + flattenedLists = _require2.flattenedLists; +module.exports = { + "names": ["MD030", "list-marker-space"], + "description": "Spaces after list markers", + "tags": ["ol", "ul", "whitespace"], + "function": function MD030(params, onError) { + var ulSingle = Number(params.config.ul_single || 1); + var olSingle = Number(params.config.ol_single || 1); + var ulMulti = Number(params.config.ul_multi || 1); + var olMulti = Number(params.config.ol_multi || 1); + var _iterator = _createForOfIteratorHelper(flattenedLists()), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var list = _step.value; + var lineCount = list.lastLineIndex - list.open.map[0]; + var allSingle = lineCount === list.items.length; + var expectedSpaces = list.unordered ? allSingle ? ulSingle : ulMulti : allSingle ? olSingle : olMulti; + var _iterator2 = _createForOfIteratorHelper(list.items), + _step2; + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var item = _step2.value; + var line = item.line, + lineNumber = item.lineNumber; + var match = /^[\s>]*\S+(\s*)/.exec(line); + var _match = _slicedToArray(match, 2), + matchLength = _match[0]["length"], + actualSpaces = _match[1]["length"]; + if (matchLength < line.length) { + var fixInfo = null; + if (expectedSpaces !== actualSpaces) { + fixInfo = { + "editColumn": matchLength - actualSpaces + 1, + "deleteCount": actualSpaces, + "insertText": "".padEnd(expectedSpaces) + }; + } + addErrorDetailIf(onError, lineNumber, expectedSpaces, actualSpaces, null, null, [1, matchLength], fixInfo); + } + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); } + } }; - /***/ }), /***/ "../lib/md031.js": @@ -3733,35 +4629,46 @@ module.exports = { "use strict"; // @ts-check -const { addErrorContext, forEachLine, isBlankLine } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const { lineMetadata } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); -const codeFencePrefixRe = /^(.*?)[`~]/; + + +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } +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."); } +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); } +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; } +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; } } +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorContext = _require.addErrorContext, + forEachLine = _require.forEachLine, + isBlankLine = _require.isBlankLine; +var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"), + lineMetadata = _require2.lineMetadata; +var codeFencePrefixRe = /^(.*?)[`~]/; module.exports = { - "names": ["MD031", "blanks-around-fences"], - "description": "Fenced code blocks should be surrounded by blank lines", - "tags": ["code", "blank_lines"], - "function": function MD031(params, onError) { - const listItems = params.config.list_items; - const includeListItems = (listItems === undefined) ? true : !!listItems; - const { lines } = params; - forEachLine(lineMetadata(), (line, i, inCode, onFence, inTable, inItem) => { - const onTopFence = (onFence > 0); - const onBottomFence = (onFence < 0); - if ((includeListItems || !inItem) && - ((onTopFence && !isBlankLine(lines[i - 1])) || - (onBottomFence && !isBlankLine(lines[i + 1])))) { - const [, prefix] = line.match(codeFencePrefixRe) || []; - const fixInfo = (prefix === undefined) ? null : { - "lineNumber": i + (onTopFence ? 1 : 2), - "insertText": `${prefix.replace(/[^>]/g, " ").trim()}\n` - }; - addErrorContext(onError, i + 1, lines[i].trim(), null, null, null, fixInfo); - } - }); - } + "names": ["MD031", "blanks-around-fences"], + "description": "Fenced code blocks should be surrounded by blank lines", + "tags": ["code", "blank_lines"], + "function": function MD031(params, onError) { + var listItems = params.config.list_items; + var includeListItems = listItems === undefined ? true : !!listItems; + var lines = params.lines; + forEachLine(lineMetadata(), function (line, i, inCode, onFence, inTable, inItem) { + var onTopFence = onFence > 0; + var onBottomFence = onFence < 0; + if ((includeListItems || !inItem) && (onTopFence && !isBlankLine(lines[i - 1]) || onBottomFence && !isBlankLine(lines[i + 1]))) { + var _ref = line.match(codeFencePrefixRe) || [], + _ref2 = _slicedToArray(_ref, 2), + prefix = _ref2[1]; + var fixInfo = prefix === undefined ? null : { + "lineNumber": i + (onTopFence ? 1 : 2), + "insertText": "".concat(prefix.replace(/[^>]/g, " ").trim(), "\n") + }; + addErrorContext(onError, i + 1, lines[i].trim(), null, null, null, fixInfo); + } + }); + } }; - /***/ }), /***/ "../lib/md032.js": @@ -3773,38 +4680,57 @@ module.exports = { "use strict"; // @ts-check -const { addErrorContext, blockquotePrefixRe, isBlankLine } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const { flattenedLists } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); + + +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; } } }; } +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); } +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; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorContext = _require.addErrorContext, + blockquotePrefixRe = _require.blockquotePrefixRe, + isBlankLine = _require.isBlankLine; +var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"), + flattenedLists = _require2.flattenedLists; module.exports = { - "names": ["MD032", "blanks-around-lists"], - "description": "Lists should be surrounded by blank lines", - "tags": ["bullet", "ul", "ol", "blank_lines"], - "function": function MD032(params, onError) { - const { lines } = params; - const filteredLists = flattenedLists().filter((list) => !list.nesting); - for (const list of filteredLists) { - const firstIndex = list.open.map[0]; - if (!isBlankLine(lines[firstIndex - 1])) { - const line = lines[firstIndex]; - const quotePrefix = line.match(blockquotePrefixRe)[0].trimEnd(); - addErrorContext(onError, firstIndex + 1, line.trim(), null, null, null, { - "insertText": `${quotePrefix}\n` - }); - } - const lastIndex = list.lastLineIndex - 1; - if (!isBlankLine(lines[lastIndex + 1])) { - const line = lines[lastIndex]; - const quotePrefix = line.match(blockquotePrefixRe)[0].trimEnd(); - addErrorContext(onError, lastIndex + 1, line.trim(), null, null, null, { - "lineNumber": lastIndex + 2, - "insertText": `${quotePrefix}\n` - }); - } - } + "names": ["MD032", "blanks-around-lists"], + "description": "Lists should be surrounded by blank lines", + "tags": ["bullet", "ul", "ol", "blank_lines"], + "function": function MD032(params, onError) { + var lines = params.lines; + var filteredLists = flattenedLists().filter(function (list) { + return !list.nesting; + }); + var _iterator = _createForOfIteratorHelper(filteredLists), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var list = _step.value; + var firstIndex = list.open.map[0]; + if (!isBlankLine(lines[firstIndex - 1])) { + var line = lines[firstIndex]; + var quotePrefix = line.match(blockquotePrefixRe)[0].trimEnd(); + addErrorContext(onError, firstIndex + 1, line.trim(), null, null, null, { + "insertText": "".concat(quotePrefix, "\n") + }); + } + var lastIndex = list.lastLineIndex - 1; + if (!isBlankLine(lines[lastIndex + 1])) { + var _line = lines[lastIndex]; + var _quotePrefix = _line.match(blockquotePrefixRe)[0].trimEnd(); + addErrorContext(onError, lastIndex + 1, _line.trim(), null, null, null, { + "lineNumber": lastIndex + 2, + "insertText": "".concat(_quotePrefix, "\n") + }); + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); } + } }; - /***/ }), /***/ "../lib/md033.js": @@ -3816,55 +4742,97 @@ module.exports = { "use strict"; // @ts-check -const { addError, forEachLine, htmlElementRe, withinAnyRange, unescapeMarkdown } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const { codeBlockAndSpanRanges, lineMetadata, referenceLinkImageData } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); -const linkDestinationRe = /\]\(\s*$/; + + +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } +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."); } +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; } } +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } +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; } } }; } +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); } +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; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addError = _require.addError, + forEachLine = _require.forEachLine, + htmlElementRe = _require.htmlElementRe, + withinAnyRange = _require.withinAnyRange, + unescapeMarkdown = _require.unescapeMarkdown; +var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"), + codeBlockAndSpanRanges = _require2.codeBlockAndSpanRanges, + lineMetadata = _require2.lineMetadata, + referenceLinkImageData = _require2.referenceLinkImageData; +var linkDestinationRe = /\]\(\s*$/; // See https://spec.commonmark.org/0.29/#autolinks -const emailAddressRe = +var emailAddressRe = // eslint-disable-next-line max-len /^[\w.!#$%&'*+/=?^`{|}~-]+@[a-zA-Z\d](?:[a-zA-Z\d-]{0,61}[a-zA-Z\d])?(?:\.[a-zA-Z\d](?:[a-zA-Z\d-]{0,61}[a-zA-Z\d])?)*$/; module.exports = { - "names": ["MD033", "no-inline-html"], - "description": "Inline HTML", - "tags": ["html"], - "function": function MD033(params, onError) { - let allowedElements = params.config.allowed_elements; - allowedElements = Array.isArray(allowedElements) ? allowedElements : []; - allowedElements = allowedElements.map((element) => element.toLowerCase()); - const exclusions = codeBlockAndSpanRanges(); - const { references, definitionLineIndices } = referenceLinkImageData(); - for (const datas of references.values()) { - for (const data of datas) { - const [lineIndex, index, , textLength, labelLength] = data; - if (labelLength > 0) { - exclusions.push([lineIndex, index + 3 + textLength, labelLength]); - } - } - } - forEachLine(lineMetadata(), (line, lineIndex, inCode) => { - let match = null; - // eslint-disable-next-line no-unmodified-loop-condition - while (!inCode && ((match = htmlElementRe.exec(line)) !== null)) { - const [tag, content, element] = match; - if (!allowedElements.includes(element.toLowerCase()) && - !tag.endsWith("\\>") && - !emailAddressRe.test(content) && - !withinAnyRange(exclusions, lineIndex, match.index, tag.length) && - !definitionLineIndices.includes(lineIndex)) { - const prefix = line.substring(0, match.index); - if (!linkDestinationRe.test(prefix)) { - const unescaped = unescapeMarkdown(prefix + "<", "_"); - if (!unescaped.endsWith("_")) { - addError(onError, lineIndex + 1, "Element: " + element, undefined, [match.index + 1, tag.length]); - } - } - } - } - }); + "names": ["MD033", "no-inline-html"], + "description": "Inline HTML", + "tags": ["html"], + "function": function MD033(params, onError) { + var allowedElements = params.config.allowed_elements; + allowedElements = Array.isArray(allowedElements) ? allowedElements : []; + allowedElements = allowedElements.map(function (element) { + return element.toLowerCase(); + }); + var exclusions = codeBlockAndSpanRanges(); + var _referenceLinkImageDa = referenceLinkImageData(), + references = _referenceLinkImageDa.references, + definitionLineIndices = _referenceLinkImageDa.definitionLineIndices; + var _iterator = _createForOfIteratorHelper(references.values()), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var datas = _step.value; + var _iterator2 = _createForOfIteratorHelper(datas), + _step2; + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var data = _step2.value; + var _data = _slicedToArray(data, 5), + lineIndex = _data[0], + index = _data[1], + textLength = _data[3], + labelLength = _data[4]; + if (labelLength > 0) { + exclusions.push([lineIndex, index + 3 + textLength, labelLength]); + } + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); } + forEachLine(lineMetadata(), function (line, lineIndex, inCode) { + var match = null; + // eslint-disable-next-line no-unmodified-loop-condition + while (!inCode && (match = htmlElementRe.exec(line)) !== null) { + var _match = match, + _match2 = _slicedToArray(_match, 3), + tag = _match2[0], + content = _match2[1], + element = _match2[2]; + if (!allowedElements.includes(element.toLowerCase()) && !tag.endsWith("\\>") && !emailAddressRe.test(content) && !withinAnyRange(exclusions, lineIndex, match.index, tag.length) && !definitionLineIndices.includes(lineIndex)) { + var prefix = line.substring(0, match.index); + if (!linkDestinationRe.test(prefix)) { + var unescaped = unescapeMarkdown(prefix + "<", "_"); + if (!unescaped.endsWith("_")) { + addError(onError, lineIndex + 1, "Element: " + element, undefined, [match.index + 1, tag.length]); + } + } + } + } + }); + } }; - /***/ }), /***/ "../lib/md034.js": @@ -3876,74 +4844,98 @@ module.exports = { "use strict"; // @ts-check -const { addErrorContext, filterTokens, funcExpExec, urlFe, withinAnyRange } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const { codeBlockAndSpanRanges, htmlElementRanges, referenceLinkImageData } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); -const htmlLinkRe = /]*)?>[^<>]*<\/a\s*>/gi; + + +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } +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."); } +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; } } +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } +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; } } }; } +function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } +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."); } +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); } +function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } +function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } +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; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorContext = _require.addErrorContext, + filterTokens = _require.filterTokens, + funcExpExec = _require.funcExpExec, + urlFe = _require.urlFe, + withinAnyRange = _require.withinAnyRange; +var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"), + codeBlockAndSpanRanges = _require2.codeBlockAndSpanRanges, + htmlElementRanges = _require2.htmlElementRanges, + referenceLinkImageData = _require2.referenceLinkImageData; +var htmlLinkRe = /]*)?>[^<>]*<\/a\s*>/gi; module.exports = { - "names": ["MD034", "no-bare-urls"], - "description": "Bare URL used", - "tags": ["links", "url"], - "function": function MD034(params, onError) { - const { lines } = params; - const codeExclusions = [ - ...codeBlockAndSpanRanges(), - ...htmlElementRanges() - ]; - filterTokens(params, "html_block", (token) => { - for (let i = token.map[0]; i < token.map[1]; i++) { - codeExclusions.push([i, 0, lines[i].length]); - } - }); - const { definitionLineIndices } = referenceLinkImageData(); - for (const [lineIndex, line] of lines.entries()) { - if (definitionLineIndices[0] === lineIndex) { - definitionLineIndices.shift(); - } - else { - let match = null; - const lineExclusions = []; - while ((match = htmlLinkRe.exec(line)) !== null) { - lineExclusions.push([lineIndex, match.index, match[0].length]); - } - while ((match = funcExpExec(urlFe, line)) !== null) { - const [bareUrl] = match; - // @ts-ignore - const matchIndex = match.index; - const bareUrlLength = bareUrl.length; - const prefix = line.slice(0, matchIndex); - const postfix = line.slice(matchIndex + bareUrlLength); - if ( - // Allow <...> to avoid reporting non-bare links - !(prefix.endsWith("<") && postfix.startsWith(">")) && - // Allow >...... - !(prefix.endsWith(">") && postfix.startsWith("` - }; - addErrorContext(onError, lineIndex + 1, bareUrl, null, null, range, fixInfo); - } - } - } - } + "names": ["MD034", "no-bare-urls"], + "description": "Bare URL used", + "tags": ["links", "url"], + "function": function MD034(params, onError) { + var lines = params.lines; + var codeExclusions = [].concat(_toConsumableArray(codeBlockAndSpanRanges()), _toConsumableArray(htmlElementRanges())); + filterTokens(params, "html_block", function (token) { + for (var i = token.map[0]; i < token.map[1]; i++) { + codeExclusions.push([i, 0, lines[i].length]); + } + }); + var _referenceLinkImageDa = referenceLinkImageData(), + definitionLineIndices = _referenceLinkImageDa.definitionLineIndices; + var _iterator = _createForOfIteratorHelper(lines.entries()), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var _step$value = _slicedToArray(_step.value, 2), + lineIndex = _step$value[0], + line = _step$value[1]; + if (definitionLineIndices[0] === lineIndex) { + definitionLineIndices.shift(); + } else { + var match = null; + var lineExclusions = []; + while ((match = htmlLinkRe.exec(line)) !== null) { + lineExclusions.push([lineIndex, match.index, match[0].length]); + } + while ((match = funcExpExec(urlFe, line)) !== null) { + var _match = match, + _match2 = _slicedToArray(_match, 1), + bareUrl = _match2[0]; + // @ts-ignore + var matchIndex = match.index; + var bareUrlLength = bareUrl.length; + var prefix = line.slice(0, matchIndex); + var postfix = line.slice(matchIndex + bareUrlLength); + if ( + // Allow <...> to avoid reporting non-bare links + !(prefix.endsWith("<") && postfix.startsWith(">")) && + // Allow >...... + !(prefix.endsWith(">") && postfix.startsWith("") + }; + addErrorContext(onError, lineIndex + 1, bareUrl, null, null, range, fixInfo); + } + } + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); } + } }; - /***/ }), /***/ "../lib/md035.js": @@ -3955,29 +4947,33 @@ module.exports = { "use strict"; // @ts-check -const { addErrorDetailIf, filterTokens } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); + + +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorDetailIf = _require.addErrorDetailIf, + filterTokens = _require.filterTokens; module.exports = { - "names": ["MD035", "hr-style"], - "description": "Horizontal rule style", - "tags": ["hr"], - "function": function MD035(params, onError) { - let style = String(params.config.style || "consistent").trim(); - filterTokens(params, "hr", (token) => { - const { line, lineNumber } = token; - let { markup } = token; - const match = line.match(/[_*\-\s]+$/); - if (match) { - markup = match[0].trim(); - } - if (style === "consistent") { - style = markup; - } - addErrorDetailIf(onError, lineNumber, style, markup); - }); - } + "names": ["MD035", "hr-style"], + "description": "Horizontal rule style", + "tags": ["hr"], + "function": function MD035(params, onError) { + var style = String(params.config.style || "consistent").trim(); + filterTokens(params, "hr", function (token) { + var line = token.line, + lineNumber = token.lineNumber; + var markup = token.markup; + var match = line.match(/[_*\-\s]+$/); + if (match) { + markup = match[0].trim(); + } + if (style === "consistent") { + style = markup; + } + addErrorDetailIf(onError, lineNumber, style, markup); + }); + } }; - /***/ }), /***/ "../lib/md036.js": @@ -3989,60 +4985,68 @@ module.exports = { "use strict"; // @ts-check -const { addErrorContext, allPunctuation } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); + + +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; } } }; } +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); } +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; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorContext = _require.addErrorContext, + allPunctuation = _require.allPunctuation; module.exports = { - "names": ["MD036", "no-emphasis-as-heading", "no-emphasis-as-header"], - "description": "Emphasis used instead of a heading", - "tags": ["headings", "headers", "emphasis"], - "function": function MD036(params, onError) { - let punctuation = params.config.punctuation; - punctuation = - String((punctuation === undefined) ? allPunctuation : punctuation); - const re = new RegExp("[" + punctuation + "]$"); - // eslint-disable-next-line jsdoc/require-jsdoc - function base(token) { - if (token.type === "paragraph_open") { - return function inParagraph(t) { - // Always paragraph_open/inline/paragraph_close, - const children = t.children.filter(function notEmptyText(child) { - return (child.type !== "text") || (child.content !== ""); - }); - if ((children.length === 3) && - ((children[0].type === "strong_open") || - (children[0].type === "em_open")) && - (children[1].type === "text") && - !re.test(children[1].content)) { - addErrorContext(onError, t.lineNumber, children[1].content); - } - return base; - }; - } - else if (token.type === "blockquote_open") { - return function inBlockquote(t) { - if (t.type !== "blockquote_close") { - return inBlockquote; - } - return base; - }; - } - else if (token.type === "list_item_open") { - return function inListItem(t) { - if (t.type !== "list_item_close") { - return inListItem; - } - return base; - }; - } - return base; - } - let state = base; - for (const token of params.tokens) { - state = state(token); - } + "names": ["MD036", "no-emphasis-as-heading", "no-emphasis-as-header"], + "description": "Emphasis used instead of a heading", + "tags": ["headings", "headers", "emphasis"], + "function": function MD036(params, onError) { + var punctuation = params.config.punctuation; + punctuation = String(punctuation === undefined ? allPunctuation : punctuation); + var re = new RegExp("[" + punctuation + "]$"); + // eslint-disable-next-line jsdoc/require-jsdoc + function base(token) { + if (token.type === "paragraph_open") { + return function inParagraph(t) { + // Always paragraph_open/inline/paragraph_close, + var children = t.children.filter(function notEmptyText(child) { + return child.type !== "text" || child.content !== ""; + }); + if (children.length === 3 && (children[0].type === "strong_open" || children[0].type === "em_open") && children[1].type === "text" && !re.test(children[1].content)) { + addErrorContext(onError, t.lineNumber, children[1].content); + } + return base; + }; + } else if (token.type === "blockquote_open") { + return function inBlockquote(t) { + if (t.type !== "blockquote_close") { + return inBlockquote; + } + return base; + }; + } else if (token.type === "list_item_open") { + return function inListItem(t) { + if (t.type !== "list_item_close") { + return inListItem; + } + return base; + }; + } + return base; + } + var state = base; + var _iterator = _createForOfIteratorHelper(params.tokens), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var token = _step.value; + state = state(token); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); } + } }; - /***/ }), /***/ "../lib/md037.js": @@ -4054,168 +5058,163 @@ module.exports = { "use strict"; // @ts-check -const { addErrorContext, emphasisMarkersInContent, forEachLine, isBlankLine, withinAnyRange } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const { htmlElementRanges, lineMetadata } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); -const emphasisRe = /(^|[^\\]|\\\\)(?:(\*{1,3})|(_{1,3}))/g; -const embeddedUnderscoreRe = /([A-Za-z\d])_([A-Za-z\d])/g; -const asteriskListItemMarkerRe = /^([\s>]*)\*(\s+)/; -const leftSpaceRe = /^\s+/; -const rightSpaceRe = /\s+$/; -const tablePipeRe = /\|/; + + +function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } +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."); } +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); } +function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } +function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } +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; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorContext = _require.addErrorContext, + emphasisMarkersInContent = _require.emphasisMarkersInContent, + forEachLine = _require.forEachLine, + isBlankLine = _require.isBlankLine, + withinAnyRange = _require.withinAnyRange; +var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"), + htmlElementRanges = _require2.htmlElementRanges, + lineMetadata = _require2.lineMetadata; +var emphasisRe = /(^|[^\\]|\\\\)(?:(\*{1,3})|(_{1,3}))/g; +var embeddedUnderscoreRe = /([A-Za-z\d])_([A-Za-z\d])/g; +var asteriskListItemMarkerRe = /^([\s>]*)\*(\s+)/; +var leftSpaceRe = /^\s+/; +var rightSpaceRe = /\s+$/; +var tablePipeRe = /\|/; module.exports = { - "names": ["MD037", "no-space-in-emphasis"], - "description": "Spaces inside emphasis markers", - "tags": ["whitespace", "emphasis"], - "function": function MD037(params, onError) { - const exclusions = htmlElementRanges(); - // eslint-disable-next-line init-declarations - let effectiveEmphasisLength, emphasisIndex, emphasisKind, emphasisLength, pendingError = null; - // eslint-disable-next-line jsdoc/require-jsdoc - function resetRunTracking() { - emphasisIndex = -1; - emphasisLength = 0; - emphasisKind = ""; - effectiveEmphasisLength = 0; - pendingError = null; - } - // eslint-disable-next-line jsdoc/require-jsdoc - function handleRunEnd(line, lineIndex, contextLength, match, matchIndex, inTable) { - // Close current run - let content = line.substring(emphasisIndex, matchIndex); - if (!emphasisLength) { - content = content.trimStart(); - } - if (!match) { - content = content.trimEnd(); - } - const leftSpace = leftSpaceRe.test(content); - const rightSpace = rightSpaceRe.test(content); - if ((leftSpace || rightSpace) && - (!inTable || !tablePipeRe.test(content))) { - // Report the violation - const contextStart = emphasisIndex - emphasisLength; - const contextEnd = matchIndex + contextLength; - const column = contextStart + 1; - const length = contextEnd - contextStart; - if (!withinAnyRange(exclusions, lineIndex, column, length)) { - const context = line.substring(contextStart, contextEnd); - const leftMarker = line.substring(contextStart, emphasisIndex); - const rightMarker = match ? (match[2] || match[3]) : ""; - const fixedText = `${leftMarker}${content.trim()}${rightMarker}`; - return [ - onError, - lineIndex + 1, - context, - leftSpace, - rightSpace, - [column, length], - { - "editColumn": column, - "deleteCount": length, - "insertText": fixedText - } - ]; - } - } - return null; - } - // Initialize - const ignoreMarkersByLine = emphasisMarkersInContent(params); - resetRunTracking(); - forEachLine(lineMetadata(), (line, lineIndex, inCode, onFence, inTable, inItem, onBreak, inMath) => { - const onItemStart = (inItem === 1); - if (inCode || - onFence || - inTable || - onBreak || - onItemStart || - isBlankLine(line)) { - // Emphasis resets when leaving a block - resetRunTracking(); - } - if (inCode || - onFence || - onBreak || - inMath) { - // Emphasis has no meaning here - return; - } - let patchedLine = line.replace(embeddedUnderscoreRe, "$1 $2"); - if (onItemStart) { - // Trim overlapping '*' list item marker - patchedLine = patchedLine.replace(asteriskListItemMarkerRe, "$1 $2"); - } - let match = null; - // Match all emphasis-looking runs in the line... - while ((match = emphasisRe.exec(patchedLine))) { - const ignoreMarkersForLine = ignoreMarkersByLine[lineIndex]; - const matchIndex = match.index + match[1].length; - if (ignoreMarkersForLine.includes(matchIndex)) { - // Ignore emphasis markers inside code spans and links - continue; - } - const matchLength = match[0].length - match[1].length; - const matchKind = (match[2] || match[3])[0]; - if (emphasisIndex === -1) { - // New run - emphasisIndex = matchIndex + matchLength; - emphasisLength = matchLength; - emphasisKind = matchKind; - effectiveEmphasisLength = matchLength; - } - else if (matchKind === emphasisKind) { - // Matching emphasis markers - if (matchLength === effectiveEmphasisLength) { - // Ending an existing run, report any pending error - if (pendingError) { - // @ts-ignore - addErrorContext(...pendingError); - pendingError = null; - } - const error = handleRunEnd(line, lineIndex, effectiveEmphasisLength, match, matchIndex, inTable); - if (error) { - // @ts-ignore - addErrorContext(...error); - } - // Reset - resetRunTracking(); - } - else if (matchLength === 3) { - // Swap internal run length (1->2 or 2->1) - effectiveEmphasisLength = matchLength - effectiveEmphasisLength; - } - else if (effectiveEmphasisLength === 3) { - // Downgrade internal run (3->1 or 3->2) - effectiveEmphasisLength -= matchLength; - } - else { - // Upgrade to internal run (1->3 or 2->3) - effectiveEmphasisLength += matchLength; - } - // Back up one character so RegExp has a chance to match the - // next marker (ex: "**star**_underscore_") - if (emphasisRe.lastIndex > 1) { - emphasisRe.lastIndex--; - } - } - else if (emphasisRe.lastIndex > 1) { - // Back up one character so RegExp has a chance to match the - // mis-matched marker (ex: "*text_*") - emphasisRe.lastIndex--; - } - } - if (emphasisIndex !== -1) { - pendingError = pendingError || - handleRunEnd(line, lineIndex, 0, null, line.length, inTable); - // Adjust for pending run on new line - emphasisIndex = 0; - emphasisLength = 0; - } - }); + "names": ["MD037", "no-space-in-emphasis"], + "description": "Spaces inside emphasis markers", + "tags": ["whitespace", "emphasis"], + "function": function MD037(params, onError) { + var exclusions = htmlElementRanges(); + // eslint-disable-next-line init-declarations + var effectiveEmphasisLength, + emphasisIndex, + emphasisKind, + emphasisLength, + pendingError = null; + // eslint-disable-next-line jsdoc/require-jsdoc + function resetRunTracking() { + emphasisIndex = -1; + emphasisLength = 0; + emphasisKind = ""; + effectiveEmphasisLength = 0; + pendingError = null; + } + // eslint-disable-next-line jsdoc/require-jsdoc + function handleRunEnd(line, lineIndex, contextLength, match, matchIndex, inTable) { + // Close current run + var content = line.substring(emphasisIndex, matchIndex); + if (!emphasisLength) { + content = content.trimStart(); + } + if (!match) { + content = content.trimEnd(); + } + var leftSpace = leftSpaceRe.test(content); + var rightSpace = rightSpaceRe.test(content); + if ((leftSpace || rightSpace) && (!inTable || !tablePipeRe.test(content))) { + // Report the violation + var contextStart = emphasisIndex - emphasisLength; + var contextEnd = matchIndex + contextLength; + var column = contextStart + 1; + var length = contextEnd - contextStart; + if (!withinAnyRange(exclusions, lineIndex, column, length)) { + var context = line.substring(contextStart, contextEnd); + var leftMarker = line.substring(contextStart, emphasisIndex); + var rightMarker = match ? match[2] || match[3] : ""; + var fixedText = "".concat(leftMarker).concat(content.trim()).concat(rightMarker); + return [onError, lineIndex + 1, context, leftSpace, rightSpace, [column, length], { + "editColumn": column, + "deleteCount": length, + "insertText": fixedText + }]; + } + } + return null; } + // Initialize + var ignoreMarkersByLine = emphasisMarkersInContent(params); + resetRunTracking(); + forEachLine(lineMetadata(), function (line, lineIndex, inCode, onFence, inTable, inItem, onBreak, inMath) { + var onItemStart = inItem === 1; + if (inCode || onFence || inTable || onBreak || onItemStart || isBlankLine(line)) { + // Emphasis resets when leaving a block + resetRunTracking(); + } + if (inCode || onFence || onBreak || inMath) { + // Emphasis has no meaning here + return; + } + var patchedLine = line.replace(embeddedUnderscoreRe, "$1 $2"); + if (onItemStart) { + // Trim overlapping '*' list item marker + patchedLine = patchedLine.replace(asteriskListItemMarkerRe, "$1 $2"); + } + var match = null; + // Match all emphasis-looking runs in the line... + while (match = emphasisRe.exec(patchedLine)) { + var ignoreMarkersForLine = ignoreMarkersByLine[lineIndex]; + var matchIndex = match.index + match[1].length; + if (ignoreMarkersForLine.includes(matchIndex)) { + // Ignore emphasis markers inside code spans and links + continue; + } + var matchLength = match[0].length - match[1].length; + var matchKind = (match[2] || match[3])[0]; + if (emphasisIndex === -1) { + // New run + emphasisIndex = matchIndex + matchLength; + emphasisLength = matchLength; + emphasisKind = matchKind; + effectiveEmphasisLength = matchLength; + } else if (matchKind === emphasisKind) { + // Matching emphasis markers + if (matchLength === effectiveEmphasisLength) { + // Ending an existing run, report any pending error + if (pendingError) { + // @ts-ignore + addErrorContext.apply(void 0, _toConsumableArray(pendingError)); + pendingError = null; + } + var error = handleRunEnd(line, lineIndex, effectiveEmphasisLength, match, matchIndex, inTable); + if (error) { + // @ts-ignore + addErrorContext.apply(void 0, _toConsumableArray(error)); + } + // Reset + resetRunTracking(); + } else if (matchLength === 3) { + // Swap internal run length (1->2 or 2->1) + effectiveEmphasisLength = matchLength - effectiveEmphasisLength; + } else if (effectiveEmphasisLength === 3) { + // Downgrade internal run (3->1 or 3->2) + effectiveEmphasisLength -= matchLength; + } else { + // Upgrade to internal run (1->3 or 2->3) + effectiveEmphasisLength += matchLength; + } + // Back up one character so RegExp has a chance to match the + // next marker (ex: "**star**_underscore_") + if (emphasisRe.lastIndex > 1) { + emphasisRe.lastIndex--; + } + } else if (emphasisRe.lastIndex > 1) { + // Back up one character so RegExp has a chance to match the + // mis-matched marker (ex: "*text_*") + emphasisRe.lastIndex--; + } + } + if (emphasisIndex !== -1) { + pendingError = pendingError || handleRunEnd(line, lineIndex, 0, null, line.length, inTable); + // Adjust for pending run on new line + emphasisIndex = 0; + emphasisLength = 0; + } + }); + } }; - /***/ }), /***/ "../lib/md038.js": @@ -4227,58 +5226,61 @@ module.exports = { "use strict"; // @ts-check -const { addErrorContext, filterTokens, forEachInlineCodeSpan, newLineRe } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const leftSpaceRe = /^\s(?:[^`]|$)/; -const rightSpaceRe = /[^`]\s$/; -const spaceInsideCodeInline = (token) => ((token.type === "code_inline") && - (leftSpaceRe.test(token.content) || rightSpaceRe.test(token.content))); + + +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorContext = _require.addErrorContext, + filterTokens = _require.filterTokens, + forEachInlineCodeSpan = _require.forEachInlineCodeSpan, + newLineRe = _require.newLineRe; +var leftSpaceRe = /^\s(?:[^`]|$)/; +var rightSpaceRe = /[^`]\s$/; +var spaceInsideCodeInline = function spaceInsideCodeInline(token) { + return token.type === "code_inline" && (leftSpaceRe.test(token.content) || rightSpaceRe.test(token.content)); +}; module.exports = { - "names": ["MD038", "no-space-in-code"], - "description": "Spaces inside code span elements", - "tags": ["whitespace", "code"], - "function": function MD038(params, onError) { - filterTokens(params, "inline", (token) => { - if (token.children.some(spaceInsideCodeInline)) { - const tokenLines = params.lines.slice(token.map[0], token.map[1]); - forEachInlineCodeSpan(tokenLines.join("\n"), (code, lineIndex, columnIndex, tickCount) => { - let rangeIndex = columnIndex - tickCount; - let rangeLength = code.length + (2 * tickCount); - let rangeLineOffset = 0; - let fixIndex = columnIndex; - let fixLength = code.length; - const codeLines = code.split(newLineRe); - const left = leftSpaceRe.test(code); - const right = !left && rightSpaceRe.test(code); - if (right && (codeLines.length > 1)) { - rangeIndex = 0; - rangeLineOffset = codeLines.length - 1; - fixIndex = 0; - } - if (left || right) { - const codeLinesRange = codeLines[rangeLineOffset]; - if (codeLines.length > 1) { - rangeLength = codeLinesRange.length + tickCount; - fixLength = codeLinesRange.length; - } - const context = tokenLines[lineIndex + rangeLineOffset] - .substring(rangeIndex, rangeIndex + rangeLength); - const codeLinesRangeTrim = codeLinesRange.trim(); - const fixText = (codeLinesRangeTrim.startsWith("`") ? " " : "") + - codeLinesRangeTrim + - (codeLinesRangeTrim.endsWith("`") ? " " : ""); - addErrorContext(onError, token.lineNumber + lineIndex + rangeLineOffset, context, left, right, [rangeIndex + 1, rangeLength], { - "editColumn": fixIndex + 1, - "deleteCount": fixLength, - "insertText": fixText - }); - } - }); - } + "names": ["MD038", "no-space-in-code"], + "description": "Spaces inside code span elements", + "tags": ["whitespace", "code"], + "function": function MD038(params, onError) { + filterTokens(params, "inline", function (token) { + if (token.children.some(spaceInsideCodeInline)) { + var tokenLines = params.lines.slice(token.map[0], token.map[1]); + forEachInlineCodeSpan(tokenLines.join("\n"), function (code, lineIndex, columnIndex, tickCount) { + var rangeIndex = columnIndex - tickCount; + var rangeLength = code.length + 2 * tickCount; + var rangeLineOffset = 0; + var fixIndex = columnIndex; + var fixLength = code.length; + var codeLines = code.split(newLineRe); + var left = leftSpaceRe.test(code); + var right = !left && rightSpaceRe.test(code); + if (right && codeLines.length > 1) { + rangeIndex = 0; + rangeLineOffset = codeLines.length - 1; + fixIndex = 0; + } + if (left || right) { + var codeLinesRange = codeLines[rangeLineOffset]; + if (codeLines.length > 1) { + rangeLength = codeLinesRange.length + tickCount; + fixLength = codeLinesRange.length; + } + var context = tokenLines[lineIndex + rangeLineOffset].substring(rangeIndex, rangeIndex + rangeLength); + var codeLinesRangeTrim = codeLinesRange.trim(); + var fixText = (codeLinesRangeTrim.startsWith("`") ? " " : "") + codeLinesRangeTrim + (codeLinesRangeTrim.endsWith("`") ? " " : ""); + addErrorContext(onError, token.lineNumber + lineIndex + rangeLineOffset, context, left, right, [rangeIndex + 1, rangeLength], { + "editColumn": fixIndex + 1, + "deleteCount": fixLength, + "insertText": fixText + }); + } }); - } + } + }); + } }; - /***/ }), /***/ "../lib/md039.js": @@ -4290,63 +5292,75 @@ module.exports = { "use strict"; // @ts-check -const { addErrorContext, filterTokens } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); -const spaceInLinkRe = /\[(?:\s[^\]]*|[^\]]*?\s)\](?=(\([^)]*\)|\[[^\]]*\]))/; + + +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; } } }; } +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); } +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; } +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorContext = _require.addErrorContext, + filterTokens = _require.filterTokens; +var spaceInLinkRe = /\[(?:\s[^\]]*|[^\]]*?\s)\](?=(\([^)]*\)|\[[^\]]*\]))/; module.exports = { - "names": ["MD039", "no-space-in-links"], - "description": "Spaces inside link text", - "tags": ["whitespace", "links"], - "function": function MD039(params, onError) { - filterTokens(params, "inline", (token) => { - const { children } = token; - let { lineNumber } = token; - let inLink = false; - let linkText = ""; - let lineIndex = 0; - for (const child of children) { - const { content, markup, type } = child; - if (type === "link_open") { - inLink = true; - linkText = ""; - } - else if (type === "link_close") { - inLink = false; - const left = linkText.trimStart().length !== linkText.length; - const right = linkText.trimEnd().length !== linkText.length; - if (left || right) { - const line = params.lines[lineNumber - 1]; - let range = null; - let fixInfo = null; - const match = line.slice(lineIndex).match(spaceInLinkRe); - if (match) { - const column = match.index + lineIndex + 1; - const length = match[0].length; - range = [column, length]; - fixInfo = { - "editColumn": column + 1, - "deleteCount": length - 2, - "insertText": linkText.trim() - }; - lineIndex = column + length - 1; - } - addErrorContext(onError, lineNumber, `[${linkText}]`, left, right, range, fixInfo); - } - } - else if ((type === "softbreak") || (type === "hardbreak")) { - lineNumber++; - lineIndex = 0; - } - else if (inLink) { - linkText += type.endsWith("_inline") ? - `${markup}${content}${markup}` : - (content || markup); - } - } - }); - } + "names": ["MD039", "no-space-in-links"], + "description": "Spaces inside link text", + "tags": ["whitespace", "links"], + "function": function MD039(params, onError) { + filterTokens(params, "inline", function (token) { + var children = token.children; + var lineNumber = token.lineNumber; + var inLink = false; + var linkText = ""; + var lineIndex = 0; + var _iterator = _createForOfIteratorHelper(children), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var child = _step.value; + var content = child.content, + markup = child.markup, + type = child.type; + if (type === "link_open") { + inLink = true; + linkText = ""; + } else if (type === "link_close") { + inLink = false; + var left = linkText.trimStart().length !== linkText.length; + var right = linkText.trimEnd().length !== linkText.length; + if (left || right) { + var line = params.lines[lineNumber - 1]; + var range = null; + var fixInfo = null; + var match = line.slice(lineIndex).match(spaceInLinkRe); + if (match) { + var column = match.index + lineIndex + 1; + var length = match[0].length; + range = [column, length]; + fixInfo = { + "editColumn": column + 1, + "deleteCount": length - 2, + "insertText": linkText.trim() + }; + lineIndex = column + length - 1; + } + addErrorContext(onError, lineNumber, "[".concat(linkText, "]"), left, right, range, fixInfo); + } + } else if (type === "softbreak" || type === "hardbreak") { + lineNumber++; + lineIndex = 0; + } else if (inLink) { + linkText += type.endsWith("_inline") ? "".concat(markup).concat(content).concat(markup) : content || markup; + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + }); + } }; - /***/ }), /***/ "../lib/md040.js": @@ -4358,31 +5372,34 @@ module.exports = { "use strict"; // @ts-check -const { addError, addErrorContext, filterTokens } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); + + +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addError = _require.addError, + addErrorContext = _require.addErrorContext, + filterTokens = _require.filterTokens; module.exports = { - "names": ["MD040", "fenced-code-language"], - "description": "Fenced code blocks should have a language specified", - "tags": ["code", "language"], - "function": function MD040(params, onError) { - let allowed = params.config.allowed_languages; - allowed = Array.isArray(allowed) ? allowed : []; - const languageOnly = !!params.config.language_only; - filterTokens(params, "fence", function forToken(token) { - const lang = token.info.trim().split(/\s+/u).shift(); - if (lang === "") { - addErrorContext(onError, token.lineNumber, token.line); - } - else if ((allowed.length > 0) && !allowed.includes(lang)) { - addError(onError, token.lineNumber, `"${lang}" is not allowed`); - } - if (languageOnly && (token.info !== lang)) { - addError(onError, token.lineNumber, `Info string contains more than language: "${token.info}"`); - } - }); - } + "names": ["MD040", "fenced-code-language"], + "description": "Fenced code blocks should have a language specified", + "tags": ["code", "language"], + "function": function MD040(params, onError) { + var allowed = params.config.allowed_languages; + allowed = Array.isArray(allowed) ? allowed : []; + var languageOnly = !!params.config.language_only; + filterTokens(params, "fence", function forToken(token) { + var lang = token.info.trim().split(/[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]+/).shift(); + if (lang === "") { + addErrorContext(onError, token.lineNumber, token.line); + } else if (allowed.length > 0 && !allowed.includes(lang)) { + addError(onError, token.lineNumber, "\"".concat(lang, "\" is not allowed")); + } + if (languageOnly && token.info !== lang) { + addError(onError, token.lineNumber, "Info string contains more than language: \"".concat(token.info, "\"")); + } + }); + } }; - /***/ }), /***/ "../lib/md041.js": @@ -4394,43 +5411,44 @@ module.exports = { "use strict"; // @ts-check -const { addErrorContext, frontMatterHasTitle } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"); + + +var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), + addErrorContext = _require.addErrorContext, + frontMatterHasTitle = _require.frontMatterHasTitle; module.exports = { - "names": ["MD041", "first-line-heading", "first-line-h1"], - "description": "First line in a file should be a top-level heading", - "tags": ["headings", "headers"], - "function": function MD041(params, onError) { - const level = Number(params.config.level || 1); - const tag = "h" + level; - const foundFrontMatterTitle = frontMatterHasTitle(params.frontMatterLines, params.config.front_matter_title); - if (!foundFrontMatterTitle) { - const htmlHeadingRe = new RegExp(`^]`, "i"); - params.tokens.every((token) => { - let isError = false; - if (token.type === "html_block") { - if (token.content.startsWith("