Update to markdownlint-micromark@0.1.2, include gfmTable extension, change matchAndGetTokensByType return value, include .cjs files when linting.

This commit is contained in:
David Anson 2023-02-23 22:14:44 -08:00
parent 60ad79fd2b
commit b787758a48
6 changed files with 32 additions and 31 deletions

View file

@ -862,7 +862,7 @@ function getReferenceLinkImageData(params) {
if (shortcutCandidate) {
labelText =
micromark.getTokenTextByType(
shortcutCandidate.label.tokens, "labelText"
shortcutCandidate[0].tokens, "labelText"
);
isShortcut = (labelText !== null);
}
@ -873,11 +873,11 @@ function getReferenceLinkImageData(params) {
if (fullAndCollapsedCandidate) {
labelText =
micromark.getTokenTextByType(
fullAndCollapsedCandidate.label.tokens, "labelText"
fullAndCollapsedCandidate[0].tokens, "labelText"
);
referenceStringText =
micromark.getTokenTextByType(
fullAndCollapsedCandidate.reference.tokens, "referenceString"
fullAndCollapsedCandidate[1].tokens, "referenceString"
);
isFullOrCollapsed = (labelText !== null);
}
@ -890,8 +890,8 @@ function getReferenceLinkImageData(params) {
[ "gfmFootnoteCallMarker", "gfmFootnoteCallString" ]
);
if (footnote) {
const callMarkerText = footnote.gfmFootnoteCallMarker.text;
const callString = footnote.gfmFootnoteCallString.text;
const callMarkerText = footnote[0].text;
const callString = footnote[1].text;
labelText = `${callMarkerText}${callString}`;
isShortcut = true;
}

View file

@ -2,12 +2,11 @@
"use strict";
/* eslint-disable n/no-unpublished-require */
// @ts-ignore
const { gfmAutolinkLiteral, gfmFootnote, parse, postprocess, preprocess } =
const {
gfmAutolinkLiteral, gfmFootnote, gfmTable, parse, postprocess, preprocess
// @ts-ignore
require("markdownlint-micromark");
} = require("markdownlint-micromark");
/**
* Markdown token.
@ -33,7 +32,7 @@ function getMicromarkEvents(markdown, options = {}) {
// Customize options object to add useful extensions
options.extensions ||= [];
options.extensions.push(gfmAutolinkLiteral, gfmFootnote());
options.extensions.push(gfmAutolinkLiteral, gfmFootnote(), gfmTable);
// Use micromark to parse document into Events
const encoding = undefined;
@ -153,7 +152,7 @@ function getHtmlTagInfo(token) {
return {
close,
"name": close ? name.slice(1) : name
}
};
}
}
return null;
@ -177,19 +176,20 @@ function getTokenTextByType(tokens, type) {
* @param {Token[]} tokens Micromark tokens.
* @param {string[]} matchTypes Types to match.
* @param {string[]} [resultTypes] Types to return.
* @returns {Object | null} Matching tokens by type.
* @returns {Token[] | null} Matching tokens.
*/
function matchAndGetTokensByType(tokens, matchTypes, resultTypes) {
if (tokens.length !== matchTypes.length) {
return null;
}
resultTypes ||= matchTypes;
const result = {};
const result = [];
// eslint-disable-next-line unicorn/no-for-loop
for (let i = 0; i < matchTypes.length; i++) {
if (tokens[i].type !== matchTypes[i]) {
return null;
} else if (resultTypes.includes(matchTypes[i])) {
result[matchTypes[i]] = tokens[i];
result.push(tokens[i]);
}
}
return result;

View file

@ -15,6 +15,9 @@
"engines": {
"node": ">=14.18.0"
},
"dependencies": {
"markdownlint-micromark": "0.1.2"
},
"keywords": [
"markdownlint",
"markdownlint-rule"