Update to version 0.20.2.

This commit is contained in:
David Anson 2020-04-25 21:15:13 -07:00
parent dcf566e49e
commit 00c1e28f48
4 changed files with 134 additions and 84 deletions

View file

@ -861,6 +861,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for more information.
improve MD005/MD007/MD013/MD018/MD029/MD031/MD034/MD037/MD038/MD039, improve HTML improve MD005/MD007/MD013/MD018/MD029/MD031/MD034/MD037/MD038/MD039, improve HTML
comment handling, update dependencies. comment handling, update dependencies.
* 0.20.1 - Fix regression in MD037. * 0.20.1 - Fix regression in MD037.
* 0.20.2 - Fix regression in MD037, improve MD038.
[npm-image]: https://img.shields.io/npm/v/markdownlint.svg [npm-image]: https://img.shields.io/npm/v/markdownlint.svg
[npm-url]: https://www.npmjs.com/package/markdownlint [npm-url]: https://www.npmjs.com/package/markdownlint

View file

@ -36,6 +36,8 @@ module.exports.inlineCommentRe = inlineCommentRe;
module.exports.bareUrlRe = /(?:http|ftp)s?:\/\/[^\s\]"']*/ig; module.exports.bareUrlRe = /(?:http|ftp)s?:\/\/[^\s\]"']*/ig;
module.exports.listItemMarkerRe = /^([\s>]*)(?:[*+-]|\d+[.)])\s+/; module.exports.listItemMarkerRe = /^([\s>]*)(?:[*+-]|\d+[.)])\s+/;
module.exports.orderedListItemMarkerRe = /^[\s>]*0*(\d+)[.)]/; module.exports.orderedListItemMarkerRe = /^[\s>]*0*(\d+)[.)]/;
// Regular expression for emphasis markers
var emphasisMarkersRe = /[_*]+/g;
// readFile options for reading with the UTF-8 encoding // readFile options for reading with the UTF-8 encoding
module.exports.utf8Encoding = { "encoding": "utf8" }; module.exports.utf8Encoding = { "encoding": "utf8" };
// All punctuation characters (normal and full-width) // All punctuation characters (normal and full-width)
@ -328,88 +330,94 @@ module.exports.forEachHeading = function forEachHeading(params, handler) {
} }
}); });
}; };
// Calls the provided function for each inline code span's content /**
module.exports.forEachInlineCodeSpan = * Calls the provided function for each inline code span's content.
function forEachInlineCodeSpan(input, handler) { *
var currentLine = 0; * @param {string} input Markdown content.
var currentColumn = 0; * @param {Function} handler Callback function.
var index = 0; * @returns {void}
while (index < input.length) { */
var startIndex = -1; function forEachInlineCodeSpan(input, handler) {
var startLine = -1; var currentLine = 0;
var startColumn = -1; var currentColumn = 0;
var tickCount = 0; var index = 0;
var currentTicks = 0; while (index < input.length) {
var state = "normal"; var startIndex = -1;
// Deliberate <= so trailing 0 completes the last span (ex: "text `code`") var startLine = -1;
for (; index <= input.length; index++) { var startColumn = -1;
var char = input[index]; var tickCount = 0;
// Ignore backticks in link destination var currentTicks = 0;
if ((char === "[") && (state === "normal")) { var state = "normal";
state = "linkTextOpen"; // Deliberate <= so trailing 0 completes the last span (ex: "text `code`")
} for (; index <= input.length; index++) {
else if ((char === "]") && (state === "linkTextOpen")) { var char = input[index];
state = "linkTextClosed"; // Ignore backticks in link destination
} if ((char === "[") && (state === "normal")) {
else if ((char === "(") && (state === "linkTextClosed")) { state = "linkTextOpen";
state = "linkDestinationOpen"; }
} else if ((char === "]") && (state === "linkTextOpen")) {
else if (((char === "(") && (state === "linkDestinationOpen")) || state = "linkTextClosed";
((char === ")") && (state === "linkDestinationOpen")) || }
(state === "linkTextClosed")) { else if ((char === "(") && (state === "linkTextClosed")) {
state = "normal"; state = "linkDestinationOpen";
} }
// Parse backtick open/close else if (((char === "(") && (state === "linkDestinationOpen")) ||
if ((char === "`") && (state !== "linkDestinationOpen")) { ((char === ")") && (state === "linkDestinationOpen")) ||
// Count backticks at start or end of code span (state === "linkTextClosed")) {
currentTicks++; state = "normal";
if ((startIndex === -1) || (startColumn === -1)) { }
startIndex = index + 1; // Parse backtick open/close
} if ((char === "`") && (state !== "linkDestinationOpen")) {
} // Count backticks at start or end of code span
else { currentTicks++;
if ((startIndex >= 0) && if ((startIndex === -1) || (startColumn === -1)) {
(startColumn >= 0) && startIndex = index + 1;
(tickCount === currentTicks)) {
// Found end backticks; invoke callback for code span
handler(input.substring(startIndex, index - currentTicks), startLine, startColumn, tickCount);
startIndex = -1;
startColumn = -1;
}
else if ((startIndex >= 0) && (startColumn === -1)) {
// Found start backticks
tickCount = currentTicks;
startLine = currentLine;
startColumn = currentColumn;
}
// Not in backticks
currentTicks = 0;
}
if (char === "\n") {
// On next line
currentLine++;
currentColumn = 0;
}
else if ((char === "\\") &&
((startIndex === -1) || (startColumn === -1)) &&
(input[index + 1] !== "\n")) {
// Escape character outside code, skip next
index++;
currentColumn += 2;
}
else {
// On next column
currentColumn++;
} }
} }
if (startIndex >= 0) { else {
// Restart loop after unmatched start backticks (ex: "`text``code``") if ((startIndex >= 0) &&
index = startIndex; (startColumn >= 0) &&
currentLine = startLine; (tickCount === currentTicks)) {
currentColumn = startColumn; // Found end backticks; invoke callback for code span
handler(input.substring(startIndex, index - currentTicks), startLine, startColumn, tickCount);
startIndex = -1;
startColumn = -1;
}
else if ((startIndex >= 0) && (startColumn === -1)) {
// Found start backticks
tickCount = currentTicks;
startLine = currentLine;
startColumn = currentColumn;
}
// Not in backticks
currentTicks = 0;
}
if (char === "\n") {
// On next line
currentLine++;
currentColumn = 0;
}
else if ((char === "\\") &&
((startIndex === -1) || (startColumn === -1)) &&
(input[index + 1] !== "\n")) {
// Escape character outside code, skip next
index++;
currentColumn += 2;
}
else {
// On next column
currentColumn++;
} }
} }
}; if (startIndex >= 0) {
// Restart loop after unmatched start backticks (ex: "`text``code``")
index = startIndex;
currentLine = startLine;
currentColumn = startColumn;
}
}
}
module.exports.forEachInlineCodeSpan = forEachInlineCodeSpan;
/** /**
* Adds a generic error object via the onError callback. * Adds a generic error object via the onError callback.
* *
@ -473,6 +481,37 @@ module.exports.frontMatterHasTitle =
return !ignoreFrontMatter && return !ignoreFrontMatter &&
frontMatterLines.some(function (line) { return frontMatterTitleRe.test(line); }); frontMatterLines.some(function (line) { return frontMatterTitleRe.test(line); });
}; };
/**
* Returns a list of emphasis markers in code spans.
*
* @param {Object} params RuleParams instance.
* @returns {number[][]} List of markers.
*/
function emphasisMarkersInCodeSpans(params) {
var lines = params.lines;
var byLine = new Array(lines.length);
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);
codeLines.forEach(function (codeLine, codeLineIndex) {
var match = null;
while ((match = emphasisMarkersRe.exec(codeLine))) {
var byLineIndex = lineNumber - 1 + lineIndex + codeLineIndex;
var inLine = byLine[byLineIndex] || [];
var codeLineOffset = codeLineIndex ? 0 : column - 1 + tickCount;
inLine.push(codeLineOffset + match.index);
byLine[byLineIndex] = inLine;
}
});
});
}
});
return byLine;
}
module.exports.emphasisMarkersInCodeSpans = emphasisMarkersInCodeSpans;
/** /**
* Gets the most common line ending, falling back to the platform default. * Gets the most common line ending, falling back to the platform default.
* *
@ -2702,7 +2741,7 @@ module.exports = {
},{"../helpers":2}],37:[function(require,module,exports){ },{"../helpers":2}],37:[function(require,module,exports){
// @ts-check // @ts-check
"use strict"; "use strict";
var _a = require("../helpers"), addErrorContext = _a.addErrorContext, forEachLine = _a.forEachLine, isBlankLine = _a.isBlankLine; var _a = require("../helpers"), addErrorContext = _a.addErrorContext, emphasisMarkersInCodeSpans = _a.emphasisMarkersInCodeSpans, forEachLine = _a.forEachLine, includesSorted = _a.includesSorted, isBlankLine = _a.isBlankLine;
var lineMetadata = require("./cache").lineMetadata; var lineMetadata = require("./cache").lineMetadata;
var emphasisRe = /(^|[^\\])(?:(\*\*?\*?)|(__?_?))/g; var emphasisRe = /(^|[^\\])(?:(\*\*?\*?)|(__?_?))/g;
var asteriskListItemMarkerRe = /^(\s*)\*(\s+)/; var asteriskListItemMarkerRe = /^(\s*)\*(\s+)/;
@ -2714,11 +2753,12 @@ module.exports = {
"tags": ["whitespace", "emphasis"], "tags": ["whitespace", "emphasis"],
"function": function MD037(params, onError) { "function": function MD037(params, onError) {
// eslint-disable-next-line init-declarations // eslint-disable-next-line init-declarations
var effectiveEmphasisLength, emphasisIndex, emphasisLength, pendingError; var effectiveEmphasisLength, emphasisIndex, emphasisKind, emphasisLength, pendingError = null;
// eslint-disable-next-line jsdoc/require-jsdoc // eslint-disable-next-line jsdoc/require-jsdoc
function resetRunTracking() { function resetRunTracking() {
emphasisIndex = -1; emphasisIndex = -1;
emphasisLength = 0; emphasisLength = 0;
emphasisKind = "";
effectiveEmphasisLength = 0; effectiveEmphasisLength = 0;
pendingError = null; pendingError = null;
} }
@ -2761,6 +2801,7 @@ module.exports = {
return null; return null;
} }
// Initialize // Initialize
var ignoreMarkersByLine = emphasisMarkersInCodeSpans(params);
resetRunTracking(); resetRunTracking();
forEachLine(lineMetadata(), function (line, lineIndex, inCode, onFence, inTable, inItem, onBreak) { forEachLine(lineMetadata(), function (line, lineIndex, inCode, onFence, inTable, inItem, onBreak) {
var onItemStart = (inItem === 1); var onItemStart = (inItem === 1);
@ -2779,15 +2820,23 @@ module.exports = {
var match = null; var match = null;
// Match all emphasis-looking runs in the line... // Match all emphasis-looking runs in the line...
while ((match = emphasisRe.exec(line))) { while ((match = emphasisRe.exec(line))) {
var ignoreMarkersForLine = ignoreMarkersByLine[lineIndex] || [];
var matchIndex = match.index + match[1].length; var matchIndex = match.index + match[1].length;
if (includesSorted(ignoreMarkersForLine, matchIndex)) {
// Ignore emphasis markers inside code spans
continue;
}
var matchLength = match[0].length - match[1].length; var matchLength = match[0].length - match[1].length;
var matchKind = (match[2] || match[3])[0];
if (emphasisIndex === -1) { if (emphasisIndex === -1) {
// New run // New run
emphasisIndex = matchIndex + matchLength; emphasisIndex = matchIndex + matchLength;
emphasisLength = matchLength; emphasisLength = matchLength;
emphasisKind = matchKind;
effectiveEmphasisLength = matchLength; effectiveEmphasisLength = matchLength;
} }
else if (matchLength === effectiveEmphasisLength) { else if ((matchLength === effectiveEmphasisLength) &&
(matchKind === emphasisKind)) {
// Ending an existing run, report any pending error // Ending an existing run, report any pending error
if (pendingError) { if (pendingError) {
addErrorContext.apply(void 0, pendingError); addErrorContext.apply(void 0, pendingError);
@ -2830,7 +2879,7 @@ module.exports = {
var _a = require("../helpers"), addErrorContext = _a.addErrorContext, filterTokens = _a.filterTokens, forEachInlineCodeSpan = _a.forEachInlineCodeSpan, newLineRe = _a.newLineRe; var _a = require("../helpers"), addErrorContext = _a.addErrorContext, filterTokens = _a.filterTokens, forEachInlineCodeSpan = _a.forEachInlineCodeSpan, newLineRe = _a.newLineRe;
var leftSpaceRe = /^\s([^`]|$)/; var leftSpaceRe = /^\s([^`]|$)/;
var rightSpaceRe = /[^`]\s$/; var rightSpaceRe = /[^`]\s$/;
var singleLeftRightSpaceRe = /^\s\S+\s$/; var singleLeftRightSpaceRe = /^\s(?:\S.*\S|\S)\s$/;
module.exports = { module.exports = {
"names": ["MD038", "no-space-in-code"], "names": ["MD038", "no-space-in-code"],
"description": "Spaces inside code span elements", "description": "Spaces inside code span elements",

View file

@ -1,6 +1,6 @@
{ {
"name": "markdownlint-rule-helpers", "name": "markdownlint-rule-helpers",
"version": "0.8.0", "version": "0.9.0",
"description": "A collection of markdownlint helper functions for custom rules", "description": "A collection of markdownlint helper functions for custom rules",
"main": "helpers.js", "main": "helpers.js",
"author": "David Anson (https://dlaa.me/)", "author": "David Anson (https://dlaa.me/)",

View file

@ -1,6 +1,6 @@
{ {
"name": "markdownlint", "name": "markdownlint",
"version": "0.20.1", "version": "0.20.2",
"description": "A Node.js style checker and lint tool for Markdown/CommonMark files.", "description": "A Node.js style checker and lint tool for Markdown/CommonMark files.",
"main": "lib/markdownlint.js", "main": "lib/markdownlint.js",
"types": "lib/markdownlint.d.ts", "types": "lib/markdownlint.d.ts",