Add MD022 with tests, create shared module.

This commit is contained in:
David Anson 2015-03-08 23:08:43 -07:00
parent 5591cf4587
commit 9bedd25234
7 changed files with 75 additions and 3 deletions

View file

@ -1,5 +1,7 @@
"use strict";
var shared = require("./shared");
function indentFor(token) {
return token.line.length - token.line.trimLeft().length;
}
@ -253,7 +255,7 @@ module.exports = [
filterTokens(params.tokens, "code_block", "fence")
.forEach(function forToken(token) {
if (token.content && token.content
.split(/\r\n|\r|\n/)
.split(shared.newLineRe)
.filter(function filterLine(line) {
return line;
}).every(function forLine(line) {
@ -318,6 +320,42 @@ module.exports = [
}
},
{
"name": "MD022",
"desc": "Headers should be surrounded by blank lines",
"func": function MD022(params, errors) {
var prevHeadingLineNumber = 0;
var prevMaxLineIndex = -1;
var needBlankLine = false;
params.tokens.forEach(function forToken(token) {
if (token.type === "heading_open") {
if ((token.lines[0] - prevMaxLineIndex) === 0) {
errors.push(token.lineNumber);
}
prevHeadingLineNumber = token.lineNumber;
} else if (token.type === "heading_close") {
needBlankLine = true;
} else if (token.type === "inline") {
token.content.split(shared.newLineRe)
.forEach(function forLine(line, offset) {
if (/^(-+|=+)\s*$/.test(line)) {
errors.push(token.lines[0] + offset);
}
});
}
if (token.lines) {
if (needBlankLine) {
if ((token.lines[0] - prevMaxLineIndex) === 0) {
errors.push(prevHeadingLineNumber);
}
needBlankLine = false;
}
prevMaxLineIndex = Math.max(prevMaxLineIndex, token.lines[1]);
}
});
}
},
{
"name": "MD028",
"desc": "Blank line inside blockquote",