2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
2024-11-28 20:36:44 -08:00
|
|
|
import { addErrorContext } from "../helpers/helpers.cjs";
|
2025-03-03 23:22:28 -08:00
|
|
|
import { getParentOfType } from "../helpers/micromark-helpers.cjs";
|
2024-11-28 20:36:44 -08:00
|
|
|
import { filterByTypesCached } from "./cache.mjs";
|
2018-01-21 21:44:25 -08:00
|
|
|
|
2025-03-03 23:22:28 -08:00
|
|
|
/** @type {import("../helpers/micromark-helpers.cjs").TokenType[]} */
|
|
|
|
const listTypes = [ "listOrdered", "listUnordered" ];
|
|
|
|
|
2024-12-03 19:58:28 -08:00
|
|
|
/** @type {import("markdownlint").Rule} */
|
2024-11-28 20:36:44 -08:00
|
|
|
export default {
|
2024-09-01 16:16:05 -07:00
|
|
|
"names": [ "MD027", "no-multiple-space-blockquote" ],
|
2018-01-21 21:44:25 -08:00
|
|
|
"description": "Multiple spaces after blockquote symbol",
|
2024-09-01 16:16:05 -07:00
|
|
|
"tags": [ "blockquote", "whitespace", "indentation" ],
|
2024-03-09 16:17:50 -08:00
|
|
|
"parser": "micromark",
|
2018-01-21 21:44:25 -08:00
|
|
|
"function": function MD027(params, onError) {
|
2025-03-03 23:22:28 -08:00
|
|
|
const listItems = params.config.list_items;
|
|
|
|
const includeListItems = (listItems === undefined) ? true : !!listItems;
|
2024-10-28 21:40:39 -07:00
|
|
|
const { tokens } = params.parsers.micromark;
|
2024-08-24 22:05:16 -07:00
|
|
|
for (const token of filterByTypesCached([ "linePrefix" ])) {
|
2024-10-28 21:40:39 -07:00
|
|
|
const parent = token.parent;
|
|
|
|
const codeIndented = parent?.type === "codeIndented";
|
|
|
|
const siblings = parent?.children || tokens;
|
|
|
|
if (
|
|
|
|
!codeIndented &&
|
2025-03-03 23:22:28 -08:00
|
|
|
(siblings[siblings.indexOf(token) - 1]?.type === "blockQuotePrefix") &&
|
|
|
|
(includeListItems || (
|
|
|
|
!listTypes.includes(siblings[siblings.indexOf(token) + 1]?.type) &&
|
|
|
|
!getParentOfType(token, listTypes)
|
|
|
|
))
|
2024-10-28 21:40:39 -07:00
|
|
|
) {
|
2024-02-26 21:07:24 -08:00
|
|
|
const { startColumn, startLine, text } = token;
|
|
|
|
const { length } = text;
|
|
|
|
const line = params.lines[startLine - 1];
|
|
|
|
addErrorContext(
|
|
|
|
onError,
|
|
|
|
startLine,
|
|
|
|
line,
|
2024-06-21 21:03:30 -07:00
|
|
|
undefined,
|
|
|
|
undefined,
|
2024-02-26 21:07:24 -08:00
|
|
|
[ startColumn, length ],
|
|
|
|
{
|
|
|
|
"editColumn": startColumn,
|
|
|
|
"deleteCount": length
|
|
|
|
}
|
|
|
|
);
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
2022-06-08 22:10:27 -07:00
|
|
|
}
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
};
|