DavidAnson / markdownlint

A Node.js style checker and lint tool for Markdown/CommonMark files.
MIT License
4.81k stars 733 forks source link

MD034 triggered when URL is escaped in the protocol section #269

Closed nschonni closed 4 years ago

nschonni commented 4 years ago

https://dlaa.me/markdownlint/#%25mhttp%5C%3A%2F%2Fwww.contoso.com

Sometimes you want to show a link without the autolink happening, so you escape one of the characters in the :// sequence. It seems the reqex for the rule is ignoring that and still treating it as a link.

DavidAnson commented 4 years ago

The RegExp is applied after parsing, so it doesn’t see the ‘\’. What about the suggestion to use a code block at the end of the rule documentation? https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md#md034

DavidAnson commented 4 years ago

The markdown-it parser doesn’t seem to ignore the link using this technique: https://markdown-it.github.io/#md3=%7B%22source%22%3A%22http%5C%5C%3A%2F%2Fwww.contoso.com%22%2C%22defaults%22%3A%7B%22html%22%3Afalse%2C%22xhtmlOut%22%3Afalse%2C%22breaks%22%3Afalse%2C%22langPrefix%22%3A%22language-%22%2C%22linkify%22%3Atrue%2C%22typographer%22%3Atrue%2C%22_highlight%22%3Atrue%2C%22_strict%22%3Afalse%2C%22_view%22%3A%22html%22%7D%7D

nschonni commented 4 years ago

Sorry, I stripped down the example to the minimum viable, but in the case I came across, it was being escaped to it could be bolded/emphasized, so the backticks wouldn't work.

DavidAnson commented 4 years ago

As I note above, the trick you show with backslash does not work with the markdown-itparser which means it shouldn’t work with any CommonMark parser.

There are other tricks:

But they are all unsightly and some break the link.

Ultimately, I think my recommendation is to disable MD034 for this scenario, either per-line, file, or project. Or disable auto-linking in the relevant Markdown parser (good ones should provide this option).

nschonni commented 4 years ago

This is for docs.microsoft.com content, so Markdig :)

DavidAnson commented 4 years ago

This works (using the zero-width non-breaking space character), though it’s pretty ugly in the source. However, I think it’s the best I can offer:

https://dlaa.me/markdownlint/#%25m%23%20Issue%20269%0A%0Ahttp%3A%26%2365279%3B%2F%2Fwww.contoso.com%0A

nschonni commented 4 years ago

For the particular PR, they ended up just disabling the rule for it. Probably something for Markdown-it I guess, so it doesn't appear as a link in the AST

DavidAnson commented 4 years ago

No clear fix here, and the issue seems to be mitigated by disabling the rule.

nschonni commented 2 years ago

Ha, when to open up this issue again because I've hit it again on mdn/content 😄 FYI, I've got the basic config in that repo now, but it isn't fully plugged into the CI yet, so there is still regular regressions