Add new rule MD058/blanks-around-tables (fixes #132).

This commit is contained in:
David Anson 2024-06-01 21:32:10 -07:00
parent 5ecdb045a5
commit 26466108e9
27 changed files with 914 additions and 76 deletions

View file

@ -2,28 +2,12 @@
"use strict";
const { addErrorContext, blockquotePrefixRe, isBlankLine } = require("../helpers");
const { addErrorContextForLine, isBlankLine } = require("../helpers");
const { filterByPredicate, nonContentTokens } = require("../helpers/micromark.cjs");
const isList = (token) => (
(token.type === "listOrdered") || (token.type === "listUnordered")
);
const addBlankLineError = (onError, lines, lineIndex, lineNumber) => {
const line = lines[lineIndex];
const quotePrefix = line.match(blockquotePrefixRe)[0].trimEnd();
addErrorContext(
onError,
lineIndex + 1,
line.trim(),
null,
null,
null,
{
lineNumber,
"insertText": `${quotePrefix}\n`
}
);
};
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
@ -53,7 +37,12 @@ module.exports = {
// Look for a blank line above the list
const firstIndex = list.startLine - 1;
if (!isBlankLine(lines[firstIndex - 1])) {
addBlankLineError(onError, lines, firstIndex);
addErrorContextForLine(
onError,
// @ts-ignore
lines,
firstIndex
);
}
// Find the "visual" end of the list
@ -69,7 +58,13 @@ module.exports = {
// Look for a blank line below the list
const lastIndex = endLine - 1;
if (!isBlankLine(lines[lastIndex + 1])) {
addBlankLineError(onError, lines, lastIndex, lastIndex + 2);
addErrorContextForLine(
onError,
// @ts-ignore
lines,
lastIndex,
lastIndex + 2
);
}
}
}