diff --git a/demo/markdownlint-browser.js b/demo/markdownlint-browser.js index 4595cdde..9490bd8d 100644 --- a/demo/markdownlint-browser.js +++ b/demo/markdownlint-browser.js @@ -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); } diff --git a/lib/md031.js b/lib/md031.js index bfc4351c..fce25ac0 100644 --- a/lib/md031.js +++ b/lib/md031.js @@ -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, diff --git a/test/blanks-around-fences-in-lists.md b/test/blanks-around-fences-in-lists.md new file mode 100644 index 00000000..094b35f7 --- /dev/null +++ b/test/blanks-around-fences-in-lists.md @@ -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 +> > ``` diff --git a/test/snapshots/markdownlint-test-scenarios.js.md b/test/snapshots/markdownlint-test-scenarios.js.md index 3deb92ed..157c269c 100644 --- a/test/snapshots/markdownlint-test-scenarios.js.md +++ b/test/snapshots/markdownlint-test-scenarios.js.md @@ -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 diff --git a/test/snapshots/markdownlint-test-scenarios.js.snap b/test/snapshots/markdownlint-test-scenarios.js.snap index 0ccc0364..7b490a0a 100644 Binary files a/test/snapshots/markdownlint-test-scenarios.js.snap and b/test/snapshots/markdownlint-test-scenarios.js.snap differ