Add Rule.parser property for custom rules to specify which Markdown parser output they use, honor it strictly, and add full type support.

This commit is contained in:
David Anson 2024-03-09 16:17:50 -08:00
parent d2acc168d2
commit d5994ae4de
68 changed files with 635 additions and 115 deletions

View file

@ -29,6 +29,7 @@ module.exports = {
"names": [ "every-n-lines" ],
"description": "Rule that reports an error every N lines",
"tags": [ "test" ],
"parser": "none",
"function": (params, onError) => {
const n = params.config.n || 2;
forEachLine(getLineMetadata(params), (line, lineIndex) => {

View file

@ -702,10 +702,10 @@ module.exports.frontMatterHasTitle =
/**
* Returns an object with information about reference links and images.
*
* @param {Object} params RuleParams instance.
* @param {import("../helpers/micromark.cjs").Token[]} tokens Micromark tokens.
* @returns {Object} Reference link/image data.
*/
function getReferenceLinkImageData(params) {
function getReferenceLinkImageData(tokens) {
const normalizeReference = (s) => s.toLowerCase().trim().replace(/\s+/g, " ");
const definitions = new Map();
const definitionLineIndices = [];
@ -714,7 +714,7 @@ function getReferenceLinkImageData(params) {
const shortcuts = new Map();
const filteredTokens =
micromark.filterByTypes(
params.parsers.micromark.tokens,
tokens,
[
// definitionLineIndices
"definition", "gfmFootnoteDefinition",

View file

@ -15,20 +15,7 @@ const flatTokensSymbol = Symbol("flat-tokens");
/** @typedef {import("markdownlint-micromark").Event} Event */
/** @typedef {import("markdownlint-micromark").ParseOptions} ParseOptions */
/** @typedef {import("markdownlint-micromark").TokenType} TokenType */
/**
* Markdown token.
*
* @typedef {Object} Token
* @property {TokenType} type Token type.
* @property {number} startLine Start line (1-based).
* @property {number} startColumn Start column (1-based).
* @property {number} endLine End line (1-based).
* @property {number} endColumn End column (1-based).
* @property {string} text Token text.
* @property {Token[]} children Child tokens.
* @property {Token | null} parent Parent token.
*/
/** @typedef {import("../lib/markdownlint.js").MicromarkToken} Token */
/**
* Returns whether a token is an htmlFlow type containing an HTML comment.