Rename markdownlint-micromark Token's .tokens property to .children for consistency and clarity.

This commit is contained in:
David Anson 2023-02-25 15:42:28 -08:00
parent 781b854f4b
commit 13ced64c21
6 changed files with 1558 additions and 1558 deletions

View file

@ -858,31 +858,31 @@ function getReferenceLinkImageData(params) {
let labelText = null;
let referenceStringText = null;
const shortcutCandidate =
micromark.matchAndGetTokensByType(token.tokens, [ "label" ]);
micromark.matchAndGetTokensByType(token.children, [ "label" ]);
if (shortcutCandidate) {
labelText =
micromark.getTokenTextByType(
shortcutCandidate[0].tokens, "labelText"
shortcutCandidate[0].children, "labelText"
);
isShortcut = (labelText !== null);
}
const fullAndCollapsedCandidate =
micromark.matchAndGetTokensByType(
token.tokens, [ "label", "reference" ]
token.children, [ "label", "reference" ]
);
if (fullAndCollapsedCandidate) {
labelText =
micromark.getTokenTextByType(
fullAndCollapsedCandidate[0].tokens, "labelText"
fullAndCollapsedCandidate[0].children, "labelText"
);
referenceStringText =
micromark.getTokenTextByType(
fullAndCollapsedCandidate[1].tokens, "referenceString"
fullAndCollapsedCandidate[1].children, "referenceString"
);
isFullOrCollapsed = (labelText !== null);
}
const footnote = micromark.matchAndGetTokensByType(
token.tokens,
token.children,
[
"gfmFootnoteCallLabelMarker", "gfmFootnoteCallMarker",
"gfmFootnoteCallString", "gfmFootnoteCallLabelMarker"

View file

@ -18,7 +18,7 @@ const {
* @property {number} endLine End line (1-based).
* @property {number} endColumn End column (1-based).
* @property {string} text Token text.
* @property {Token[]} tokens Child tokens.
* @property {Token[]} children Child tokens.
*/
/**
@ -60,7 +60,7 @@ function micromarkParse(markdown, options = {}) {
// Create Token objects
const document = [];
let current = {
"tokens": document
"children": document
};
const history = [ current ];
for (const event of events) {
@ -84,11 +84,11 @@ function micromarkParse(markdown, options = {}) {
endLine,
endColumn,
text,
"tokens": []
"children": []
};
previous.tokens.push(current);
previous.children.push(current);
} else if (kind === "exit") {
Object.freeze(current.tokens);
Object.freeze(current.children);
Object.freeze(current);
// @ts-ignore
current = history.pop();
@ -116,7 +116,7 @@ function filterByPredicate(tokens, allowed, transform) {
if (allowed(token)) {
result.push(token);
}
const transformed = transform ? transform(token.tokens) : token.tokens;
const transformed = transform ? transform(token.children) : token.children;
pending.unshift(...transformed);
}
return result;