mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-21 21:30:47 +02:00
Update MD022/blanks-around-headings to allow specifying a different number of blank lines for each heading level (fixes #504).
This commit is contained in:
parent
bdc9d357f3
commit
d9de1dd22f
13 changed files with 690 additions and 64 deletions
|
@ -1366,6 +1366,24 @@ function flattenedChildren(parent) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the heading level of a Micromark heading tokan.
|
||||
*
|
||||
* @param {Token} heading Micromark heading token.
|
||||
* @returns {number} Heading level.
|
||||
*/
|
||||
function getHeadingLevel(heading) {
|
||||
var headingSequence = filterByTypes(heading.children, ["atxHeadingSequence", "setextHeadingLineSequence"]);
|
||||
var level = 1;
|
||||
var text = headingSequence[0].text;
|
||||
if (text[0] === "#") {
|
||||
level = Math.min(text.length, 6);
|
||||
} else if (text[0] === "-") {
|
||||
level = 2;
|
||||
}
|
||||
return level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets information about the tag in an HTML token.
|
||||
*
|
||||
|
@ -1443,6 +1461,7 @@ module.exports = {
|
|||
filterByPredicate: filterByPredicate,
|
||||
filterByTypes: filterByTypes,
|
||||
flattenedChildren: flattenedChildren,
|
||||
getHeadingLevel: getHeadingLevel,
|
||||
getHtmlTagInfo: getHtmlTagInfo,
|
||||
getMicromarkEvents: getMicromarkEvents,
|
||||
getTokenTextByType: getTokenTextByType,
|
||||
|
@ -4143,7 +4162,15 @@ module.exports = {
|
|||
|
||||
|
||||
|
||||
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
||||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
||||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
||||
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
||||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
||||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
||||
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
||||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
||||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
||||
var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
|
||||
|
@ -4151,7 +4178,36 @@ var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
|
|||
blockquotePrefixRe = _require.blockquotePrefixRe,
|
||||
isBlankLine = _require.isBlankLine;
|
||||
var _require2 = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs"),
|
||||
filterByTypes = _require2.filterByTypes;
|
||||
filterByTypes = _require2.filterByTypes,
|
||||
getHeadingLevel = _require2.getHeadingLevel;
|
||||
var defaultLines = 1;
|
||||
var getLinesFunction = function getLinesFunction(linesParam) {
|
||||
if (Array.isArray(linesParam)) {
|
||||
var linesArray = new Array(6).fill(defaultLines);
|
||||
var _iterator = _createForOfIteratorHelper(_toConsumableArray(linesParam.entries()).slice(0, 6)),
|
||||
_step;
|
||||
try {
|
||||
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
||||
var _step$value = _slicedToArray(_step.value, 2),
|
||||
index = _step$value[0],
|
||||
value = _step$value[1];
|
||||
linesArray[index] = value;
|
||||
}
|
||||
} catch (err) {
|
||||
_iterator.e(err);
|
||||
} finally {
|
||||
_iterator.f();
|
||||
}
|
||||
return function (heading) {
|
||||
return linesArray[getHeadingLevel(heading) - 1];
|
||||
};
|
||||
}
|
||||
// Coerce linesParam to a number
|
||||
var lines = linesParam === undefined ? defaultLines : Number(linesParam);
|
||||
return function () {
|
||||
return lines;
|
||||
};
|
||||
};
|
||||
var getBlockQuote = function getBlockQuote(str, count) {
|
||||
return (str || "").match(blockquotePrefixRe)[0].trimEnd()
|
||||
// eslint-disable-next-line unicorn/prefer-spread
|
||||
|
@ -4162,29 +4218,26 @@ module.exports = {
|
|||
"description": "Headings should be surrounded by blank lines",
|
||||
"tags": ["headings", "headers", "blank_lines"],
|
||||
"function": function MD022(params, onError) {
|
||||
var linesAbove = params.config.lines_above;
|
||||
linesAbove = Number(linesAbove === undefined ? 1 : linesAbove);
|
||||
var linesBelow = params.config.lines_below;
|
||||
linesBelow = Number(linesBelow === undefined ? 1 : linesBelow);
|
||||
var getLinesAbove = getLinesFunction(params.config.lines_above);
|
||||
var getLinesBelow = getLinesFunction(params.config.lines_below);
|
||||
var lines = params.lines,
|
||||
parsers = params.parsers;
|
||||
var headings = filterByTypes(parsers.micromark.tokens, ["atxHeading", "setextHeading"]);
|
||||
var _iterator = _createForOfIteratorHelper(headings),
|
||||
_step;
|
||||
var _iterator2 = _createForOfIteratorHelper(headings),
|
||||
_step2;
|
||||
try {
|
||||
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
||||
var heading = _step.value;
|
||||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
||||
var heading = _step2.value;
|
||||
var startLine = heading.startLine,
|
||||
endLine = heading.endLine;
|
||||
var line = lines[startLine - 1].trim();
|
||||
|
||||
// Check lines above
|
||||
var linesAbove = getLinesAbove(heading);
|
||||
if (linesAbove >= 0) {
|
||||
var actualAbove = 0;
|
||||
for (var i = 0; i < linesAbove; i++) {
|
||||
if (isBlankLine(lines[startLine - 2 - i])) {
|
||||
actualAbove++;
|
||||
}
|
||||
for (var i = 0; i < linesAbove && isBlankLine(lines[startLine - 2 - i]); i++) {
|
||||
actualAbove++;
|
||||
}
|
||||
addErrorDetailIf(onError, startLine, linesAbove, actualAbove, "Above", line, null, {
|
||||
"insertText": getBlockQuote(lines[startLine - 2], linesAbove - actualAbove)
|
||||
|
@ -4192,12 +4245,11 @@ module.exports = {
|
|||
}
|
||||
|
||||
// Check lines below
|
||||
var linesBelow = getLinesBelow(heading);
|
||||
if (linesBelow >= 0) {
|
||||
var actualBelow = 0;
|
||||
for (var _i = 0; _i < linesBelow; _i++) {
|
||||
if (isBlankLine(lines[endLine + _i])) {
|
||||
actualBelow++;
|
||||
}
|
||||
for (var _i2 = 0; _i2 < linesBelow && isBlankLine(lines[endLine + _i2]); _i2++) {
|
||||
actualBelow++;
|
||||
}
|
||||
addErrorDetailIf(onError, startLine, linesBelow, actualBelow, "Below", line, null, {
|
||||
"lineNumber": endLine + 1,
|
||||
|
@ -4206,9 +4258,9 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_iterator.e(err);
|
||||
_iterator2.e(err);
|
||||
} finally {
|
||||
_iterator.f();
|
||||
_iterator2.f();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -68,9 +68,10 @@ for (const rule of rules) {
|
|||
);
|
||||
for (const property of Object.keys(ruleData.properties).sort()) {
|
||||
const propData = ruleData.properties[property];
|
||||
const propType = (propData.type === "array") ?
|
||||
`${propData.items.type}[]` :
|
||||
propData.type;
|
||||
const propType = [ propData.type ]
|
||||
.flat()
|
||||
.map((type) => ((type === "array") ? `${propData.items.type}[]` : type))
|
||||
.join("|");
|
||||
const defaultValue = Array.isArray(propData.default) ?
|
||||
JSON.stringify(propData.default) :
|
||||
propData.default;
|
||||
|
|
|
@ -23,12 +23,16 @@ Some more text
|
|||
```
|
||||
|
||||
The `lines_above` and `lines_below` parameters can be used to specify a
|
||||
different number of blank lines (including `0`) above or below each heading. If
|
||||
the value `-1` is used for either parameter, any number of blank lines is
|
||||
allowed.
|
||||
different number of blank lines (including `0`) above or below each heading.
|
||||
If the value `-1` is used for either parameter, any number of blank lines is
|
||||
allowed. To customize the number of lines above or below each heading level
|
||||
individually, specify a `number[]` where values correspond to heading levels
|
||||
1-6 (in order).
|
||||
|
||||
Note: If `lines_above` or `lines_below` are configured to require more than one
|
||||
blank line, [MD012/no-multiple-blanks](md012.md) should also be customized.
|
||||
Notes: If `lines_above` or `lines_below` are configured to require more than one
|
||||
blank line, [MD012/no-multiple-blanks](md012.md) should also be customized. This
|
||||
rule checks for *at least* as many blank lines as specified; any extra blank
|
||||
lines are ignored.
|
||||
|
||||
Rationale: Aside from aesthetic reasons, some parsers, including `kramdown`,
|
||||
will not parse headings that don't have a blank line before, and will parse them
|
||||
|
|
18
doc/Rules.md
18
doc/Rules.md
|
@ -806,8 +806,8 @@ Aliases: `blanks-around-headers`, `blanks-around-headings`
|
|||
|
||||
Parameters:
|
||||
|
||||
- `lines_above`: Blank lines above heading (`integer`, default `1`)
|
||||
- `lines_below`: Blank lines below heading (`integer`, default `1`)
|
||||
- `lines_above`: Blank lines above heading (`integer|integer[]`, default `1`)
|
||||
- `lines_below`: Blank lines below heading (`integer|integer[]`, default `1`)
|
||||
|
||||
Fixable: Some violations can be fixed by tooling
|
||||
|
||||
|
@ -836,12 +836,16 @@ Some more text
|
|||
```
|
||||
|
||||
The `lines_above` and `lines_below` parameters can be used to specify a
|
||||
different number of blank lines (including `0`) above or below each heading. If
|
||||
the value `-1` is used for either parameter, any number of blank lines is
|
||||
allowed.
|
||||
different number of blank lines (including `0`) above or below each heading.
|
||||
If the value `-1` is used for either parameter, any number of blank lines is
|
||||
allowed. To customize the number of lines above or below each heading level
|
||||
individually, specify a `number[]` where values correspond to heading levels
|
||||
1-6 (in order).
|
||||
|
||||
Note: If `lines_above` or `lines_below` are configured to require more than one
|
||||
blank line, [MD012/no-multiple-blanks](md012.md) should also be customized.
|
||||
Notes: If `lines_above` or `lines_below` are configured to require more than one
|
||||
blank line, [MD012/no-multiple-blanks](md012.md) should also be customized. This
|
||||
rule checks for *at least* as many blank lines as specified; any extra blank
|
||||
lines are ignored.
|
||||
|
||||
Rationale: Aside from aesthetic reasons, some parsers, including `kramdown`,
|
||||
will not parse headings that don't have a blank line before, and will parse them
|
||||
|
|
18
doc/md022.md
18
doc/md022.md
|
@ -6,8 +6,8 @@ Aliases: `blanks-around-headers`, `blanks-around-headings`
|
|||
|
||||
Parameters:
|
||||
|
||||
- `lines_above`: Blank lines above heading (`integer`, default `1`)
|
||||
- `lines_below`: Blank lines below heading (`integer`, default `1`)
|
||||
- `lines_above`: Blank lines above heading (`integer|integer[]`, default `1`)
|
||||
- `lines_below`: Blank lines below heading (`integer|integer[]`, default `1`)
|
||||
|
||||
Fixable: Some violations can be fixed by tooling
|
||||
|
||||
|
@ -36,12 +36,16 @@ Some more text
|
|||
```
|
||||
|
||||
The `lines_above` and `lines_below` parameters can be used to specify a
|
||||
different number of blank lines (including `0`) above or below each heading. If
|
||||
the value `-1` is used for either parameter, any number of blank lines is
|
||||
allowed.
|
||||
different number of blank lines (including `0`) above or below each heading.
|
||||
If the value `-1` is used for either parameter, any number of blank lines is
|
||||
allowed. To customize the number of lines above or below each heading level
|
||||
individually, specify a `number[]` where values correspond to heading levels
|
||||
1-6 (in order).
|
||||
|
||||
Note: If `lines_above` or `lines_below` are configured to require more than one
|
||||
blank line, [MD012/no-multiple-blanks](md012.md) should also be customized.
|
||||
Notes: If `lines_above` or `lines_below` are configured to require more than one
|
||||
blank line, [MD012/no-multiple-blanks](md012.md) should also be customized. This
|
||||
rule checks for *at least* as many blank lines as specified; any extra blank
|
||||
lines are ignored.
|
||||
|
||||
Rationale: Aside from aesthetic reasons, some parsers, including `kramdown`,
|
||||
will not parse headings that don't have a blank line before, and will parse them
|
||||
|
|
|
@ -245,6 +245,27 @@ function flattenedChildren(parent) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the heading level of a Micromark heading tokan.
|
||||
*
|
||||
* @param {Token} heading Micromark heading token.
|
||||
* @returns {number} Heading level.
|
||||
*/
|
||||
function getHeadingLevel(heading) {
|
||||
const headingSequence = filterByTypes(
|
||||
heading.children,
|
||||
[ "atxHeadingSequence", "setextHeadingLineSequence" ]
|
||||
);
|
||||
let level = 1;
|
||||
const { text } = headingSequence[0];
|
||||
if (text[0] === "#") {
|
||||
level = Math.min(text.length, 6);
|
||||
} else if (text[0] === "-") {
|
||||
level = 2;
|
||||
}
|
||||
return level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets information about the tag in an HTML token.
|
||||
*
|
||||
|
@ -321,6 +342,7 @@ module.exports = {
|
|||
filterByPredicate,
|
||||
filterByTypes,
|
||||
flattenedChildren,
|
||||
getHeadingLevel,
|
||||
getHtmlTagInfo,
|
||||
getMicromarkEvents,
|
||||
getTokenTextByType,
|
||||
|
|
58
lib/md022.js
58
lib/md022.js
|
@ -4,7 +4,23 @@
|
|||
|
||||
const { addErrorDetailIf, blockquotePrefixRe, isBlankLine } =
|
||||
require("../helpers");
|
||||
const { filterByTypes } = require("../helpers/micromark.cjs");
|
||||
const { filterByTypes, getHeadingLevel } =
|
||||
require("../helpers/micromark.cjs");
|
||||
|
||||
const defaultLines = 1;
|
||||
|
||||
const getLinesFunction = (linesParam) => {
|
||||
if (Array.isArray(linesParam)) {
|
||||
const linesArray = new Array(6).fill(defaultLines);
|
||||
for (const [ index, value ] of [ ...linesParam.entries() ].slice(0, 6)) {
|
||||
linesArray[index] = value;
|
||||
}
|
||||
return (heading) => linesArray[getHeadingLevel(heading) - 1];
|
||||
}
|
||||
// Coerce linesParam to a number
|
||||
const lines = (linesParam === undefined) ? defaultLines : Number(linesParam);
|
||||
return () => lines;
|
||||
};
|
||||
|
||||
const getBlockQuote = (str, count) => (
|
||||
(str || "")
|
||||
|
@ -20,10 +36,8 @@ module.exports = {
|
|||
"description": "Headings should be surrounded by blank lines",
|
||||
"tags": [ "headings", "headers", "blank_lines" ],
|
||||
"function": function MD022(params, onError) {
|
||||
let linesAbove = params.config.lines_above;
|
||||
linesAbove = Number((linesAbove === undefined) ? 1 : linesAbove);
|
||||
let linesBelow = params.config.lines_below;
|
||||
linesBelow = Number((linesBelow === undefined) ? 1 : linesBelow);
|
||||
const getLinesAbove = getLinesFunction(params.config.lines_above);
|
||||
const getLinesBelow = getLinesFunction(params.config.lines_below);
|
||||
const { lines, parsers } = params;
|
||||
const headings = filterByTypes(
|
||||
parsers.micromark.tokens,
|
||||
|
@ -34,12 +48,15 @@ module.exports = {
|
|||
const line = lines[startLine - 1].trim();
|
||||
|
||||
// Check lines above
|
||||
const linesAbove = getLinesAbove(heading);
|
||||
if (linesAbove >= 0) {
|
||||
let actualAbove = 0;
|
||||
for (let i = 0; i < linesAbove; i++) {
|
||||
if (isBlankLine(lines[startLine - 2 - i])) {
|
||||
actualAbove++;
|
||||
}
|
||||
for (
|
||||
let i = 0;
|
||||
(i < linesAbove) && isBlankLine(lines[startLine - 2 - i]);
|
||||
i++
|
||||
) {
|
||||
actualAbove++;
|
||||
}
|
||||
addErrorDetailIf(
|
||||
onError,
|
||||
|
@ -50,19 +67,24 @@ module.exports = {
|
|||
line,
|
||||
null,
|
||||
{
|
||||
"insertText":
|
||||
getBlockQuote(lines[startLine - 2], linesAbove - actualAbove)
|
||||
"insertText": getBlockQuote(
|
||||
lines[startLine - 2],
|
||||
linesAbove - actualAbove
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Check lines below
|
||||
const linesBelow = getLinesBelow(heading);
|
||||
if (linesBelow >= 0) {
|
||||
let actualBelow = 0;
|
||||
for (let i = 0; i < linesBelow; i++) {
|
||||
if (isBlankLine(lines[endLine + i])) {
|
||||
actualBelow++;
|
||||
}
|
||||
for (
|
||||
let i = 0;
|
||||
(i < linesBelow) && isBlankLine(lines[endLine + i]);
|
||||
i++
|
||||
) {
|
||||
actualBelow++;
|
||||
}
|
||||
addErrorDetailIf(
|
||||
onError,
|
||||
|
@ -74,8 +96,10 @@ module.exports = {
|
|||
null,
|
||||
{
|
||||
"lineNumber": endLine + 1,
|
||||
"insertText":
|
||||
getBlockQuote(lines[endLine], linesBelow - actualBelow)
|
||||
"insertText": getBlockQuote(
|
||||
lines[endLine],
|
||||
linesBelow - actualBelow
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -229,13 +229,25 @@ for (const rule of rules) {
|
|||
scheme.properties = {
|
||||
"lines_above": {
|
||||
"description": "Blank lines above heading",
|
||||
"type": "integer",
|
||||
"type": [
|
||||
"integer",
|
||||
"array"
|
||||
],
|
||||
"items": {
|
||||
"type": "integer"
|
||||
},
|
||||
"minimum": -1,
|
||||
"default": 1
|
||||
},
|
||||
"lines_below": {
|
||||
"description": "Blank lines below heading",
|
||||
"type": "integer",
|
||||
"type": [
|
||||
"integer",
|
||||
"array"
|
||||
],
|
||||
"items": {
|
||||
"type": "integer"
|
||||
},
|
||||
"minimum": -1,
|
||||
"default": 1
|
||||
}
|
||||
|
|
|
@ -361,13 +361,25 @@
|
|||
"properties": {
|
||||
"lines_above": {
|
||||
"description": "Blank lines above heading",
|
||||
"type": "integer",
|
||||
"type": [
|
||||
"integer",
|
||||
"array"
|
||||
],
|
||||
"items": {
|
||||
"type": "integer"
|
||||
},
|
||||
"minimum": -1,
|
||||
"default": 1
|
||||
},
|
||||
"lines_below": {
|
||||
"description": "Blank lines below heading",
|
||||
"type": "integer",
|
||||
"type": [
|
||||
"integer",
|
||||
"array"
|
||||
],
|
||||
"items": {
|
||||
"type": "integer"
|
||||
},
|
||||
"minimum": -1,
|
||||
"default": 1
|
||||
}
|
||||
|
|
127
test/blanks-around-headings-arrays.md
Normal file
127
test/blanks-around-headings-arrays.md
Normal file
|
@ -0,0 +1,127 @@
|
|||
# Blanks Around Headings (Arrays)
|
||||
|
||||
# Apple - Good
|
||||
Text
|
||||
# Apple - Top {MD022}
|
||||
Text
|
||||
|
||||
# Apple - Bottom
|
||||
|
||||
Text
|
||||
|
||||
|
||||
## Banana - Good
|
||||
|
||||
|
||||
Text
|
||||
|
||||
## Banana - Top {MD022}
|
||||
|
||||
|
||||
Text
|
||||
|
||||
|
||||
## Banana - Bottom {MD022}
|
||||
|
||||
Text
|
||||
|
||||
|
||||
|
||||
### Cherry - Good
|
||||
|
||||
Text
|
||||
|
||||
|
||||
### Cherry - Top {MD022}
|
||||
|
||||
Text
|
||||
|
||||
|
||||
|
||||
### Cherry - Bottom {MD022}
|
||||
Text
|
||||
#### Durian - Good ####
|
||||
|
||||
|
||||
|
||||
Text
|
||||
|
||||
#### Durian - Top ####
|
||||
|
||||
|
||||
|
||||
Text
|
||||
#### Durian - Bottom {MD022} ####
|
||||
|
||||
Text
|
||||
|
||||
##### Elderberry - Good
|
||||
|
||||
Text
|
||||
##### Elderberry - Top {MD022}
|
||||
|
||||
Text
|
||||
|
||||
##### Elderberry - Bottom
|
||||
Text
|
||||
|
||||
###### Fig - Good ######
|
||||
|
||||
|
||||
|
||||
|
||||
Text
|
||||
###### Fig - Top {MD022} ######
|
||||
|
||||
|
||||
|
||||
|
||||
Text
|
||||
|
||||
###### Fig - Bottom {MD022} ######
|
||||
|
||||
Text
|
||||
|
||||
Grape - Good
|
||||
============
|
||||
|
||||
---
|
||||
Grape - Top {MD022}
|
||||
===================
|
||||
|
||||
Text
|
||||
|
||||
Grape - Bottom
|
||||
==============
|
||||
|
||||
|
||||
Text
|
||||
|
||||
|
||||
Honeycomb - Good
|
||||
---------
|
||||
|
||||
|
||||
Text
|
||||
|
||||
Honeycomb - Top {MD022}
|
||||
-----------------------
|
||||
|
||||
|
||||
Text
|
||||
|
||||
|
||||
Honeycomb - Bottom {MD022}
|
||||
--------------------------
|
||||
|
||||
Text
|
||||
|
||||
<!-- markdownlint-configure-file {
|
||||
"heading-style": false,
|
||||
"no-multiple-blanks": false,
|
||||
"single-title": false,
|
||||
"blanks-around-headings": {
|
||||
"lines_above": [ 1, 2, 3, -1],
|
||||
"lines_below": [ -1, 2, 1, 3, -1, 4, 10 ]
|
||||
}
|
||||
} -->
|
|
@ -919,7 +919,7 @@ test("readme", (t) => new Promise((resolve) => {
|
|||
}));
|
||||
|
||||
test("validateJsonUsingConfigSchemaStrict", (t) => {
|
||||
t.plan(158);
|
||||
t.plan(159);
|
||||
const configRe =
|
||||
/^[\s\S]*<!-- markdownlint-configure-file ([\s\S]*) -->[\s\S]*$/;
|
||||
const ignoreFiles = new Set([
|
||||
|
|
|
@ -4466,6 +4466,370 @@ Generated by [AVA](https://avajs.dev).
|
|||
`,
|
||||
}
|
||||
|
||||
## blanks-around-headings-arrays.md
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
{
|
||||
errors: [
|
||||
{
|
||||
errorContext: '# Apple - Top {MD022}',
|
||||
errorDetail: 'Expected: 1; Actual: 0; Above',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `␊
|
||||
`,
|
||||
},
|
||||
lineNumber: 5,
|
||||
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: '## Banana - Top {MD022}',
|
||||
errorDetail: 'Expected: 2; Actual: 1; Above',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `␊
|
||||
`,
|
||||
},
|
||||
lineNumber: 18,
|
||||
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: '## Banana - Bottom {MD022}',
|
||||
errorDetail: 'Expected: 2; Actual: 1; Below',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `␊
|
||||
`,
|
||||
lineNumber: 25,
|
||||
},
|
||||
lineNumber: 24,
|
||||
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: '### Cherry - Top {MD022}',
|
||||
errorDetail: 'Expected: 3; Actual: 2; Above',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `␊
|
||||
`,
|
||||
},
|
||||
lineNumber: 35,
|
||||
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: '### Cherry - Bottom {MD022}',
|
||||
errorDetail: 'Expected: 1; Actual: 0; Below',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `␊
|
||||
`,
|
||||
lineNumber: 42,
|
||||
},
|
||||
lineNumber: 41,
|
||||
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: '#### Durian - Bottom {MD022} ####',
|
||||
errorDetail: 'Expected: 3; Actual: 1; Below',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `␊
|
||||
␊
|
||||
`,
|
||||
lineNumber: 55,
|
||||
},
|
||||
lineNumber: 54,
|
||||
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: '##### Elderberry - Top {MD022}',
|
||||
errorDetail: 'Expected: 1; Actual: 0; Above',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `␊
|
||||
`,
|
||||
},
|
||||
lineNumber: 61,
|
||||
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: '###### Fig - Top {MD022} ######',
|
||||
errorDetail: 'Expected: 1; Actual: 0; Above',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `␊
|
||||
`,
|
||||
},
|
||||
lineNumber: 74,
|
||||
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: '###### Fig - Bottom {MD022} ######',
|
||||
errorDetail: 'Expected: 4; Actual: 1; Below',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `␊
|
||||
␊
|
||||
␊
|
||||
`,
|
||||
lineNumber: 82,
|
||||
},
|
||||
lineNumber: 81,
|
||||
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: 'Grape - Top {MD022}',
|
||||
errorDetail: 'Expected: 1; Actual: 0; Above',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `␊
|
||||
`,
|
||||
},
|
||||
lineNumber: 89,
|
||||
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: 'Honeycomb - Top {MD022}',
|
||||
errorDetail: 'Expected: 2; Actual: 1; Above',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `␊
|
||||
`,
|
||||
},
|
||||
lineNumber: 107,
|
||||
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: 'Honeycomb - Bottom {MD022}',
|
||||
errorDetail: 'Expected: 2; Actual: 1; Below',
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `␊
|
||||
`,
|
||||
lineNumber: 116,
|
||||
},
|
||||
lineNumber: 114,
|
||||
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',
|
||||
],
|
||||
},
|
||||
],
|
||||
fixed: `# Blanks Around Headings (Arrays)␊
|
||||
␊
|
||||
# Apple - Good␊
|
||||
Text␊
|
||||
␊
|
||||
# Apple - Top {MD022}␊
|
||||
Text␊
|
||||
␊
|
||||
# Apple - Bottom␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
␊
|
||||
## Banana - Good␊
|
||||
␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
␊
|
||||
## Banana - Top {MD022}␊
|
||||
␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
␊
|
||||
## Banana - Bottom {MD022}␊
|
||||
␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
␊
|
||||
␊
|
||||
### Cherry - Good␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
␊
|
||||
␊
|
||||
### Cherry - Top {MD022}␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
␊
|
||||
␊
|
||||
### Cherry - Bottom {MD022}␊
|
||||
␊
|
||||
Text␊
|
||||
#### Durian - Good ####␊
|
||||
␊
|
||||
␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
#### Durian - Top ####␊
|
||||
␊
|
||||
␊
|
||||
␊
|
||||
Text␊
|
||||
#### Durian - Bottom {MD022} ####␊
|
||||
␊
|
||||
␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
##### Elderberry - Good␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
##### Elderberry - Top {MD022}␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
##### Elderberry - Bottom␊
|
||||
Text␊
|
||||
␊
|
||||
###### Fig - Good ######␊
|
||||
␊
|
||||
␊
|
||||
␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
###### Fig - Top {MD022} ######␊
|
||||
␊
|
||||
␊
|
||||
␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
###### Fig - Bottom {MD022} ######␊
|
||||
␊
|
||||
␊
|
||||
␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
Grape - Good␊
|
||||
============␊
|
||||
␊
|
||||
---␊
|
||||
␊
|
||||
Grape - Top {MD022}␊
|
||||
===================␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
Grape - Bottom␊
|
||||
==============␊
|
||||
␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
␊
|
||||
Honeycomb - Good␊
|
||||
---------␊
|
||||
␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
␊
|
||||
Honeycomb - Top {MD022}␊
|
||||
-----------------------␊
|
||||
␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
␊
|
||||
Honeycomb - Bottom {MD022}␊
|
||||
--------------------------␊
|
||||
␊
|
||||
␊
|
||||
Text␊
|
||||
␊
|
||||
<!-- markdownlint-configure-file {␊
|
||||
"heading-style": false,␊
|
||||
"no-multiple-blanks": false,␊
|
||||
"single-title": false,␊
|
||||
"blanks-around-headings": {␊
|
||||
"lines_above": [ 1, 2, 3, -1],␊
|
||||
"lines_below": [ -1, 2, 1, 3, -1, 4, 10 ]␊
|
||||
}␊
|
||||
} -->␊
|
||||
`,
|
||||
}
|
||||
|
||||
## blanks-around-headings.md
|
||||
|
||||
> Snapshot 1
|
||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue