markdownlint-rule-helpers
Advanced tools
Comparing version 0.14.0 to 0.15.0
@@ -32,6 +32,7 @@ // @ts-check | ||
// Regular expression for inline links and shortcut reference links | ||
const linkRe = /\[(?:[^[\]]|\[[^\]]*\])*\](?:\(\S*\))?/g; | ||
const linkRe = /(\[(?:[^[\]]|\[[^\]]*\])*\])(\(\S*\)|\[\S*\])?/g; | ||
module.exports.linkRe = linkRe; | ||
// readFile options for reading with the UTF-8 encoding | ||
module.exports.utf8Encoding = "utf8"; | ||
// Regular expression for link reference definition lines | ||
module.exports.linkReferenceRe = /^ {0,3}\[[^\]]+]:\s.*$/; | ||
@@ -306,3 +307,3 @@ // All punctuation characters (normal and full-width) | ||
// Returns (nested) lists as a flat array (in order) | ||
module.exports.flattenLists = function flattenLists(params) { | ||
module.exports.flattenLists = function flattenLists(tokens) { | ||
const flattenedLists = []; | ||
@@ -314,3 +315,3 @@ const stack = []; | ||
let lastWithMap = { "map": [ 0, 1 ] }; | ||
params.tokens.forEach((token) => { | ||
tokens.forEach((token) => { | ||
if (isMathBlock(token) && token.map[1]) { | ||
@@ -525,2 +526,43 @@ // markdown-it-texmath plugin does not account for math_block_end | ||
/** | ||
* Returns an array of code span ranges. | ||
* | ||
* @param {string[]} lines Lines to scan for code span ranges. | ||
* @returns {number[][]} Array of ranges (line, index, length). | ||
*/ | ||
module.exports.inlineCodeSpanRanges = (lines) => { | ||
const exclusions = []; | ||
forEachInlineCodeSpan( | ||
lines.join("\n"), | ||
(code, lineIndex, columnIndex) => { | ||
const codeLines = code.split(newLineRe); | ||
// eslint-disable-next-line unicorn/no-for-loop | ||
for (let i = 0; i < codeLines.length; i++) { | ||
exclusions.push( | ||
[ lineIndex + i, columnIndex, codeLines[i].length ] | ||
); | ||
columnIndex = 0; | ||
} | ||
} | ||
); | ||
return exclusions; | ||
}; | ||
/** | ||
* Determines whether the specified range overlaps another range. | ||
* | ||
* @param {number[][]} ranges Array of ranges (line, index, length). | ||
* @param {number} lineIndex Line index to check. | ||
* @param {number} index Index to check. | ||
* @param {number} length Length to check. | ||
* @returns {boolean} True iff the specified range overlaps. | ||
*/ | ||
module.exports.overlapsAnyRange = (ranges, lineIndex, index, length) => ( | ||
!ranges.every((span) => ( | ||
(lineIndex !== span[0]) || | ||
(index + length < span[1]) || | ||
(index > span[1] + span[2]) | ||
)) | ||
); | ||
// Returns a range object for a line by applying a RegExp | ||
@@ -527,0 +569,0 @@ module.exports.rangeFromRegExp = function rangeFromRegExp(line, regexp) { |
{ | ||
"name": "markdownlint-rule-helpers", | ||
"version": "0.14.0", | ||
"version": "0.15.0", | ||
"description": "A collection of markdownlint helper functions for custom rules", | ||
@@ -5,0 +5,0 @@ "main": "helpers.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28396
734