Add MD032 with tests, improve infrastructure.

This commit is contained in:
David Anson 2015-02-24 23:35:34 -08:00
parent 160146ac3a
commit aef1524308
3 changed files with 111 additions and 1 deletions

View file

@ -26,5 +26,31 @@ module.exports = {
}
});
return errors;
},
"MD032": function MD032(lines) {
// Some parsers have trouble detecting lists without surrounding
// whitespace, so examine the lines directly.
var errors = [];
var inList = false;
var inCode = false;
var prevLine = "";
lines.forEach(function forLine(line, lineNum) {
if (!inCode) {
var listMarker = line.trim().match(/^([\*\+\-]|(\d+\.))\s/);
if (listMarker && !inList && !prevLine.match(/^($|\s)/)) {
errors.push(lineNum + 1);
} else if (!listMarker && inList && !line.match(/^($|\s)/)) {
errors.push(lineNum);
}
inList = listMarker;
}
if (line.trim().match(/^(```|~~~)/)) {
inCode = !inCode;
inList = false;
}
prevLine = line;
});
return errors;
}
};