mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-18 06:50:12 +01:00
Everything under `lib/rules/*` is a rules file (with the name of the rule in camelCase), re-exported into an array in `lib/rules.js`. Moved the regular expressions from `lib/rules.js` to `lib/expressions.js`, and the rest of the variables into `lib/shared.js`.
33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
var shared = require("../shared");
|
|
var expressions = require("../expressions");
|
|
|
|
module.exports = {
|
|
"name": "MD032",
|
|
"desc": "Lists should be surrounded by blank lines",
|
|
"tags": [ "bullet", "ul", "ol", "blank_lines" ],
|
|
"aliases": [ "blanks-around-lists" ],
|
|
"regexp": null,
|
|
"func": function MD032(params, errors) {
|
|
var blankOrListRe = /^[\s>]*($|\s)/;
|
|
var inList = false;
|
|
var prevLine = "";
|
|
shared.forEachLine(params, function forLine(line, lineIndex, inCode, onFence) {
|
|
if (!inCode || onFence) {
|
|
var lineTrim = line.trim();
|
|
var listMarker = expressions.listItemMarkerRe.test(lineTrim);
|
|
if (listMarker && !inList && !blankOrListRe.test(prevLine)) {
|
|
// Check whether this list prefix can interrupt a paragraph
|
|
if (expressions.listItemMarkerInterruptsRe.test(lineTrim)) {
|
|
errors.addContext(lineIndex + 1, lineTrim);
|
|
} else {
|
|
listMarker = false;
|
|
}
|
|
} else if (!listMarker && inList && !blankOrListRe.test(line)) {
|
|
errors.addContext(lineIndex, lineTrim);
|
|
}
|
|
inList = listMarker;
|
|
}
|
|
prevLine = line;
|
|
});
|
|
}
|
|
};
|