mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
This commit is contained in:
parent
460836445c
commit
10f095c4fd
32 changed files with 3149 additions and 333 deletions
|
|
@ -748,7 +748,19 @@ function getReferenceLinkImageData(params) {
|
|||
if (definitions.has(reference)) {
|
||||
duplicateDefinitions.push([ reference, token.startLine - 1 ]);
|
||||
} else {
|
||||
definitions.set(reference, token.startLine - 1);
|
||||
let destinationString = null;
|
||||
const parent =
|
||||
micromark.getTokenParentOfType(token, [ "definition" ]);
|
||||
if (parent) {
|
||||
destinationString = micromark.getTokenTextByType(
|
||||
micromark.filterByPredicate(parent.children),
|
||||
"definitionDestinationString"
|
||||
);
|
||||
}
|
||||
definitions.set(
|
||||
reference,
|
||||
[ token.startLine - 1, destinationString ]
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -239,11 +239,12 @@ function micromarkParse(
|
|||
* Filter a list of Micromark tokens by predicate.
|
||||
*
|
||||
* @param {Token[]} tokens Micromark tokens.
|
||||
* @param {AllowedPredicate} allowed Allowed token predicate.
|
||||
* @param {AllowedPredicate} [allowed] Allowed token predicate.
|
||||
* @param {TransformPredicate} [transformChildren] Transform predicate.
|
||||
* @returns {Token[]} Filtered tokens.
|
||||
*/
|
||||
function filterByPredicate(tokens, allowed, transformChildren) {
|
||||
allowed = allowed || (() => true);
|
||||
const result = [];
|
||||
const queue = [
|
||||
{
|
||||
|
|
@ -353,7 +354,7 @@ function getTokenParentOfType(token, types) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the text of a single token from a list of Micromark tokens by type.
|
||||
* Get the text of the first match from a list of Micromark tokens by type.
|
||||
*
|
||||
* @param {Token[]} tokens Micromark tokens.
|
||||
* @param {string} type Types to match.
|
||||
|
|
@ -361,7 +362,7 @@ function getTokenParentOfType(token, types) {
|
|||
*/
|
||||
function getTokenTextByType(tokens, type) {
|
||||
const filtered = tokens.filter((token) => token.type === type);
|
||||
return (filtered.length === 1) ? filtered[0].text : null;
|
||||
return (filtered.length > 0) ? filtered[0].text : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue