Refactor to remove helpers addErrorContextForLine and blockquotePrefixRe, add micromark helper getBlockQuotePrefixText.

This commit is contained in:
David Anson 2024-10-04 22:41:34 -07:00
parent 29ebb28f10
commit 5182911acc
6 changed files with 170 additions and 152 deletions

View file

@ -18,10 +18,6 @@ const inlineCommentStartRe =
/(<!--\s*markdownlint-(disable|enable|capture|restore|disable-file|enable-file|disable-line|disable-next-line|configure-file))(?:\s|-->)/gi;
module.exports.inlineCommentStartRe = inlineCommentStartRe;
// Regular expression for blockquote prefixes
const blockquotePrefixRe = /^[>\s]*/;
module.exports.blockquotePrefixRe = blockquotePrefixRe;
// Regular expression for link reference definitions
const linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])\]:/;
module.exports.linkReferenceDefinitionRe = linkReferenceDefinitionRe;
@ -346,34 +342,6 @@ function addErrorContext(
}
module.exports.addErrorContext = addErrorContext;
/**
* Adds an error object with context for a construct missing a blank line.
*
* @param {Object} onError RuleOnError instance.
* @param {string[]} lines Lines of Markdown content.
* @param {number} lineIndex Line index of line.
* @param {number} [lineNumber] Line number for override.
* @returns {void}
*/
function addErrorContextForLine(onError, lines, lineIndex, lineNumber) {
const line = lines[lineIndex];
// @ts-ignore
const quotePrefix = line.match(blockquotePrefixRe)[0].trimEnd();
addErrorContext(
onError,
lineIndex + 1,
line.trim(),
undefined,
undefined,
undefined,
{
lineNumber,
"insertText": `${quotePrefix}\n`
}
);
}
module.exports.addErrorContextForLine = addErrorContextForLine;
/**
* Defines a range within a file (start line/column to end line/column, subset of MicromarkToken).
*