2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2019-04-13 11:18:57 -07:00
|
|
|
const { addError } = require("../helpers");
|
2024-02-26 21:07:24 -08:00
|
|
|
const { filterByTypes } = require("../helpers/micromark.cjs");
|
|
|
|
|
|
|
|
const ignoreTypes = new Set([ "lineEnding", "listItemIndent", "linePrefix" ]);
|
2018-01-21 21:44:25 -08:00
|
|
|
|
2024-02-27 20:42:09 -08:00
|
|
|
// eslint-disable-next-line jsdoc/valid-types
|
|
|
|
/** @type import("./markdownlint").Rule */
|
2018-01-21 21:44:25 -08:00
|
|
|
module.exports = {
|
|
|
|
"names": [ "MD028", "no-blanks-blockquote" ],
|
|
|
|
"description": "Blank line inside blockquote",
|
|
|
|
"tags": [ "blockquote", "whitespace" ],
|
2024-03-09 16:17:50 -08:00
|
|
|
"parser": "micromark",
|
2018-01-21 21:44:25 -08:00
|
|
|
"function": function MD028(params, onError) {
|
2024-02-28 21:01:23 -08:00
|
|
|
// eslint-disable-next-line jsdoc/valid-types
|
|
|
|
/** @type import("../helpers/micromark.cjs").Token[] */
|
|
|
|
const micromarkTokens =
|
|
|
|
// @ts-ignore
|
|
|
|
params.parsers.micromark.tokens;
|
|
|
|
for (const token of filterByTypes(micromarkTokens, [ "blockQuote" ])) {
|
2024-02-26 21:07:24 -08:00
|
|
|
const errorLineNumbers = [];
|
2024-02-28 21:01:23 -08:00
|
|
|
const siblings = token.parent?.children || micromarkTokens;
|
2024-02-26 21:07:24 -08:00
|
|
|
for (let i = siblings.indexOf(token) + 1; i < siblings.length; i++) {
|
|
|
|
const sibling = siblings[i];
|
|
|
|
const { startLine, type } = sibling;
|
|
|
|
if (type === "lineEndingBlank") {
|
|
|
|
// Possible blank between blockquotes
|
|
|
|
errorLineNumbers.push(startLine);
|
|
|
|
} else if (ignoreTypes.has(type)) {
|
|
|
|
// Ignore invisible formatting
|
|
|
|
} else if (type === "blockQuote") {
|
|
|
|
// Blockquote followed by blockquote
|
|
|
|
for (const lineNumber of errorLineNumbers) {
|
|
|
|
addError(onError, lineNumber);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
// Blockquote not followed by blockquote
|
|
|
|
break;
|
2019-08-24 22:55:51 -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
|
|
|
}
|
|
|
|
};
|