mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
Reimplement MD013/line-length using micromark tokens.
This commit is contained in:
parent
4072cf7417
commit
3b581a7f6d
10 changed files with 173 additions and 185 deletions
|
|
@ -169,24 +169,6 @@ function isBlankLine(line) {
|
|||
}
|
||||
module.exports.isBlankLine = isBlankLine;
|
||||
|
||||
// Returns true iff the sorted array contains the specified element
|
||||
module.exports.includesSorted = function includesSorted(array, element) {
|
||||
let left = 0;
|
||||
let right = array.length - 1;
|
||||
while (left <= right) {
|
||||
// eslint-disable-next-line no-bitwise
|
||||
const mid = (left + right) >> 1;
|
||||
if (array[mid] < element) {
|
||||
left = mid + 1;
|
||||
} else if (array[mid] > element) {
|
||||
right = mid - 1;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
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
|
||||
|
|
@ -460,20 +442,6 @@ module.exports.flattenLists = function flattenLists(tokens) {
|
|||
return flattenedLists;
|
||||
};
|
||||
|
||||
// Calls the provided function for each heading's content
|
||||
module.exports.forEachHeading = function forEachHeading(params, handler) {
|
||||
let heading = null;
|
||||
for (const token of params.parsers.markdownit.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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @callback InlineCodeSpanCallback
|
||||
* @param {string} code Code content.
|
||||
|
|
|
|||
|
|
@ -231,6 +231,20 @@ function micromarkParse(
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a range of numbers to a set.
|
||||
*
|
||||
* @param {Set<number>} set Set of numbers.
|
||||
* @param {number} start Starting number.
|
||||
* @param {number} end Ending number.
|
||||
* @returns {void}
|
||||
*/
|
||||
function addRangeToSet(set, start, end) {
|
||||
for (let i = start; i <= end; i++) {
|
||||
set.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @callback AllowedPredicate
|
||||
* @param {Token} token Micromark token.
|
||||
|
|
@ -485,6 +499,7 @@ const nonContentTokens = new Set([
|
|||
|
||||
module.exports = {
|
||||
"parse": micromarkParse,
|
||||
addRangeToSet,
|
||||
filterByPredicate,
|
||||
filterByTypes,
|
||||
getDescendantsByType,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue