Update MD022/blanks-around-headings to include blockquote prefix if fixing inside a blockquote (fixes #654).

This commit is contained in:
David Anson 2022-12-07 21:16:05 -08:00
parent 82ea22d31a
commit 5eef37751b
5 changed files with 285 additions and 6 deletions

View file

@ -2,7 +2,17 @@
"use strict";
const { addErrorDetailIf, filterTokens, isBlankLine } = require("../helpers");
const { addErrorDetailIf, blockquotePrefixRe, filterTokens, isBlankLine } =
require("../helpers");
const getBlockQuote = (str, count) => (
(str || "")
.match(blockquotePrefixRe)[0]
.trimEnd()
// eslint-disable-next-line unicorn/prefer-spread
.concat("\n")
.repeat(count)
);
module.exports = {
"names": [ "MD022", "blanks-around-headings", "blanks-around-headers" ],
@ -31,7 +41,8 @@ module.exports = {
lines[topIndex].trim(),
null,
{
"insertText": "".padEnd(linesAbove - actualAbove, "\n")
"insertText":
getBlockQuote(lines[topIndex - 1], linesAbove - actualAbove)
});
let actualBelow = 0;
for (let i = 0; i < linesBelow; i++) {
@ -49,7 +60,8 @@ module.exports = {
null,
{
"lineNumber": nextIndex + 1,
"insertText": "".padEnd(linesBelow - actualBelow, "\n")
"insertText":
getBlockQuote(lines[nextIndex], linesBelow - actualBelow)
});
});
}