2015-02-23 23:39:20 -08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
function padAndTrim(lines) {
|
|
|
|
return [].concat(
|
|
|
|
"",
|
2015-02-24 18:40:37 -08:00
|
|
|
lines.map(function mapLine(line) {
|
2015-02-23 23:39:20 -08:00
|
|
|
return line.trim();
|
|
|
|
}),
|
|
|
|
"");
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2015-02-24 18:40:37 -08:00
|
|
|
"MD031": function MD031(lines) {
|
2015-02-23 23:39:20 -08:00
|
|
|
// Some parsers have trouble detecting fenced code blocks without
|
|
|
|
// surrounding whitespace, so examine the lines directly.
|
|
|
|
lines = padAndTrim(lines);
|
|
|
|
var errors = [];
|
|
|
|
var inCode = false;
|
2015-02-24 18:40:37 -08:00
|
|
|
lines.forEach(function forLine(line, lineNum) {
|
2015-02-23 23:39:20 -08:00
|
|
|
if (line.match(/^(```|~~~)/)) {
|
|
|
|
inCode = !inCode;
|
|
|
|
if ((inCode && lines[lineNum - 1].length) ||
|
|
|
|
(!inCode && lines[lineNum + 1].length)) {
|
|
|
|
errors.push(lineNum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return errors;
|
2015-02-24 23:35:34 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
"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;
|
2015-02-23 23:39:20 -08:00
|
|
|
}
|
|
|
|
};
|