[GH-ISSUE #787] MD034/no-bare-urls false positive since v0.7.0 #533

Closed
opened 2026-03-03 01:27:45 +03:00 by kerem · 10 comments
Owner

Originally created by @MichaIng on GitHub (Apr 22, 2023).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/787

This code produces an error since v0.7.0:

[[text] text](https://some.url.org)

Or are there Markdown parsers which do not support brackets within the link text brackets? In case, is there a proper way to escape them?

Originally created by @MichaIng on GitHub (Apr 22, 2023). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/787 This code produces an error since v0.7.0: ```md [[text] text](https://some.url.org) ``` Or are there Markdown parsers which do not support brackets within the link text brackets? In case, is there a proper way to escape them?
kerem 2026-03-03 01:27:45 +03:00
Author
Owner

@DavidAnson commented on GitHub (Apr 22, 2023):

Per the specification, if "text" were a valid shortcut link, then it would bind more tightly than the outer link and this error message would be correct.

Example here: https://dlaa.me/markdownlint/#%25m%23%20Issue%20150%0A%0A%5B%5Btext%5D%20text%5D(https%3A%2F%2Fsome.url.org)%0A%0A%5Btext%5D%3A%20https%3A%2F%2Fexample.com%0A

In this case, "text" is not a valid shortcut link, but because the linter assumes all shortcut links are valid even if undefined (needed for other reasons), it produces this misleading output.

<!-- gh-comment-id:1518701176 --> @DavidAnson commented on GitHub (Apr 22, 2023): Per the specification, if "text" were a valid shortcut link, then it would bind more tightly than the outer link and this error message would be correct. Example here: https://dlaa.me/markdownlint/#%25m%23%20Issue%20150%0A%0A%5B%5Btext%5D%20text%5D(https%3A%2F%2Fsome.url.org)%0A%0A%5Btext%5D%3A%20https%3A%2F%2Fexample.com%0A In this case, "text" is not a valid shortcut link, but because the linter assumes all shortcut links are valid even if undefined (needed for other reasons), it produces this misleading output.
Author
Owner

@DavidAnson commented on GitHub (Apr 22, 2023):

As you suggest, it is perfectly valid to escape the inner brackets like so to avoid the warning: https://dlaa.me/markdownlint/#%25m%23%20Issue%20150%0A%0A%5B%5C%5Btext%5C%5D%20text%5D(https%3A%2F%2Fsome.url.org)%0A

<!-- gh-comment-id:1518701184 --> @DavidAnson commented on GitHub (Apr 22, 2023): As you suggest, it is perfectly valid to escape the inner brackets like so to avoid the warning: https://dlaa.me/markdownlint/#%25m%23%20Issue%20150%0A%0A%5B%5C%5Btext%5C%5D%20text%5D(https%3A%2F%2Fsome.url.org)%0A
Author
Owner

@MichaIng commented on GitHub (Apr 22, 2023):

Interesting, I never knew about shortcut links. Is there an overview for them or is this something which can/needs to be defined in the Markdown document itself?

In the actual case it was [[OS] other text](URL), so [OS] within the link text.

I'll use the backslash escaping then, thanks for the hint 🙂.

<!-- gh-comment-id:1518703015 --> @MichaIng commented on GitHub (Apr 22, 2023): Interesting, I never knew about shortcut links. Is there an overview for them or is this something which can/needs to be defined in the Markdown document itself? In the actual case it was `[[OS] other text](URL)`, so `[OS]` within the link text. I'll use the backslash escaping then, thanks for the hint 🙂.
Author
Owner

@DavidAnson commented on GitHub (Apr 22, 2023):

https://spec.commonmark.org/0.30/#shortcut-reference-link

<!-- gh-comment-id:1518703683 --> @DavidAnson commented on GitHub (Apr 22, 2023): https://spec.commonmark.org/0.30/#shortcut-reference-link
Author
Owner

@MichaIng commented on GitHub (Apr 22, 2023):

Okay makes all sense now. Since Markdownlint cannot know which shortcuts are valid and which not (unless it really interprets the whole document first), it assumes this syntax to be always a valid shortcut. And I think it is even fine like this, since brackets within link text should then simply always be escaped as best practice. Otherwise a shortcut added at a later time may break things.

Only suggestion then, since links within link text are generally wrong: What about adding a new rule which does not allow unescaped brackets (including shortcut links) within link text? This of course means that such shortcuts are not expanded within link text, to be able to detect it. I guess, currently things are (usually correctly) expanded from inside to outside, so after expanding the internal shortcut, the outer link text syntax becomes invalid so that the URL is seen as no-bare-urls violation.

<!-- gh-comment-id:1518709689 --> @MichaIng commented on GitHub (Apr 22, 2023): Okay makes all sense now. Since Markdownlint cannot know which shortcuts are valid and which not (unless it really interprets the whole document first), it assumes this syntax to be always a valid shortcut. And I think it is even fine like this, since brackets within link text should then simply always be escaped as best practice. Otherwise a shortcut added at a later time may break things. Only suggestion then, since links within link text are generally wrong: What about adding a new rule which does not allow unescaped brackets (including shortcut links) within link text? This of course means that such shortcuts are not expanded within link text, to be able to detect it. I guess, currently things are (usually correctly) expanded from inside to outside, so after expanding the internal shortcut, the outer link text syntax becomes invalid so that the URL is seen as no-bare-urls violation.
Author
Owner

@DavidAnson commented on GitHub (Apr 22, 2023):

I don't know how widespread this is, but I would like to avoid the false positive you report because one of the main goals is to avoid bothering people if they have valid Markdown. Your point about behavior changing if a shortcut link suddenly becomes valid is reasonable, but that would be true anywhere in the document and I don't think I want to recommend escaping everywhere to prevent that.

<!-- gh-comment-id:1518716482 --> @DavidAnson commented on GitHub (Apr 22, 2023): I don't know how widespread this is, but I would like to avoid the false positive you report because one of the main goals is to avoid bothering people if they have valid Markdown. Your point about behavior changing if a shortcut link suddenly becomes valid is reasonable, but that would be true anywhere in the document and I don't think I want to recommend escaping everywhere to prevent that.
Author
Owner

@MichaIng commented on GitHub (Apr 22, 2023):

Okay, this means markdownlint needs to check for defined shortcut links. A limitation is that there are (non-standard) Markdown extensions to include one document into another. Especially for such definitions which are likely used across a whole website instead of a single page only, I guess such extensions are not rarely used: https://facelessuser.github.io/pymdown-extensions/extensions/snippets/

<!-- gh-comment-id:1518718604 --> @MichaIng commented on GitHub (Apr 22, 2023): Okay, this means markdownlint needs to check for defined shortcut links. A limitation is that there are (non-standard) Markdown extensions to include one document into another. Especially for such definitions which are likely used across a whole website instead of a single page only, I guess such extensions are not rarely used: https://facelessuser.github.io/pymdown-extensions/extensions/snippets/
Author
Owner

@DavidAnson commented on GitHub (Apr 22, 2023):

That's not an issue for now - this tool supports CommonMark and popular GFM extensions.

<!-- gh-comment-id:1518721558 --> @DavidAnson commented on GitHub (Apr 22, 2023): That's not an issue for now - this tool supports CommonMark and popular GFM extensions.
Author
Owner

@NomarCub commented on GitHub (May 8, 2023):

I also have some links with brackets in their text (that are not shortcuts) that I'm used to working as normal.
I found this CommonMark rule relevant: https://spec.commonmark.org/0.30/#link-text
And checked the CommonMark dingus against the markdownlint one.

<!-- gh-comment-id:1537784262 --> @NomarCub commented on GitHub (May 8, 2023): I also have some links with brackets in their text (that are not shortcuts) that I'm used to working as normal. I found this CommonMark rule relevant: https://spec.commonmark.org/0.30/#link-text And checked the [CommonMark dingus](https://spec.commonmark.org/dingus/?text=%23%20example%0A%0A-%20%5Blink%20%5Bwith%5D%20brackets%5D(https%3A%2F%2Fwww.google.com)%0A-%20%5Blink%20%5Bwith%5D%20%5Bmore%5D%20brakets%5D(https%3A%2F%2Fgithub.com%2FDavidAnson)%0A-%20%5Blink%20(with)%20parentheses%5D(https%3A%2F%2Fgithub.com%2FDavidAnson%2Fmarkdownlint)%0A-%20%5Blink%20%7Bwith%7D%20braces%5D(https%3A%2F%2Fgithub.com%2FDavidAnson%2Fmarkdownlint-cli2)%0A) against the [markdownlint one](https://dlaa.me/markdownlint/#%25m%23%20example%0A%0A-%20%5Blink%20%5Bwith%5D%20brackets%5D(https%3A%2F%2Fwww.google.com)%0A-%20%5Blink%20%5Bwith%5D%20%5Bmore%5D%20brakets%5D(https%3A%2F%2Fgithub.com%2FDavidAnson)%0A-%20%5Blink%20(with)%20parentheses%5D(https%3A%2F%2Fgithub.com%2FDavidAnson%2Fmarkdownlint)%0A-%20%5Blink%20%7Bwith%7D%20braces%5D(https%3A%2F%2Fgithub.com%2FDavidAnson%2Fmarkdownlint-cli2)%0A).
Author
Owner

@MichaIng commented on GitHub (Jun 2, 2023):

Makes sense. Many thanks for looking into it and the clarification.

<!-- gh-comment-id:1574012185 --> @MichaIng commented on GitHub (Jun 2, 2023): Makes sense. Many thanks for looking into it and the clarification.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/markdownlint#533
No description provided.