Allow '0'- and ' '-prefixed ordered list markers in MD005/MD029 (fixes #126).

This commit is contained in:
David Anson 2018-06-15 22:37:12 -07:00
parent 2710c375b3
commit 4a1e42d942
7 changed files with 190 additions and 8 deletions

View file

@ -10,10 +10,32 @@ module.exports = {
"tags": [ "bullet", "ul", "indentation" ],
"function": function MD005(params, onError) {
shared.flattenLists().forEach(function forList(list) {
const expectedIndent = list.indent;
let expectedEnd = 0;
let actualEnd = -1;
let endMatching = false;
list.items.forEach(function forItem(item) {
shared.addErrorDetailIf(onError, item.lineNumber, list.indent,
shared.indentFor(item), null,
shared.rangeFromRegExp(item.line, shared.listItemMarkerRe));
const actualIndent = shared.indentFor(item);
if (list.unordered) {
shared.addErrorDetailIf(onError, item.lineNumber,
expectedIndent, actualIndent, null,
shared.rangeFromRegExp(item.line, shared.listItemMarkerRe));
} else {
const match = shared.orderedListItemMarkerRe.exec(item.line);
actualEnd = match && match[0].length;
expectedEnd = expectedEnd || actualEnd;
if ((expectedIndent !== actualIndent) || endMatching) {
if (expectedEnd === actualEnd) {
endMatching = true;
} else {
const detail = endMatching ?
`Expected: (${expectedEnd}); Actual: (${actualEnd})` :
`Expected: ${expectedIndent}; Actual: ${actualIndent}`;
shared.addError(onError, item.lineNumber, detail, null,
shared.rangeFromRegExp(item.line, shared.listItemMarkerRe));
}
}
}
});
});
}

View file

@ -4,8 +4,6 @@
const shared = require("./shared");
const numberRe = /^[\s>]*([^.)]*)[.)]/;
module.exports = {
"names": [ "MD029", "ol-prefix" ],
"description": "Ordered list item prefix",
@ -17,12 +15,12 @@ module.exports = {
let listStyle = style;
if (listStyle === "one_or_ordered") {
const second = (list.items.length > 1) &&
numberRe.exec(list.items[1].line);
shared.orderedListItemMarkerRe.exec(list.items[1].line);
listStyle = (second && (second[1] !== "1")) ? "ordered" : "one";
}
let number = 1;
list.items.forEach(function forItem(item) {
const match = numberRe.exec(item.line);
const match = shared.orderedListItemMarkerRe.exec(item.line);
shared.addErrorDetailIf(onError, item.lineNumber,
String(number), !match || match[1],
"Style: " + (listStyle === "one" ? "1/1/1" : "1/2/3"),

View file

@ -17,7 +17,8 @@ module.exports.inlineCommentRe = inlineCommentRe;
// Regular expressions for range matching
module.exports.atxHeadingSpaceRe = /^#+\s*\S/;
module.exports.bareUrlRe = /(?:http|ftp)s?:\/\/[^\s]*/i;
module.exports.listItemMarkerRe = /^[\s>]*(?:[*+-]|\d+\.)\s+/;
module.exports.listItemMarkerRe = /^[\s>]*(?:[*+-]|\d+[.)])\s+/;
module.exports.orderedListItemMarkerRe = /^[\s>]*0*(\d+)[.)]/;
// readFile options for reading with the UTF-8 encoding
module.exports.utf8Encoding = { "encoding": "utf8" };