mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD022/blanks-around-headings to include blockquote prefix if fixing inside a blockquote (fixes #654).
This commit is contained in:
parent
82ea22d31a
commit
5eef37751b
5 changed files with 285 additions and 6 deletions
|
@ -3190,7 +3190,13 @@ module.exports = {
|
|||
"use strict";
|
||||
// @ts-check
|
||||
|
||||
const { addErrorDetailIf, filterTokens, isBlankLine } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
|
||||
const { addErrorDetailIf, blockquotePrefixRe, filterTokens, isBlankLine } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
|
||||
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"],
|
||||
"description": "Headings should be surrounded by blank lines",
|
||||
|
@ -3210,7 +3216,7 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
addErrorDetailIf(onError, topIndex + 1, linesAbove, actualAbove, "Above", 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++) {
|
||||
|
@ -3220,7 +3226,7 @@ module.exports = {
|
|||
}
|
||||
addErrorDetailIf(onError, topIndex + 1, linesBelow, actualBelow, "Below", lines[topIndex].trim(), null, {
|
||||
"lineNumber": nextIndex + 1,
|
||||
"insertText": "".padEnd(linesBelow - actualBelow, "\n")
|
||||
"insertText": getBlockQuote(lines[nextIndex], linesBelow - actualBelow)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
18
lib/md022.js
18
lib/md022.js
|
@ -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)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -34,3 +34,41 @@ Text
|
|||
- Item
|
||||
|
||||
Text
|
||||
|
||||
> Text
|
||||
>
|
||||
> ## Heading One {MD022}
|
||||
> Text
|
||||
|
||||
Text
|
||||
|
||||
> Text
|
||||
> ## Heading Two {MD022}
|
||||
>
|
||||
> Text
|
||||
|
||||
Text
|
||||
|
||||
> Text
|
||||
> ## Heading Three {MD022}
|
||||
> Text
|
||||
|
||||
Text
|
||||
|
||||
> > Text
|
||||
> > ### Heading Four {MD022}
|
||||
> > Text
|
||||
|
||||
Text
|
||||
|
||||
> Text
|
||||
> > ### Heading Five {MD022}
|
||||
> > Text
|
||||
|
||||
Text
|
||||
|
||||
> > Text
|
||||
> > ### Heading Six {MD022}
|
||||
> Text
|
||||
|
||||
Text
|
||||
|
|
|
@ -3997,6 +3997,181 @@ Generated by [AVA](https://avajs.dev).
|
|||
'blanks-around-headers',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> ## Heading One {MD022}',
|
||||
errorDetail: 'Expected: 1; Actual: 0; Below',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `>␊
|
||||
`,
|
||||
lineNumber: 41,
|
||||
},
|
||||
lineNumber: 40,
|
||||
ruleDescription: 'Headings should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
|
||||
ruleNames: [
|
||||
'MD022',
|
||||
'blanks-around-headings',
|
||||
'blanks-around-headers',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> ## Heading Two {MD022}',
|
||||
errorDetail: 'Expected: 1; Actual: 0; Above',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `>␊
|
||||
`,
|
||||
},
|
||||
lineNumber: 46,
|
||||
ruleDescription: 'Headings should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
|
||||
ruleNames: [
|
||||
'MD022',
|
||||
'blanks-around-headings',
|
||||
'blanks-around-headers',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> ## Heading Three {MD022}',
|
||||
errorDetail: 'Expected: 1; Actual: 0; Above',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `>␊
|
||||
`,
|
||||
},
|
||||
lineNumber: 53,
|
||||
ruleDescription: 'Headings should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
|
||||
ruleNames: [
|
||||
'MD022',
|
||||
'blanks-around-headings',
|
||||
'blanks-around-headers',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> ## Heading Three {MD022}',
|
||||
errorDetail: 'Expected: 1; Actual: 0; Below',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `>␊
|
||||
`,
|
||||
lineNumber: 54,
|
||||
},
|
||||
lineNumber: 53,
|
||||
ruleDescription: 'Headings should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
|
||||
ruleNames: [
|
||||
'MD022',
|
||||
'blanks-around-headings',
|
||||
'blanks-around-headers',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> > ### Heading Four {MD022}',
|
||||
errorDetail: 'Expected: 1; Actual: 0; Above',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `> >␊
|
||||
`,
|
||||
},
|
||||
lineNumber: 59,
|
||||
ruleDescription: 'Headings should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
|
||||
ruleNames: [
|
||||
'MD022',
|
||||
'blanks-around-headings',
|
||||
'blanks-around-headers',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> > ### Heading Four {MD022}',
|
||||
errorDetail: 'Expected: 1; Actual: 0; Below',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `> >␊
|
||||
`,
|
||||
lineNumber: 60,
|
||||
},
|
||||
lineNumber: 59,
|
||||
ruleDescription: 'Headings should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
|
||||
ruleNames: [
|
||||
'MD022',
|
||||
'blanks-around-headings',
|
||||
'blanks-around-headers',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> > ### Heading Five {MD022}',
|
||||
errorDetail: 'Expected: 1; Actual: 0; Above',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `>␊
|
||||
`,
|
||||
},
|
||||
lineNumber: 65,
|
||||
ruleDescription: 'Headings should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
|
||||
ruleNames: [
|
||||
'MD022',
|
||||
'blanks-around-headings',
|
||||
'blanks-around-headers',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> > ### Heading Five {MD022}',
|
||||
errorDetail: 'Expected: 1; Actual: 0; Below',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `> >␊
|
||||
`,
|
||||
lineNumber: 66,
|
||||
},
|
||||
lineNumber: 65,
|
||||
ruleDescription: 'Headings should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
|
||||
ruleNames: [
|
||||
'MD022',
|
||||
'blanks-around-headings',
|
||||
'blanks-around-headers',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> > ### Heading Six {MD022}',
|
||||
errorDetail: 'Expected: 1; Actual: 0; Above',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `> >␊
|
||||
`,
|
||||
},
|
||||
lineNumber: 71,
|
||||
ruleDescription: 'Headings should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
|
||||
ruleNames: [
|
||||
'MD022',
|
||||
'blanks-around-headings',
|
||||
'blanks-around-headers',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> > ### Heading Six {MD022}',
|
||||
errorDetail: 'Expected: 1; Actual: 0; Below',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `>␊
|
||||
`,
|
||||
lineNumber: 72,
|
||||
},
|
||||
lineNumber: 71,
|
||||
ruleDescription: 'Headings should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
|
||||
ruleNames: [
|
||||
'MD022',
|
||||
'blanks-around-headings',
|
||||
'blanks-around-headers',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> ## Quoted indented sub-head...',
|
||||
errorDetail: null,
|
||||
|
@ -4157,6 +4332,54 @@ Generated by [AVA](https://avajs.dev).
|
|||
- Item␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
> Text␊
|
||||
>␊
|
||||
> ## Heading One {MD022}␊
|
||||
>␊
|
||||
> Text␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
> Text␊
|
||||
>␊
|
||||
> ## Heading Two {MD022}␊
|
||||
>␊
|
||||
> Text␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
> Text␊
|
||||
>␊
|
||||
> ## Heading Three {MD022}␊
|
||||
>␊
|
||||
> Text␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
> > Text␊
|
||||
> >␊
|
||||
> > ### Heading Four {MD022}␊
|
||||
> >␊
|
||||
> > Text␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
> Text␊
|
||||
>␊
|
||||
> > ### Heading Five {MD022}␊
|
||||
> >␊
|
||||
> > Text␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
> > Text␊
|
||||
> >␊
|
||||
> > ### Heading Six {MD022}␊
|
||||
>␊
|
||||
> Text␊
|
||||
␊
|
||||
Text␊
|
||||
`,
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue