MD053 false-positive thrown over Pandoc/GitHub footnotes
See original GitHub issueRule MD053 is incorrectly thrown after referencing a link definition over a Pandoc/Github footnote (see Pandoc’s User Guide for syntax) (and GitHub’s).
However, the rule isn’t thrown on (indented) lines directly after, i.e. on long footnotes. Though, for Pandoc to render a new line on a (long) footnote, a blank line has to be entered within two blocks of text; and creating a new (indented) block that references a link does throw the same rule violation; likely because it’s considered by Markdownlint as a code block.
As I’m not gonna bother checking the code: From what I can infer, Markdownlint checks if a link is used based on the first character(s) of a line, such as to check if a line represents a code block, and that’s why link references aren’t checked/found on footnotes.
Reproduction
$ markdownlint -V
0.32.2
0.32.2 is the latest version for CLI, which uses the latest version of the API (i.e. 0.26.2) using the following Markdown file:
<!-- pandoc.md -->
# Example with Pandoc Footnotes
A sentence with footnotes: [^1] [^2]
A sentence with named footnotes: [^name] [^name2]
A sentence with a link reference: [Pandoc's User Guide][Pandoc]
[^1]: I am a footnote!
[^2]: I reference a [PCWorld][PCW] article!
[^name]: I am a footnote with name!
[^name2]: I am also a named footnote! I also reference the [PCWorld][PCW] article!
[PCW]: https://www.pcworld.com/article/395018/how-much-ram-do-you-need-in-a-laptop.html#4gb-ram
[Pandoc]: https://pandoc.org/MANUAL.html#extension-citations
the CLI outputs:
$ markdownlint pandoc.md
pandoc.md:12:1 MD053/link-image-reference-definitions Link and image reference definitions should be needed [Unused link or image reference definition: "pcw"] [Context: "[PCW]: https://www.pcworld.com..."]
as you can see, using a link reference on a sentence doesn’t throw the rule.
While not using footnotes at all, obviously doesn’t throw any error.
Just a superfluous example
With the file:
<!-- no-pandoc.md -->
# Example without Pandoc Footnotes
A sentence that references a [PCWorld][PCW] article.
[PCW]: https://www.pcworld.com/article/395018/how-much-ram-do-you-need-in-a-laptop.html#4gb-ram
the CLI doesn’t output anything (i.e. any rule violation):
$ markdownlint no-pandoc.md
On the case of long footnotes (i.e. those that contain multiple lines/blocks of text), attempting to reference a link on a new (indented) line doesn’t throw the error. nor on further (indented) lines of text:
<!-- long.md -->
# Example with Long Footnotes
A sentence with a long footnotes: [^long] [^longer] [^longest]
[^long]: I am a long footnote!
I don't do any harm :)
[^longer]: I am a longer footnote. I do reference the [PCWorld][PCW] article.
I do harm. Though, not here: [Pandoc's User Guide][Pandoc]
[^longest]: I am the longest footnote. I also reference the [PCWorld][PCW] article.
I am a harmful new block of text: [Rule MD053][Rule]
[PCW]: https://www.pcworld.com/article/395018/how-much-ram-do-you-need-in-a-laptop.html#4gb-ram
[Pandoc]: https://pandoc.org/MANUAL.html#extension-citations
[Rule]: https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md#md053---link-and-image-reference-definitions-should-be-needed
of which CLI outputs:
$ markdownlint long.md
long.md:13:1 MD053/link-image-reference-definitions Link and image reference definitions should be needed [Unused link or image reference definition: "pcw"] [Context: "[PCW]: https://www.pcworld.com..."]
long.md:15:1 MD053/link-image-reference-definitions Link and image reference definitions should be needed [Unused link or image reference definition: "rule"] [Context: "[Rule]: https://github.com/Dav..."]
but, as you can see, the new block of text does throw the rule violation, as already explained.
Looks like this as a PDF with Pandoc
Like said, the new block text (i.e. blank line) does print a new line on the PDF.
Have to say, a lot of reproduction; but, hope it was helpful
Issue Analytics
- State:
- Created a year ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
Thank you for the exceptionally detailed issue! I don’t think I realized you could have references within definitions - and I need to understand the rules for footnotes better to see why four spaces doesn’t make a code block in your example.
By the way, it’s good remarking that this is not only behavior from Pandoc, but GitHub does something similar, but not exactly the same, i.e. you can create a new line two ways, either by indenting the new line with two spaces:
or just creating a block of text with a 4-space indent:
which I think is weirder, at least compared to Pandoc.
And, using code blocks on footnotes? They don’t work on GitHub, but they should theoretically work if GitHub applied the “alignment rule” on footnotes. [^1] [^2]
Here's how I tried to indent code blocks on the footnotes, by the way:
[^1]: I am a footnote with 2-space indent rule Here a new line Am I a code block?
[^2]: I am another footnote, but with 4-space alignment Am I also a code block?