mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-28 11:38:48 +01:00
Refactor to remove helpers addErrorContextForLine and blockquotePrefixRe, add micromark helper getBlockQuotePrefixText.
This commit is contained in:
parent
29ebb28f10
commit
5182911acc
6 changed files with 170 additions and 152 deletions
|
|
@ -133,6 +133,25 @@ function filterByTypes(tokens, types, htmlFlow) {
|
|||
return filterByPredicate(tokens, predicate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the blockquote prefix text (if any) for the specified line number.
|
||||
*
|
||||
* @param {Token[]} tokens Micromark tokens.
|
||||
* @param {number} lineNumber Line number to examine.
|
||||
* @param {number} [count] Number of times to repeat.
|
||||
* @returns {string} Blockquote prefix text.
|
||||
*/
|
||||
function getBlockQuotePrefixText(tokens, lineNumber, count = 1) {
|
||||
return filterByTypes(tokens, [ "blockQuotePrefix", "linePrefix" ])
|
||||
.filter((prefix) => prefix.startLine === lineNumber)
|
||||
.map((prefix) => prefix.text)
|
||||
.join("")
|
||||
.trimEnd()
|
||||
// eslint-disable-next-line unicorn/prefer-spread
|
||||
.concat("\n")
|
||||
.repeat(count);
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets a list of nested Micromark token descendants by type path.
|
||||
*
|
||||
|
|
@ -267,6 +286,7 @@ module.exports = {
|
|||
addRangeToSet,
|
||||
filterByPredicate,
|
||||
filterByTypes,
|
||||
getBlockQuotePrefixText,
|
||||
getDescendantsByType,
|
||||
getHeadingLevel,
|
||||
getHeadingStyle,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue