Skip to content

Commit

Permalink
final-definition: fix good footnote definitions
Browse files Browse the repository at this point in the history
Related-to: GH-318.
  • Loading branch information
wooorm committed Apr 17, 2024
1 parent db0baa2 commit a97671d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
27 changes: 21 additions & 6 deletions packages/remark-lint-final-definition/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
* 3:1-3:36: Unexpected definition before last content, expected definitions after line `5`
*
* @example
* {"gfm": true, "label": "input", "name": "gfm.md"}
* {"gfm": true, "label": "input", "name": "gfm-nok.md"}
*
* Mercury.
*
Expand All @@ -98,9 +98,20 @@
*
* Earth.
* @example
* {"gfm": true, "label": "output", "name": "gfm.md"}
* {"gfm": true, "label": "output", "name": "gfm-nok.md"}
*
* 3:1-5:13: Unexpected footnote definition before last content, expected definitions after line `7`
*
* @example
* {"gfm": true, "name": "gfm-ok.md"}
*
* Mercury.
*
* Earth.
*
* [^venus]:
* **Venus** is the second planet from
* the Sun.
*/

/**
Expand Down Expand Up @@ -142,17 +153,21 @@ const remarkLintFinalDefinition = lintRule(

if (node.type === 'definition' || node.type === 'footnoteDefinition') {
definitionStacks.push([...parents, node])
} else if (
// Do not enter footnote definitions.
return SKIP
}

if (
node.type === 'root' ||
// Ignore HTML comments.
(node.type === 'html' && /^[\t ]*<!--/.test(node.value)) ||
// Ignore MDX comments.
(node.type === 'mdxFlowExpression' && /^\s*\/\*/.test(node.value))
) {
// Empty.
} else {
contentAncestors = [...parents, node]
return
}

contentAncestors = [...parents, node]
})

const content = contentAncestors ? contentAncestors.at(-1) : undefined
Expand Down
23 changes: 22 additions & 1 deletion packages/remark-lint-final-definition/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ Earth.
3:1-3:36: Unexpected definition before last content, expected definitions after line `5`
```

##### `gfm.md`
##### `gfm-nok.md`

###### In

Expand All @@ -249,6 +249,27 @@ Earth.
3:1-5:13: Unexpected footnote definition before last content, expected definitions after line `7`
```

##### `gfm-ok.md`

###### In

> 👉 **Note**: this example uses
> GFM ([`remark-gfm`][github-remark-gfm]).
```markdown
Mercury.

Earth.

[^venus]:
**Venus** is the second planet from
the Sun.
```

###### Out

No messages.

## Compatibility

Projects maintained by the unified collective are compatible with maintained
Expand Down

0 comments on commit a97671d

Please sign in to comment.