2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2018-04-27 22:05:34 -07:00
|
|
|
const shared = require("./shared");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
2018-04-27 22:05:34 -07:00
|
|
|
const spaceAfterBlockQuote = /^\s*(?:>\s+)+\S/;
|
2018-01-21 21:44:25 -08:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
"names": [ "MD027", "no-multiple-space-blockquote" ],
|
|
|
|
"description": "Multiple spaces after blockquote symbol",
|
|
|
|
"tags": [ "blockquote", "whitespace", "indentation" ],
|
|
|
|
"function": function MD027(params, onError) {
|
2018-04-27 22:05:34 -07:00
|
|
|
let blockquoteNesting = 0;
|
|
|
|
let listItemNesting = 0;
|
2018-01-21 21:44:25 -08:00
|
|
|
params.tokens.forEach(function forToken(token) {
|
|
|
|
if (token.type === "blockquote_open") {
|
|
|
|
blockquoteNesting++;
|
|
|
|
} else if (token.type === "blockquote_close") {
|
|
|
|
blockquoteNesting--;
|
|
|
|
} else if (token.type === "list_item_open") {
|
|
|
|
listItemNesting++;
|
|
|
|
} else if (token.type === "list_item_close") {
|
|
|
|
listItemNesting--;
|
|
|
|
} else if ((token.type === "inline") && (blockquoteNesting > 0)) {
|
2018-04-27 22:05:34 -07:00
|
|
|
const multipleSpaces = listItemNesting ?
|
2018-01-21 21:44:25 -08:00
|
|
|
/^(\s*>)+\s\s+>/.test(token.line) :
|
|
|
|
/^(\s*>)+\s\s/.test(token.line);
|
|
|
|
if (multipleSpaces) {
|
|
|
|
shared.addErrorContext(onError, token.lineNumber, token.line, null,
|
|
|
|
null, shared.rangeFromRegExp(token.line, spaceAfterBlockQuote));
|
|
|
|
}
|
|
|
|
token.content.split(shared.newLineRe)
|
|
|
|
.forEach(function forLine(line, offset) {
|
|
|
|
if (/^\s/.test(line)) {
|
|
|
|
shared.addErrorContext(onError, token.lineNumber + offset,
|
|
|
|
"> " + line, null, null,
|
|
|
|
shared.rangeFromRegExp(line, spaceAfterBlockQuote));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|