mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-04-25 17:26:22 +03:00
[GH-ISSUE #1472] Should MD050 apply to link labels? #691
Labels
No labels
bug
enhancement
enhancement
enhancement
fixed in next
fixed in next
fixed in next
new rule
new rule
new rule
pull-request
question
refactoring
refactoring
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/markdownlint#691
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @lemeb on GitHub (Jan 21, 2025).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/1472
Hi :)
Issue
Consider this:
The last two bullet points are reference links to the Python documentation. Some documentation plugins enable the use of this shortened syntax.
If you run
markdownlint, however, you get an error:Is this intended?
At first, looking at the CommonMark spec, I was under the impression that maybe it is by design that link labels are not supposed to have rich syntax.
But the CommonMark playground suggests otherwise (link to the example):
It might be a philosophical question: do you consider link references to be part of the document, and therefore subject to
MD050like the rest of the text? Or is it simply metadata that deserves to be ignored?I would say the latter, especially since the CommonMark spec says:
... But I might be wrong!
Alternatively, having a configuration option to ignore link labels would be great.
Thanks a lot :)
@DavidAnson commented on GitHub (Jan 21, 2025):
Thank you for the detailed report! From what I see here, I think you're right. It surprises me that the parser is flagging emphasis in this context, but I'll have a look tonight or tomorrow and fix this.
@DavidAnson commented on GitHub (Jan 22, 2025):
Your example produces no violations when the link references you show are defined:
https://dlaa.me/markdownlint/#%25m%23%20Let's%20talk%20about%20Python%20internals%0A%0AHere%20are%20links%20to%20the%20official%20Python%20documentation%3A%0A%0A*%20%5B%60__len__%60%5D%5Bobject.len%5D%0A*%20%5B%60__call__%60%5D%5Bobject.call%5D%0A%0A%5Bobject.len%5D%3A%20https%3A%2F%2Fexample.com%2Flen%0A%5Bobject.call%5D%3A%20https%3A%2F%2Fexample.com%2Fcall%0A
So I claim the current behavior of the rule is correct and consistent with CommonMark behavior.
In order for YOUR scenario to lint cleanly WITHOUT defining the link references, this rule would need to guess your project is using MkDocs configured for mkdocstrings and infer the location of
mkdocs.ymland parse it for imports and load the inventory file and parse that file and try to match the undefined link reference. That's all pretty far out of scope for how rules behave today, so I am not inclined to do so if that's what you're proposing.@lemeb commented on GitHub (Feb 5, 2025):
Hey, sorry for the delayed response, I was off.
If I understand you correctly, you are essentially saying that mkdocstrings is doing an illegal dependency injection, and that two sets of brackets should be treated as a raw text according to the Markdown spec.
I agree with you that it's totally unreasonable to expected markdownlint to process the files accordingly and only then lint the file.
You could try to allow users to have link labels that don't have corresponding references, and parse them as link labels anyway. I'm not sure that this could be implemented in a custom rule, since this goes to the heart of parsing logic. But I might be wrong, and then again, might be out of scope anyway.
Thanks :)
@DavidAnson commented on GitHub (Feb 5, 2025):
Per the specification, if a link reference does not resolve, then that thing is not a link and it is treated as normal content. You can verify this with the demo link I sent by removing either of the reference definitions at the bottom.
I don't want to tamper with parse behavior, so my recommendation is to selectively or completely disable the relevant rule or change the reference strings in your project to not to include emphasis characters. (It's OK if your syntax isn't recognized as a link, the problem is just that it also contains content that violates one of the rules.)
@lemeb commented on GitHub (Feb 5, 2025):
Yep, I understand you! Thanks for the time