mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02: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
|
@ -63,7 +63,7 @@
|
|||
}
|
||||
],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2020,
|
||||
"ecmaVersion": 2021,
|
||||
"sourceType": "script"
|
||||
},
|
||||
"plugins": [
|
||||
|
|
|
@ -952,19 +952,19 @@ function getReferenceLinkImageData(params) {
|
|||
var referenceStringText = null;
|
||||
var shortcutCandidate = micromark.matchAndGetTokensByType(token.tokens, ["label"]);
|
||||
if (shortcutCandidate) {
|
||||
labelText = micromark.getTokenTextByType(shortcutCandidate.label.tokens, "labelText");
|
||||
labelText = micromark.getTokenTextByType(shortcutCandidate[0].tokens, "labelText");
|
||||
isShortcut = labelText !== null;
|
||||
}
|
||||
var fullAndCollapsedCandidate = micromark.matchAndGetTokensByType(token.tokens, ["label", "reference"]);
|
||||
if (fullAndCollapsedCandidate) {
|
||||
labelText = micromark.getTokenTextByType(fullAndCollapsedCandidate.label.tokens, "labelText");
|
||||
referenceStringText = micromark.getTokenTextByType(fullAndCollapsedCandidate.reference.tokens, "referenceString");
|
||||
labelText = micromark.getTokenTextByType(fullAndCollapsedCandidate[0].tokens, "labelText");
|
||||
referenceStringText = micromark.getTokenTextByType(fullAndCollapsedCandidate[1].tokens, "referenceString");
|
||||
isFullOrCollapsed = labelText !== null;
|
||||
}
|
||||
var footnote = micromark.matchAndGetTokensByType(token.tokens, ["gfmFootnoteCallLabelMarker", "gfmFootnoteCallMarker", "gfmFootnoteCallString", "gfmFootnoteCallLabelMarker"], ["gfmFootnoteCallMarker", "gfmFootnoteCallString"]);
|
||||
if (footnote) {
|
||||
var callMarkerText = footnote.gfmFootnoteCallMarker.text;
|
||||
var callString = footnote.gfmFootnoteCallString.text;
|
||||
var callMarkerText = footnote[0].text;
|
||||
var callString = footnote[1].text;
|
||||
labelText = "".concat(callMarkerText).concat(callString);
|
||||
isShortcut = true;
|
||||
}
|
||||
|
@ -1425,8 +1425,6 @@ module.exports = {
|
|||
|
||||
|
||||
|
||||
/* eslint-disable n/no-unpublished-require */
|
||||
|
||||
// @ts-ignore
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
||||
|
@ -1439,11 +1437,10 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|||
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
||||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
||||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
||||
var _require =
|
||||
// @ts-ignore
|
||||
__webpack_require__(/*! markdownlint-micromark */ "markdownlint-micromark"),
|
||||
var _require = __webpack_require__(/*! markdownlint-micromark */ "markdownlint-micromark"),
|
||||
gfmAutolinkLiteral = _require.gfmAutolinkLiteral,
|
||||
gfmFootnote = _require.gfmFootnote,
|
||||
gfmTable = _require.gfmTable,
|
||||
parse = _require.parse,
|
||||
postprocess = _require.postprocess,
|
||||
preprocess = _require.preprocess;
|
||||
|
@ -1472,7 +1469,7 @@ function getMicromarkEvents(markdown) {
|
|||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
// Customize options object to add useful extensions
|
||||
options.extensions || (options.extensions = []);
|
||||
options.extensions.push(gfmAutolinkLiteral, gfmFootnote());
|
||||
options.extensions.push(gfmAutolinkLiteral, gfmFootnote(), gfmTable);
|
||||
|
||||
// Use micromark to parse document into Events
|
||||
var encoding = undefined;
|
||||
|
@ -1635,19 +1632,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 || (resultTypes = matchTypes);
|
||||
var result = {};
|
||||
var result = [];
|
||||
// eslint-disable-next-line unicorn/no-for-loop
|
||||
for (var 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;
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
"example": "cd example && node standalone.js && grunt markdownlint --force && gulp markdownlint",
|
||||
"docker-npm-install": "docker run --rm --tty --name npm-install --volume $PWD:/home/workdir --workdir /home/workdir --user node node:16 npm install",
|
||||
"docker-npm-run-upgrade": "docker run --rm --tty --name npm-run-upgrade --volume $PWD:/home/workdir --workdir /home/workdir --user node node:16 npm run upgrade",
|
||||
"lint": "eslint --ext .js,.mjs --max-warnings 0 .",
|
||||
"lint": "eslint --ext .js,.cjs,.mjs --max-warnings 0 .",
|
||||
"lint-test-repos": "ava --timeout=5m test/markdownlint-test-repos.js",
|
||||
"serial-config-docs": "npm run build-config && npm run build-docs",
|
||||
"serial-declaration-demo": "npm run build-declaration && npm-run-all --continue-on-error --parallel build-demo test-declaration",
|
||||
|
@ -83,7 +83,7 @@
|
|||
"markdown-it-sub": "1.0.0",
|
||||
"markdown-it-sup": "1.0.0",
|
||||
"markdown-it-texmath": "1.0.0",
|
||||
"markdownlint-micromark": "0.1.1",
|
||||
"markdownlint-micromark": "0.1.2",
|
||||
"markdownlint-rule-helpers": "0.18.0",
|
||||
"npm-run-all": "4.1.5",
|
||||
"strip-json-comments": "5.0.0",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue