mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD032/blanks-around-lists to ignore (end-appended) undefined reference tokens when determining the last line of a list (fixes #1453).
This commit is contained in:
parent
599b687849
commit
8ad4698536
5 changed files with 24 additions and 10 deletions
|
@ -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 = {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -88,6 +88,11 @@ text
|
|||
|
||||
<p>* Not a list</p>
|
||||
|
||||
1. Undefined reference token
|
||||
<pre>
|
||||
[()]
|
||||
</pre>
|
||||
|
||||
<!-- markdownlint-configure-file {
|
||||
"no-inline-html": false,
|
||||
"ul-style": false,
|
||||
|
|
|
@ -37346,7 +37346,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
insertText: `␊
|
||||
`,
|
||||
},
|
||||
lineNumber: 98,
|
||||
lineNumber: 103,
|
||||
ruleDescription: 'Files should end with a single newline character',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md047.md',
|
||||
ruleNames: [
|
||||
|
@ -37457,6 +37457,11 @@ Generated by [AVA](https://avajs.dev).
|
|||
␊
|
||||
<p>* Not a list</p>␊
|
||||
␊
|
||||
1. Undefined reference token␊
|
||||
<pre>␊
|
||||
[()]␊
|
||||
</pre>␊
|
||||
␊
|
||||
<!-- markdownlint-configure-file {␊
|
||||
"no-inline-html": false,␊
|
||||
"ul-style": false,␊
|
||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue