diff --git a/helpers/micromark-helpers.cjs b/helpers/micromark-helpers.cjs index 842c8210a..87e75cbe6 100644 --- a/helpers/micromark-helpers.cjs +++ b/helpers/micromark-helpers.cjs @@ -78,12 +78,11 @@ function addRangeToSet(set, start, end) { * 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 = [ { @@ -278,7 +277,11 @@ const nonContentTokens = new Set([ "lineEnding", "lineEndingBlank", "linePrefix", - "listItemIndent" + "listItemIndent", + "undefinedReference", + "undefinedReferenceCollapsed", + "undefinedReferenceFull", + "undefinedReferenceShortcut" ]); module.exports = { diff --git a/lib/md032.mjs b/lib/md032.mjs index 5dc23cdd3..dcb57ced8 100644 --- a/lib/md032.mjs +++ b/lib/md032.mjs @@ -45,13 +45,14 @@ export default { } // Find the "visual" end of the list + const flattenedChildren = filterByPredicate( + list.children, + (token) => !nonContentTokens.has(token.type), + (token) => nonContentTokens.has(token.type) ? [] : token.children + ); let endLine = list.endLine; - const flattenedChildren = filterByPredicate(list.children); - for (const child of flattenedChildren.reverse()) { - if (!nonContentTokens.has(child.type)) { - endLine = child.endLine; - break; - } + if (flattenedChildren.length > 0) { + endLine = flattenedChildren[flattenedChildren.length - 1].endLine; } // Look for a blank line below the list diff --git a/test/lists_without_blank_lines.md b/test/lists_without_blank_lines.md index f0f3dd357..4f7d6446d 100644 --- a/test/lists_without_blank_lines.md +++ b/test/lists_without_blank_lines.md @@ -88,6 +88,11 @@ text
* Not a list
+1. Undefined reference token ++ [()] ++