mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-01-04 23:18:49 +01:00
Update to markdownlint-micromark@0.1.2, include gfmTable extension, change matchAndGetTokensByType return value, include .cjs files when linting.
This commit is contained in:
parent
60ad79fd2b
commit
b787758a48
6 changed files with 32 additions and 31 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@
|
|||
"engines": {
|
||||
"node": ">=14.18.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"markdownlint-micromark": "0.1.2"
|
||||
},
|
||||
"keywords": [
|
||||
"markdownlint",
|
||||
"markdownlint-rule"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue