mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Add basic infrastructure, MD031, and test.
This commit is contained in:
parent
cdec362dc0
commit
d16e1cafc1
5 changed files with 136 additions and 1 deletions
30
lib/rules.js
Normal file
30
lib/rules.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
"use strict";
|
||||
|
||||
function padAndTrim(lines) {
|
||||
return [].concat(
|
||||
"",
|
||||
lines.map(function(line) {
|
||||
return line.trim();
|
||||
}),
|
||||
"");
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
MD031: function(lines) {
|
||||
// Some parsers have trouble detecting fenced code blocks without
|
||||
// surrounding whitespace, so examine the lines directly.
|
||||
lines = padAndTrim(lines);
|
||||
var errors = [];
|
||||
var inCode = false;
|
||||
lines.forEach(function(line, lineNum) {
|
||||
if (line.match(/^(```|~~~)/)) {
|
||||
inCode = !inCode;
|
||||
if ((inCode && lines[lineNum - 1].length) ||
|
||||
(!inCode && lines[lineNum + 1].length)) {
|
||||
errors.push(lineNum);
|
||||
}
|
||||
}
|
||||
});
|
||||
return errors;
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue