mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 22:40:13 +01:00
Refactor to remove codeBlockAndSpanRanges helper.
This commit is contained in:
parent
c5f4a93cc7
commit
7efc2605b1
7 changed files with 96 additions and 128 deletions
|
|
@ -333,6 +333,31 @@ function getDescendantsByType(parent, typePath) {
|
|||
return tokens;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @typedef {readonly string[]} ReadonlyStringArray */
|
||||
|
||||
/**
|
||||
* Gets the line/column/length exclusions for a Micromark token.
|
||||
*
|
||||
* @param {ReadonlyStringArray} lines File/string lines.
|
||||
* @param {Token} token Micromark token.
|
||||
* @returns {number[][]} Exclusions (line number, start column, length).
|
||||
*/
|
||||
function getExclusionsForToken(lines, token) {
|
||||
const exclusions = [];
|
||||
const { endColumn, endLine, startColumn, startLine } = token;
|
||||
for (let lineNumber = startLine; lineNumber <= endLine; lineNumber++) {
|
||||
const start = (lineNumber === startLine) ? startColumn : 1;
|
||||
const end = (lineNumber === endLine) ? endColumn : lines[lineNumber - 1].length;
|
||||
exclusions.push([
|
||||
lineNumber,
|
||||
start,
|
||||
end - start + 1
|
||||
]);
|
||||
}
|
||||
return exclusions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the heading level of a Micromark heading tokan.
|
||||
*
|
||||
|
|
@ -503,6 +528,7 @@ module.exports = {
|
|||
filterByPredicate,
|
||||
filterByTypes,
|
||||
getDescendantsByType,
|
||||
getExclusionsForToken,
|
||||
getHeadingLevel,
|
||||
getHeadingStyle,
|
||||
getHeadingText,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue