Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAnson committed Oct 19, 2024
1 parent eae26a2 commit 18a7935
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 17 deletions.
25 changes: 24 additions & 1 deletion helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,9 @@ function getReferenceLinkImageData(tokens) {
// definitions and definitionLineIndices
"definitionLabelString", "gfmFootnoteDefinitionLabelString",
// references and shortcuts
"gfmFootnoteCall", "image", "link"
"gfmFootnoteCall", "image", "link",
// undefined link labels
"undefinedReferenceCollapsed", "undefinedReferenceFull", "undefinedReferenceShortcut"

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 20)

Type '"undefinedReferenceCollapsed"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 20)

Type '"undefinedReferenceFull"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 20)

Type '"undefinedReferenceShortcut"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 20)

Type '"undefinedReferenceFull"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 20)

Type '"undefinedReferenceShortcut"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18)

Type '"undefinedReferenceCollapsed"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18)

Type '"undefinedReferenceFull"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18)

Type '"undefinedReferenceShortcut"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18)

Type '"undefinedReferenceFull"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18)

Type '"undefinedReferenceShortcut"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

Type '"undefinedReferenceCollapsed"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

Type '"undefinedReferenceFull"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

Type '"undefinedReferenceShortcut"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 22)

Type '"undefinedReferenceCollapsed"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 22)

Type '"undefinedReferenceFull"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 22)

Type '"undefinedReferenceShortcut"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 22)

Type '"undefinedReferenceCollapsed"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 22)

Type '"undefinedReferenceFull"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 22)

Type '"undefinedReferenceShortcut"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 20)

Type '"undefinedReferenceCollapsed"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 20)

Type '"undefinedReferenceFull"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 20)

Type '"undefinedReferenceShortcut"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18)

Type '"undefinedReferenceCollapsed"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18)

Type '"undefinedReferenceFull"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 388 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18)

Type '"undefinedReferenceShortcut"' is not assignable to type 'keyof TokenTypeMap'.
]
);
for (const token of filteredTokens) {
Expand Down Expand Up @@ -455,6 +457,27 @@ function getReferenceLinkImageData(tokens) {
}
}
break;
case "undefinedReferenceCollapsed":

Check failure on line 460 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 20)

Type '"undefinedReferenceCollapsed"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 460 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 20)

Type '"undefinedReferenceCollapsed"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 460 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18)

Type '"undefinedReferenceCollapsed"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 460 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18)

Type '"undefinedReferenceCollapsed"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 460 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

Type '"undefinedReferenceCollapsed"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 460 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 22)

Type '"undefinedReferenceCollapsed"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 460 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 22)

Type '"undefinedReferenceCollapsed"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 460 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 20)

Type '"undefinedReferenceCollapsed"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 460 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18)

Type '"undefinedReferenceCollapsed"' is not comparable to type 'keyof TokenTypeMap'.
case "undefinedReferenceFull":

Check failure on line 461 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 20)

Type '"undefinedReferenceFull"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 461 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 20)

Type '"undefinedReferenceFull"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 461 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18)

Type '"undefinedReferenceFull"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 461 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18)

Type '"undefinedReferenceFull"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 461 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

Type '"undefinedReferenceFull"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 461 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 22)

Type '"undefinedReferenceFull"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 461 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 22)

Type '"undefinedReferenceFull"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 461 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 20)

Type '"undefinedReferenceFull"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 461 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18)

Type '"undefinedReferenceFull"' is not comparable to type 'keyof TokenTypeMap'.
case "undefinedReferenceShortcut":

Check failure on line 462 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 20)

Type '"undefinedReferenceShortcut"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 462 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 20)

Type '"undefinedReferenceShortcut"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 462 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18)

Type '"undefinedReferenceShortcut"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 462 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18)

Type '"undefinedReferenceShortcut"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 462 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

Type '"undefinedReferenceShortcut"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 462 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 22)

Type '"undefinedReferenceShortcut"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 462 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 22)

Type '"undefinedReferenceShortcut"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 462 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 20)

Type '"undefinedReferenceShortcut"' is not comparable to type 'keyof TokenTypeMap'.

Check failure on line 462 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18)

Type '"undefinedReferenceShortcut"' is not comparable to type 'keyof TokenTypeMap'.
{
const label = micromark.getDescendantsByType(token, [ "undefinedReference" ])[0].children.map((t) => t.text).join("");

Check failure on line 464 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 20)

Type '"undefinedReference"' is not assignable to type 'keyof TokenTypeMap | (keyof TokenTypeMap)[]'.

Check failure on line 464 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 20)

Type '"undefinedReference"' is not assignable to type 'keyof TokenTypeMap | (keyof TokenTypeMap)[]'.

Check failure on line 464 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18)

Type '"undefinedReference"' is not assignable to type 'keyof TokenTypeMap | (keyof TokenTypeMap)[]'.

Check failure on line 464 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18)

Type '"undefinedReference"' is not assignable to type 'keyof TokenTypeMap | (keyof TokenTypeMap)[]'.

Check failure on line 464 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

Type '"undefinedReference"' is not assignable to type 'keyof TokenTypeMap | (keyof TokenTypeMap)[]'.

Check failure on line 464 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 22)

Type '"undefinedReference"' is not assignable to type 'keyof TokenTypeMap | (keyof TokenTypeMap)[]'.

Check failure on line 464 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 22)

Type '"undefinedReference"' is not assignable to type 'keyof TokenTypeMap | (keyof TokenTypeMap)[]'.

Check failure on line 464 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 20)

Type '"undefinedReference"' is not assignable to type 'keyof TokenTypeMap | (keyof TokenTypeMap)[]'.

Check failure on line 464 in helpers/helpers.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18)

Type '"undefinedReference"' is not assignable to type 'keyof TokenTypeMap | (keyof TokenTypeMap)[]'.
const isShortcut = token.type === "undefinedReferenceShortcut";
const referenceDatum = [
token.startLine - 1,
token.startColumn - 1,
token.text.length,
label.length,
0 // (referenceString?.text || "").length
];
const reference =
normalizeReference(/*referenceString?.text ||*/ label);
const dictionary = isShortcut ? shortcuts : references;
const referenceData = dictionary.get(reference) || [];
referenceData.push(referenceDatum);
dictionary.set(reference, referenceData);
}
break;
}
}
return {
Expand Down
133 changes: 118 additions & 15 deletions helpers/micromark-parse.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const { flatTokensSymbol, htmlFlowSymbol, newLineRe } = require("./shared.js");

/** @typedef {import("markdownlint-micromark").Event} Event */
/** @typedef {import("markdownlint-micromark").ParseOptions} MicromarkParseOptions */
/** @typedef {import("../lib/markdownlint.js").MicromarkToken} Token */
/** @typedef {import("markdownlint-micromark").Token} Token */
/** @typedef {import("../lib/markdownlint.js").MicromarkToken} MicromarkToken */

/**
* Parse options.
Expand Down Expand Up @@ -44,17 +45,119 @@ function getEvents(
micromark.math()
);

// Use micromark to parse document into Events
const encoding = undefined;
const eol = true;
const parseContext = micromark.parse(micromarkParseOptions);
if (shimReferences) {
// Customize ParseContext to treat all references as defined
parseContext.defined.includes = (searchElement) => searchElement.length > 0;
// // Shim labelEnd to identify undefined link labels
/** @type {Event[][]} */
const artificialEventLists = [];
const { labelEnd } = micromark;

Check failure on line 51 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 20)

Property 'labelEnd' does not exist on type 'typeof import("/home/runner/work/markdownlint/markdownlint/node_modules/markdownlint-micromark/micromark")'.

Check failure on line 51 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 20)

Property 'labelEnd' does not exist on type 'typeof import("/Users/runner/work/markdownlint/markdownlint/node_modules/markdownlint-micromark/micromark")'.

Check failure on line 51 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18)

Property 'labelEnd' does not exist on type 'typeof import("/home/runner/work/markdownlint/markdownlint/node_modules/markdownlint-micromark/micromark")'.

Check failure on line 51 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18)

Property 'labelEnd' does not exist on type 'typeof import("/Users/runner/work/markdownlint/markdownlint/node_modules/markdownlint-micromark/micromark")'.

Check failure on line 51 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

Property 'labelEnd' does not exist on type 'typeof import("/home/runner/work/markdownlint/markdownlint/node_modules/markdownlint-micromark/micromark")'.

Check failure on line 51 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 22)

Property 'labelEnd' does not exist on type 'typeof import("/Users/runner/work/markdownlint/markdownlint/node_modules/markdownlint-micromark/micromark")'.

Check failure on line 51 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 22)

Property 'labelEnd' does not exist on type 'typeof import("D:/a/markdownlint/markdownlint/node_modules/markdownlint-micromark/micromark")'.

Check failure on line 51 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 20)

Property 'labelEnd' does not exist on type 'typeof import("D:/a/markdownlint/markdownlint/node_modules/markdownlint-micromark/micromark")'.

Check failure on line 51 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18)

Property 'labelEnd' does not exist on type 'typeof import("D:/a/markdownlint/markdownlint/node_modules/markdownlint-micromark/micromark")'.
const tokenizeOriginal = labelEnd.tokenize;
function tokenizeShim(effects, okOriginal, nokOriginal) {

Check warning on line 53 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 20)

Missing JSDoc comment

Check warning on line 53 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 20)

Missing JSDoc comment

Check warning on line 53 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18)

Missing JSDoc comment

Check warning on line 53 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18)

Missing JSDoc comment

Check warning on line 53 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

Missing JSDoc comment

Check warning on line 53 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 22)

Missing JSDoc comment

Check warning on line 53 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 22)

Missing JSDoc comment

Check warning on line 53 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 20)

Missing JSDoc comment

Check warning on line 53 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18)

Missing JSDoc comment
// TODO: Type this as TokenizeContext
const tokenizeContext = this;
const nokShim = (code) => {
// TODO: Remove next
/** @type {Event[]} */
const events = tokenizeContext.events;

// Find start of label
let indexStart = events.length;
while (--indexStart >= 0) {
const event = events[indexStart];
const [ kind, token ] = event;
if (kind === "enter") {
const { type, _balanced } = token;
if ((type === "labelImage") || (type === "labelLink")) {
break;
}
}
}

if (indexStart >= 0) {
// Create artificial enter/exit and all "data" events within
const eventStart = events[indexStart];
const eventEnd = events[events.length - 1];
/** @type {Token} */
const artificialReferenceType = {
"type": "undefinedReferenceShortcut",

Check failure on line 80 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 20)

Type '"undefinedReferenceShortcut"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 80 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 20)

Type '"undefinedReferenceShortcut"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 80 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18)

Type '"undefinedReferenceShortcut"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 80 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18)

Type '"undefinedReferenceShortcut"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 80 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

Type '"undefinedReferenceShortcut"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 80 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 22)

Type '"undefinedReferenceShortcut"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 80 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 22)

Type '"undefinedReferenceShortcut"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 80 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 20)

Type '"undefinedReferenceShortcut"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 80 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18)

Type '"undefinedReferenceShortcut"' is not assignable to type 'keyof TokenTypeMap'.
"start": eventStart[1].start,
"end": eventEnd[1].end
};
/** @type {Token} */
const artificialReference = {
...artificialReferenceType,
"type": "undefinedReference"

Check failure on line 87 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 20)

Type '"undefinedReference"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 87 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 20)

Type '"undefinedReference"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 87 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18)

Type '"undefinedReference"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 87 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18)

Type '"undefinedReference"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 87 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

Type '"undefinedReference"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 87 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 22)

Type '"undefinedReference"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 87 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 22)

Type '"undefinedReference"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 87 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 20)

Type '"undefinedReference"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 87 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18)

Type '"undefinedReference"' is not assignable to type 'keyof TokenTypeMap'.
};
const rel = events.slice(indexStart);
const dataEvents = rel.filter((event) => ["data", "lineEnding"].includes(event[1].type));

// ...
let skip = false;
const prev = artificialEventLists.length && artificialEventLists[artificialEventLists.length - 1][0];
if (prev && (prev[1].end.line === artificialReferenceType.start.line) && (prev[1].end.column === artificialReferenceType.start.column)) {
if (dataEvents.length === 0) {
prev[1].type = "undefinedReferenceCollapsed";

Check failure on line 97 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 20)

Type '"undefinedReferenceCollapsed"' is not assignable to type 'keyof TokenTypeMap'.

Check failure on line 97 in helpers/micromark-parse.cjs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18)

Type '"undefinedReferenceCollapsed"' is not assignable to type 'keyof TokenTypeMap'.
prev[1].end = eventEnd[1].end;
// const pl = artificialEventLists[artificialEventLists.length - 1];
// pl.splice(pl.length - 1, 0, ...rel.filter((event) => event[1].type === "labelMarker"));
skip = true;
} else {
artificialReferenceType.type = "undefinedReferenceFull";
artificialReferenceType.start = prev[1].start;
}
}

if (!skip) {
const dataText = dataEvents.filter((de) => de[0] === "enter").map((de) => tokenizeContext.sliceSerialize(de[1])).join("").trim();
if (
(dataText.length > 0) &&
!dataText.includes("]")
) {
/** @type {Event[]} */
const artificialEvents = [];
artificialEvents.push([ "enter", artificialReferenceType, tokenizeContext ]);
artificialEvents.push([ "enter", artificialReference, tokenizeContext ]);
for (const event of dataEvents) {
artificialEvents.push([ event[0], { ...event[1] }, tokenizeContext ]);
}
artificialEvents.push([ "exit", artificialReference, tokenizeContext ]);
artificialEvents.push([ "exit", artificialReferenceType, tokenizeContext ]);
artificialEventLists.push(artificialEvents);
}
}
}

// Continue with original behavior
return nokOriginal(code);
};

// Shim nok handler of labelEnd's tokenize
return tokenizeOriginal.call(tokenizeContext, effects, okOriginal, nokShim);
}

try {
// Shim labelEnd behavior
labelEnd.tokenize = tokenizeShim;

// Use micromark to parse document into Events
const encoding = undefined;
const eol = true;
const parseContext = micromark.parse(micromarkParseOptions);
if (shimReferences) {
// Customize ParseContext to treat all references as defined
// parseContext.defined.includes = (searchElement) => searchElement.length > 0;
}
const chunks = micromark.preprocess()(markdown, encoding, eol);
let events = micromark.postprocess(parseContext.document().write(chunks));

// Append artificial events and return all events
for (const artificialEventList of artificialEventLists) {
events = events.concat(artificialEventList);
}
return events;

} finally {
// Restore labelEnd behavior
labelEnd.tokenize = tokenizeOriginal;
}
const chunks = micromark.preprocess()(markdown, encoding, eol);
const events = micromark.postprocess(parseContext.document().write(chunks));
return events;
}

/**
Expand All @@ -64,8 +167,8 @@ function getEvents(
* @param {ParseOptions} [parseOptions] Options.
* @param {MicromarkParseOptions} [micromarkParseOptions] Options for micromark.
* @param {number} [lineDelta] Offset for start/end line.
* @param {Token} [ancestor] Parent of top-most tokens.
* @returns {Token[]} Micromark tokens.
* @param {MicromarkToken} [ancestor] Parent of top-most tokens.
* @returns {MicromarkToken[]} Micromark tokens.
*/
function parseInternal(
markdown,
Expand All @@ -83,7 +186,7 @@ function parseInternal(
// Create Token objects
const document = [];
let flatTokens = [];
/** @type {Token} */
/** @type {MicromarkToken} */
const root = {
"type": "data",
"startLine": -1,
Expand Down Expand Up @@ -183,7 +286,7 @@ function parseInternal(
*
* @param {string} markdown Markdown document.
* @param {ParseOptions} [parseOptions] Options.
* @returns {Token[]} Micromark tokens.
* @returns {MicromarkToken[]} Micromark tokens.
*/
function parse(markdown, parseOptions) {
return parseInternal(markdown, parseOptions);
Expand Down
1 change: 1 addition & 0 deletions micromark/exports.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export { math } from "micromark-extension-math";
export { parse } from "micromark";
export { postprocess } from "micromark";
export { preprocess } from "micromark";
export { labelEnd } from "micromark-core-commonmark";
14 changes: 14 additions & 0 deletions micromark/micromark.d.cts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ declare type Construct = {
add?: 'after' | 'before' | undefined
}

declare type Construct_2 = Construct;

/**
* Several constructs, mapped from their initial codes.
*/
Expand Down Expand Up @@ -975,6 +977,9 @@ declare interface HtmlOptions_3 extends Object {
displayMode?: never
}

/** @type {Construct} */
export declare const labelEnd: Construct_2;

/**
* Type of line ending in markdown.
*/
Expand Down Expand Up @@ -1747,3 +1752,12 @@ export declare interface TokenTypeMap {
mathTextPadding: 'mathTextPadding'
mathTextSequence: 'mathTextSequence'
}

// Source: [CUSTOM]

export declare interface TokenTypeMap {
undefinedReference: 'undefinedReference'
undefinedReferenceCollapsed: 'undefinedReferenceCollapsed'
undefinedReferenceFull: 'undefinedReferenceFull'
undefinedReferenceShortcut: 'undefinedReferenceShortcut'
}
3 changes: 2 additions & 1 deletion micromark/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "markdownlint-micromark",
"version": "0.1.11",
"version": "0.1.12",
"description": "A trivial package that re-exports some micromark functionality as a CommonJS module",
"type": "commonjs",
"exports": "./micromark.cjs",
Expand Down Expand Up @@ -33,6 +33,7 @@
"devDependencies": {
"@microsoft/api-extractor": "7.47.11",
"micromark": "4.0.0",
"micromark-core-commonmark": "2.0.1",
"micromark-extension-directive": "3.0.2",
"micromark-extension-gfm-autolink-literal": "2.1.0",
"micromark-extension-gfm-footnote": "2.1.0",
Expand Down
7 changes: 7 additions & 0 deletions micromark/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
// - micromark/node_modules/micromark-extension-gfm-footnote/index.d.ts
// - micromark/node_modules/micromark-extension-gfm-table/index.d.ts
// - micromark/node_modules/micromark-extension-math/index.d.ts
// - export declare interface TokenTypeMap {
// undefinedReference: 'undefinedReference'
// undefinedReferenceCollapsed: 'undefinedReferenceCollapsed'
// undefinedReferenceFull: 'undefinedReferenceFull'
// undefinedReferenceShortcut: 'undefinedReferenceShortcut'
// }
// 7. Update version number in package.json and stage changes
// 8. Test: npm run build, npm pack, npm install ./micromark/markdownlint-micromark-0.1.11.tgz, npm run ci, verify types like gfmFootnote* in getReferenceLinkImageData(...)
// 9. Publish: git clean -dfx, npm install, npm run build, npm publish ., git push
Expand All @@ -24,5 +30,6 @@ export type { gfmFootnote, gfmFootnoteHtml } from "micromark-extension-gfm-footn
export type { gfmTable, gfmTableHtml } from "micromark-extension-gfm-table";
export type { math, mathHtml } from "micromark-extension-math";
export type { compile, parse, postprocess, preprocess } from "micromark";
export type { labelEnd } from "micromark-core-commonmark";

export type { CompileData, Event, ParseOptions, Token, TokenType, TokenTypeMap } from "micromark-util-types";

0 comments on commit 18a7935

Please sign in to comment.