mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 05:50:13 +01:00
Update MD031/blanks-around-fences to avoid duplicating list item markers when adding blank lines (fixes #485).
This commit is contained in:
parent
cf26cc7c92
commit
5f5f44e8e0
5 changed files with 576 additions and 4 deletions
|
|
@ -3428,7 +3428,7 @@ module.exports = {
|
|||
|
||||
var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, forEachLine = _a.forEachLine, isBlankLine = _a.isBlankLine;
|
||||
var lineMetadata = (__webpack_require__(/*! ./cache */ "../lib/cache.js").lineMetadata);
|
||||
var codeFencePrefixRe = /^(.*?)\s*[`~]/;
|
||||
var codeFencePrefixRe = /^(.*?)[`~]/;
|
||||
module.exports = {
|
||||
"names": ["MD031", "blanks-around-fences"],
|
||||
"description": "Fenced code blocks should be surrounded by blank lines",
|
||||
|
|
@ -3446,7 +3446,7 @@ module.exports = {
|
|||
var _a = line.match(codeFencePrefixRe) || [], prefix = _a[1];
|
||||
var fixInfo = (prefix === undefined) ? null : {
|
||||
"lineNumber": i + (onTopFence ? 1 : 2),
|
||||
"insertText": "".concat(prefix, "\n")
|
||||
"insertText": "".concat(prefix.replace(/[^>]/g, " ").trim(), "\n")
|
||||
};
|
||||
addErrorContext(onError, i + 1, lines[i].trim(), null, null, null, fixInfo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
const { addErrorContext, forEachLine, isBlankLine } = require("../helpers");
|
||||
const { lineMetadata } = require("./cache");
|
||||
|
||||
const codeFencePrefixRe = /^(.*?)\s*[`~]/;
|
||||
const codeFencePrefixRe = /^(.*?)[`~]/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD031", "blanks-around-fences" ],
|
||||
|
|
@ -24,7 +24,7 @@ module.exports = {
|
|||
const [ , prefix ] = line.match(codeFencePrefixRe) || [];
|
||||
const fixInfo = (prefix === undefined) ? null : {
|
||||
"lineNumber": i + (onTopFence ? 1 : 2),
|
||||
"insertText": `${prefix}\n`
|
||||
"insertText": `${prefix.replace(/[^>]/g, " ").trim()}\n`
|
||||
};
|
||||
addErrorContext(
|
||||
onError,
|
||||
|
|
|
|||
71
test/blanks-around-fences-in-lists.md
Normal file
71
test/blanks-around-fences-in-lists.md
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
# Blanks Around Fences In Lists
|
||||
|
||||
1. ```text
|
||||
Text
|
||||
```
|
||||
2. ```text
|
||||
Text
|
||||
```
|
||||
3. ```text
|
||||
Text
|
||||
```
|
||||
|
||||
Text
|
||||
|
||||
- ```text
|
||||
Text
|
||||
```
|
||||
- ```text
|
||||
Text
|
||||
```
|
||||
- ```text
|
||||
Text
|
||||
```
|
||||
|
||||
Text
|
||||
|
||||
> 1. ```text
|
||||
> Text
|
||||
> ```
|
||||
> 2. ```text
|
||||
> Text
|
||||
> ```
|
||||
> 3. ```text
|
||||
> Text
|
||||
> ```
|
||||
|
||||
Text
|
||||
|
||||
> - ```text
|
||||
> Text
|
||||
> ```
|
||||
> - ```text
|
||||
> Text
|
||||
> ```
|
||||
> - ```text
|
||||
> Text
|
||||
> ```
|
||||
|
||||
Text
|
||||
|
||||
> > 1. ```text
|
||||
> > Text
|
||||
> > ```
|
||||
> > 2. ```text
|
||||
> > Text
|
||||
> > ```
|
||||
> > 3. ```text
|
||||
> > Text
|
||||
> > ```
|
||||
|
||||
Text
|
||||
|
||||
> > - ```text
|
||||
> > Text
|
||||
> > ```
|
||||
> > - ```text
|
||||
> > Text
|
||||
> > ```
|
||||
> > - ```text
|
||||
> > Text
|
||||
> > ```
|
||||
|
|
@ -2861,6 +2861,507 @@ Generated by [AVA](https://avajs.dev).
|
|||
`,
|
||||
}
|
||||
|
||||
## blanks-around-fences-in-lists.md
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
{
|
||||
errors: [
|
||||
{
|
||||
errorContext: '```',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `␊
|
||||
`,
|
||||
lineNumber: 6,
|
||||
},
|
||||
lineNumber: 5,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '2. ```text',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `␊
|
||||
`,
|
||||
lineNumber: 6,
|
||||
},
|
||||
lineNumber: 6,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '```',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `␊
|
||||
`,
|
||||
lineNumber: 9,
|
||||
},
|
||||
lineNumber: 8,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '3. ```text',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `␊
|
||||
`,
|
||||
lineNumber: 9,
|
||||
},
|
||||
lineNumber: 9,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '```',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `␊
|
||||
`,
|
||||
lineNumber: 18,
|
||||
},
|
||||
lineNumber: 17,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '- ```text',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `␊
|
||||
`,
|
||||
lineNumber: 18,
|
||||
},
|
||||
lineNumber: 18,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '```',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `␊
|
||||
`,
|
||||
lineNumber: 21,
|
||||
},
|
||||
lineNumber: 20,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '- ```text',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `␊
|
||||
`,
|
||||
lineNumber: 21,
|
||||
},
|
||||
lineNumber: 21,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> ```',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `>␊
|
||||
`,
|
||||
lineNumber: 30,
|
||||
},
|
||||
lineNumber: 29,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> 2. ```text',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `>␊
|
||||
`,
|
||||
lineNumber: 30,
|
||||
},
|
||||
lineNumber: 30,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> ```',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `>␊
|
||||
`,
|
||||
lineNumber: 33,
|
||||
},
|
||||
lineNumber: 32,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> 3. ```text',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `>␊
|
||||
`,
|
||||
lineNumber: 33,
|
||||
},
|
||||
lineNumber: 33,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> ```',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `>␊
|
||||
`,
|
||||
lineNumber: 42,
|
||||
},
|
||||
lineNumber: 41,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> - ```text',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `>␊
|
||||
`,
|
||||
lineNumber: 42,
|
||||
},
|
||||
lineNumber: 42,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> ```',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `>␊
|
||||
`,
|
||||
lineNumber: 45,
|
||||
},
|
||||
lineNumber: 44,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> - ```text',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `>␊
|
||||
`,
|
||||
lineNumber: 45,
|
||||
},
|
||||
lineNumber: 45,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> > ```',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `> >␊
|
||||
`,
|
||||
lineNumber: 54,
|
||||
},
|
||||
lineNumber: 53,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> > 2. ```text',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `> >␊
|
||||
`,
|
||||
lineNumber: 54,
|
||||
},
|
||||
lineNumber: 54,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> > ```',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `> >␊
|
||||
`,
|
||||
lineNumber: 57,
|
||||
},
|
||||
lineNumber: 56,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> > 3. ```text',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `> >␊
|
||||
`,
|
||||
lineNumber: 57,
|
||||
},
|
||||
lineNumber: 57,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> > ```',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `> >␊
|
||||
`,
|
||||
lineNumber: 66,
|
||||
},
|
||||
lineNumber: 65,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> > - ```text',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `> >␊
|
||||
`,
|
||||
lineNumber: 66,
|
||||
},
|
||||
lineNumber: 66,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> > ```',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `> >␊
|
||||
`,
|
||||
lineNumber: 69,
|
||||
},
|
||||
lineNumber: 68,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '> > - ```text',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `> >␊
|
||||
`,
|
||||
lineNumber: 69,
|
||||
},
|
||||
lineNumber: 69,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md031',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
],
|
||||
fixed: `# Blanks Around Fences In Lists␊
|
||||
␊
|
||||
1. \`\`\`text␊
|
||||
Text␊
|
||||
\`\`\`␊
|
||||
␊
|
||||
2. \`\`\`text␊
|
||||
Text␊
|
||||
\`\`\`␊
|
||||
␊
|
||||
3. \`\`\`text␊
|
||||
Text␊
|
||||
\`\`\`␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
- \`\`\`text␊
|
||||
Text␊
|
||||
\`\`\`␊
|
||||
␊
|
||||
- \`\`\`text␊
|
||||
Text␊
|
||||
\`\`\`␊
|
||||
␊
|
||||
- \`\`\`text␊
|
||||
Text␊
|
||||
\`\`\`␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
> 1. \`\`\`text␊
|
||||
> Text␊
|
||||
> \`\`\`␊
|
||||
>␊
|
||||
> 2. \`\`\`text␊
|
||||
> Text␊
|
||||
> \`\`\`␊
|
||||
>␊
|
||||
> 3. \`\`\`text␊
|
||||
> Text␊
|
||||
> \`\`\`␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
> - \`\`\`text␊
|
||||
> Text␊
|
||||
> \`\`\`␊
|
||||
>␊
|
||||
> - \`\`\`text␊
|
||||
> Text␊
|
||||
> \`\`\`␊
|
||||
>␊
|
||||
> - \`\`\`text␊
|
||||
> Text␊
|
||||
> \`\`\`␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
> > 1. \`\`\`text␊
|
||||
> > Text␊
|
||||
> > \`\`\`␊
|
||||
> >␊
|
||||
> > 2. \`\`\`text␊
|
||||
> > Text␊
|
||||
> > \`\`\`␊
|
||||
> >␊
|
||||
> > 3. \`\`\`text␊
|
||||
> > Text␊
|
||||
> > \`\`\`␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
> > - \`\`\`text␊
|
||||
> > Text␊
|
||||
> > \`\`\`␊
|
||||
> >␊
|
||||
> > - \`\`\`text␊
|
||||
> > Text␊
|
||||
> > \`\`\`␊
|
||||
> >␊
|
||||
> > - \`\`\`text␊
|
||||
> > Text␊
|
||||
> > \`\`\`␊
|
||||
`,
|
||||
}
|
||||
|
||||
## blanks-around-headings-0-2.md
|
||||
|
||||
> Snapshot 1
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue