2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
2019-09-09 22:03:59 -07:00
|
|
|
const { addErrorContext, newLineRe } = require("../helpers");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
2019-09-09 22:03:59 -07:00
|
|
|
const spaceAfterBlockQuoteRe = /^((?:\s*>)+)(\s{2,})\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;
|
2023-02-18 21:41:07 -08:00
|
|
|
for (const token of params.parsers.markdownit.tokens) {
|
2019-09-09 22:03:59 -07:00
|
|
|
const { content, lineNumber, type } = token;
|
|
|
|
|
if (type === "blockquote_open") {
|
2018-01-21 21:44:25 -08:00
|
|
|
blockquoteNesting++;
|
2019-09-09 22:03:59 -07:00
|
|
|
} else if (type === "blockquote_close") {
|
2018-01-21 21:44:25 -08:00
|
|
|
blockquoteNesting--;
|
2019-09-09 22:03:59 -07:00
|
|
|
} else if (type === "list_item_open") {
|
2018-01-21 21:44:25 -08:00
|
|
|
listItemNesting++;
|
2019-09-09 22:03:59 -07:00
|
|
|
} else if (type === "list_item_close") {
|
2018-01-21 21:44:25 -08:00
|
|
|
listItemNesting--;
|
2019-09-09 22:03:59 -07:00
|
|
|
} else if ((type === "inline") && blockquoteNesting) {
|
|
|
|
|
const lineCount = content.split(newLineRe).length;
|
|
|
|
|
for (let i = 0; i < lineCount; i++) {
|
|
|
|
|
const line = params.lines[lineNumber + i - 1];
|
|
|
|
|
const match = line.match(spaceAfterBlockQuoteRe);
|
|
|
|
|
if (match) {
|
|
|
|
|
const [
|
|
|
|
|
fullMatch,
|
|
|
|
|
{ "length": blockquoteLength },
|
|
|
|
|
{ "length": spaceLength }
|
|
|
|
|
] = match;
|
|
|
|
|
if (!listItemNesting || (fullMatch[fullMatch.length - 1] === ">")) {
|
|
|
|
|
addErrorContext(
|
|
|
|
|
onError,
|
|
|
|
|
lineNumber + i,
|
|
|
|
|
line,
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
[ 1, fullMatch.length ],
|
|
|
|
|
{
|
|
|
|
|
"editColumn": blockquoteLength + 1,
|
|
|
|
|
"deleteCount": spaceLength - 1
|
|
|
|
|
}
|
|
|
|
|
);
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
2019-09-09 22:03:59 -07:00
|
|
|
}
|
|
|
|
|
}
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
2022-06-08 22:10:27 -07:00
|
|
|
}
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
|
};
|