mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-24 01:40:13 +01:00
Update MD022/blanks-around-headings to allow passing -1 for lines_above/lines_below to allow any number of blank lines in that direction (fixes #546).
This commit is contained in:
parent
f079df140c
commit
809841098d
12 changed files with 273 additions and 58 deletions
78
lib/md022.js
78
lib/md022.js
|
|
@ -32,45 +32,53 @@ module.exports = {
|
|||
for (const heading of headings) {
|
||||
const { startLine, endLine } = heading;
|
||||
const line = lines[startLine - 1].trim();
|
||||
let actualAbove = 0;
|
||||
for (let i = 0; i < linesAbove; i++) {
|
||||
if (isBlankLine(lines[startLine - 2 - i])) {
|
||||
actualAbove++;
|
||||
|
||||
// Check lines above
|
||||
if (linesAbove >= 0) {
|
||||
let actualAbove = 0;
|
||||
for (let i = 0; i < linesAbove; i++) {
|
||||
if (isBlankLine(lines[startLine - 2 - i])) {
|
||||
actualAbove++;
|
||||
}
|
||||
}
|
||||
addErrorDetailIf(
|
||||
onError,
|
||||
startLine,
|
||||
linesAbove,
|
||||
actualAbove,
|
||||
"Above",
|
||||
line,
|
||||
null,
|
||||
{
|
||||
"insertText":
|
||||
getBlockQuote(lines[startLine - 2], linesAbove - actualAbove)
|
||||
}
|
||||
);
|
||||
}
|
||||
addErrorDetailIf(
|
||||
onError,
|
||||
startLine,
|
||||
linesAbove,
|
||||
actualAbove,
|
||||
"Above",
|
||||
line,
|
||||
null,
|
||||
{
|
||||
"insertText":
|
||||
getBlockQuote(lines[startLine - 2], linesAbove - actualAbove)
|
||||
}
|
||||
);
|
||||
let actualBelow = 0;
|
||||
for (let i = 0; i < linesBelow; i++) {
|
||||
if (isBlankLine(lines[endLine + i])) {
|
||||
actualBelow++;
|
||||
|
||||
// Check lines below
|
||||
if (linesBelow >= 0) {
|
||||
let actualBelow = 0;
|
||||
for (let i = 0; i < linesBelow; i++) {
|
||||
if (isBlankLine(lines[endLine + i])) {
|
||||
actualBelow++;
|
||||
}
|
||||
}
|
||||
addErrorDetailIf(
|
||||
onError,
|
||||
startLine,
|
||||
linesBelow,
|
||||
actualBelow,
|
||||
"Below",
|
||||
line,
|
||||
null,
|
||||
{
|
||||
"lineNumber": endLine + 1,
|
||||
"insertText":
|
||||
getBlockQuote(lines[endLine], linesBelow - actualBelow)
|
||||
}
|
||||
);
|
||||
}
|
||||
addErrorDetailIf(
|
||||
onError,
|
||||
startLine,
|
||||
linesBelow,
|
||||
actualBelow,
|
||||
"Below",
|
||||
line,
|
||||
null,
|
||||
{
|
||||
"lineNumber": endLine + 1,
|
||||
"insertText":
|
||||
getBlockQuote(lines[endLine], linesBelow - actualBelow)
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue