mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-04-25 09:16:02 +03:00
[GH-ISSUE #1959] MD051 false positive: Link fragments for headings containing colons (:) are flagged as invalid #791
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#791
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 @zts2005 on GitHub (Feb 15, 2026).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/1959
What did you do?
I created a Markdown document with a heading containing an English colon (
:) and tried to link to it using a fragment generated by removing the punctuation, which follows the GitHub heading algorithm.Example code:
What did you expect to happen?
The link
[link](#something)should be considered valid. According to the GitHub heading algorithm (and how VS Code's built-in preview/autocomplete works), punctuation like colons should be removed when generating the fragment. Therefore,## some:thingshould result in the IDsomething.What actually happened?
The linter triggers a
MD051/link-fragmentsviolation: "Link fragments should be valid".Interestingly, if I change the colon to a Chinese colon (
:) or remove it entirely, the warning disappears.What messages or errors were there?
MD051/link-fragments: Link fragments should be validHow can the issue be reproduced?
Paste the following content into a Markdown file with
MD051enabled:The linter will flag
#somethingas invalid.What version were you using?
markdownlintextension version: 0.61.1What operating system were you using?
Windows 10 22H2
@zts2005 commented on GitHub (Feb 15, 2026):
Oh, I think I should have submitted the issue in the main repository, but it seems I made a mistake.
I'm very sorry.
@DavidAnson commented on GitHub (Feb 15, 2026):
You can see from the rendered output in the demo app that the text after the colon in your scenario is being recognized as a directive which is what causes this problem. You can read more about directives here:
https://github.com/micromark/micromark-extension-directive
This problem can be avoided by escaping the colon in the title with a backlash character as shown here:
https://dlaa.me/markdownlint/#%25m%23%20Issue%201959%0A%0A%23%23%20some%3Athing%0A%0A%5Btest%20link%5D(%23something)%0A%0A%23%23%20other%5C%3Athing%0A%0A%5Btest%20link%5D(%23otherthing)%0A
@zts2005 commented on GitHub (Feb 16, 2026):
Okay, I understand. This is the first time I have learned about this feature. Thank you.