markdownlint icon indicating copy to clipboard operation
markdownlint copied to clipboard

Reference links are lost between dollar signs

Open nex3 opened this issue 1 year ago • 7 comments

This is an issue with the following markdown:

$ [foo][] $

[foo]: http://example.org

Note that $ is not an active character in standard Markdown, although it may be used by extensions. The document above is valid Markdown and [foo][] is interpreted as a link (as in this gist or the CommonMark dingus), but markdownlint produces this error:

MD053/link-image-reference-definitions Link and image reference definitions should be needed [Unused link or image reference definition: "foo"] [Context: "[foo]: http://example.org"]

As a workaround, you can add a \ before the first $.

nex3 avatar Jun 17 '24 23:06 nex3

While wrapping text with dollar signs like you show is not part of the CommonMark specification, it is commonly used in Markdown to provide math/equation support. Commonly enough, in fact, that issues get filed against this project when people expect math behavior and don't get it. Therefore, math syntax is enabled by default for parts of the pipeline. As you note, math syntax does not apply if the leading dollar sign is escaped and that is what I would recommend if you find yourself needing to use the syntax above.

https://github.com/micromark/micromark-extension-math

DavidAnson avatar Jun 18 '24 03:06 DavidAnson

I think it's highly unexpected behavior to diverge from the specification and the actual behavior of GitHub here. But regardless, it would be valuable to be able to control which non-standard extensions this parser assumed to exist through the configuration file.

nex3 avatar Jun 18 '24 23:06 nex3

I get where you are coming from, but GitHub does actually support math syntax by default. Here is their documentation: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/writing-mathematical-expressions

So far I have had double digit number of requests to add support for math and a couple of other common-ish extensions whereas this issue may be the first one asking to remove such support. Given how easy it is to escape one's way out of this problem, I am inclined not to make it configurable just yet.

I could do a better job documenting which extensions are enabled, though things are in a bit of flux at the moment while I am busy migrating parsers in the background.

DavidAnson avatar Jun 19 '24 05:06 DavidAnson

Github does not use $ as delimiter but $` and `$

stof avatar Jun 19 '24 09:06 stof

Quoting the GitHub documentation I linked to:

You can either surround the expression with dollar symbols ($), or start the expression with $[backtick] and end it with [backtick]$.

You can also verify this experimentally.

DavidAnson avatar Jun 19 '24 16:06 DavidAnson

When using $ as delimiters, Github still requires the start and end delimiters to be on the same line. They won't consider them delimiters when there is a LF between them, while your linter does. and it also requires that the start delimiter is not followed by spaces (the end delimiter can be preceded by spaces).

stof avatar Jun 19 '24 17:06 stof

Because there is no standard here, implementations may vary. I have generally found the micromark implementation (as used here) to be representative of real-world use and consistent with the specification when available. If you'd like to open a micromark issue for any behaviors you disagree with, I've found that team to be very responsive to input.

For the purpose of this issue, I think the underlying topic is whether it's reasonable for markdownlint to recognize math syntax by default and whether it's necessary to provide a way to opt out of that. I've stated my current position above and remain open to feedback.

DavidAnson avatar Jun 19 '24 19:06 DavidAnson