mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Add MD012, MD028 with tests, support multiple markers by line.
This commit is contained in:
parent
f35d690fb1
commit
c864ac1b96
4 changed files with 85 additions and 3 deletions
39
lib/rules.js
39
lib/rules.js
|
@ -212,6 +212,45 @@ module.exports = [
|
|||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "MD012",
|
||||
"desc": "Multiple consecutive blank lines",
|
||||
"func": function MD012(params, errors) {
|
||||
var exclusions = [];
|
||||
params.tokens.filter(function filterToken(token) {
|
||||
return ((token.type === "code_block") || (token.type === "fence"));
|
||||
}).forEach(function forToken(token) {
|
||||
for (var i = token.lines[0] ; i < token.lines[1] ; i++) {
|
||||
exclusions.push(i);
|
||||
}
|
||||
});
|
||||
var prevLine = "-";
|
||||
params.lines.forEach(function forLine(line, lineIndex) {
|
||||
line = line.trim();
|
||||
if (!line.length && !prevLine.length &&
|
||||
(exclusions.indexOf(lineIndex) === -1)) {
|
||||
errors.push(lineIndex + 1);
|
||||
}
|
||||
prevLine = line;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "MD028",
|
||||
"desc": "Blank line inside blockquote",
|
||||
"func": function MD028(params, errors) {
|
||||
var prevToken = {};
|
||||
params.tokens.forEach(function forToken(token) {
|
||||
if ((token.type === "blockquote_open") &&
|
||||
(prevToken.type === "blockquote_close")) {
|
||||
errors.push(token.lineNumber - 1);
|
||||
}
|
||||
prevToken = token;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "MD031",
|
||||
"desc": "Fenced code blocks should be surrounded by blank lines",
|
||||
|
|
31
test/blockquote_blank_lines.md
Normal file
31
test/blockquote_blank_lines.md
Normal file
|
@ -0,0 +1,31 @@
|
|||
Some text
|
||||
|
||||
> a quote
|
||||
> same quote
|
||||
|
||||
> blank line above me
|
||||
|
||||
|
||||
> two blank lines above me
|
||||
|
||||
> space above me
|
||||
|
||||
* List with embedded blockquote
|
||||
|
||||
> Test
|
||||
> Test
|
||||
|
||||
> Test
|
||||
|
||||
* Item 2
|
||||
|
||||
> Test. The blank line below should _not_ trigger MD028 as one blockquote is
|
||||
> inside the list, and the other is outside it.
|
||||
|
||||
> Test
|
||||
|
||||
Expected errors:
|
||||
|
||||
{MD028:5} {MD028:8} {MD028:10} {MD028:17}
|
||||
{MD009:10} (trailing space is intentional)
|
||||
{MD012:8} (multiple blank lines are intentional)
|
11
test/consecutive_blank_lines.md
Normal file
11
test/consecutive_blank_lines.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
Some text
|
||||
|
||||
|
||||
Some text {MD012:3}
|
||||
|
||||
This is a code block
|
||||
|
||||
|
||||
with two blank lines in it
|
||||
|
||||
Some more text
|
|
@ -34,11 +34,12 @@ function createTestForFile(file) {
|
|||
var lines = contents.split(/\r\n|\r|\n/g);
|
||||
var results = {};
|
||||
lines.forEach(function forLine(line, lineNum) {
|
||||
var match = line.match(/\{(MD\d+)(?::(\d+))?\}/);
|
||||
if (match) {
|
||||
var regex = /\{(MD\d+)(?::(\d+))?\}/g;
|
||||
var match;
|
||||
while ((match = regex.exec(line))) {
|
||||
var rule = match[1];
|
||||
var errors = results[rule] || [];
|
||||
errors.push(lineNum + 1);
|
||||
errors.push(match[2] ? parseInt(match[2], 10) : lineNum + 1);
|
||||
results[rule] = errors;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue