[GH-ISSUE #1959] MD051 false positive: Link fragments for headings containing colons (:) are flagged as invalid #791

Closed
opened 2026-03-03 01:29:53 +03:00 by kerem · 3 comments
Owner

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:

## some:thing

[link](#something)

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:thing should result in the ID something.

What actually happened?
The linter triggers a MD051/link-fragments violation: "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 valid

How can the issue be reproduced?
Paste the following content into a Markdown file with MD051 enabled:

## some:thing

[link](#something)

The linter will flag #something as invalid.

What version were you using?

  • VS Code markdownlint extension version: 0.61.1

What operating system were you using?
Windows 10 22H2

Originally created by @zts2005 on GitHub (Feb 15, 2026). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/1959 <!-- Thank you for taking the time to report an issue! When deciding where to open an issue, please note there are multiple projects under the markdownlint umbrella: - https://github.com/DavidAnson/markdownlint : This is the core JavaScript/Node.js library and is used by other tools. Most issues with implementation and rule behavior belong here. - https://github.com/igorshubovych/markdownlint-cli : This is the original CLI for markdownlint. Issues specific to CLI belong here. - https://github.com/DavidAnson/markdownlint-cli2 : This is a newer CLI for markdownlint and is used by other tools. Issues specific to CLI2 belong here. - https://github.com/DavidAnson/vscode-markdownlint : This is the Visual Studio Code extension for markdownlint. Issues specific to VS Code belong here. - https://github.com/DavidAnson/markdownlint-cli2-action : This is a GitHub Action for markdownlint. Issues specific to the Action belong here. - https://github.com/markdownlint/markdownlint : This is the original markdownlint implementation for Ruby. All Ruby-related issues belong here. Before creating an issue, it's a good practice to search existing issues for something similar. If your issue has already been reported, please update the existing one with any new information. It's also good to review the documentation for any relevant details. When describing an issue, the following information is helpful: - What did you do? - What did you expect to happen? - What actually happened? - What messages or errors were there? - How can the issue be reproduced? - What version were you using? - What operating system were you using? The simplest demonstration of a problem is the most helpful. Small examples can be pasted into the issue description. (Be sure to paste as code so GitHub doesn't render the example in Markdown.) For larger examples, linking to a repository or file is more appropriate. Before proposing a new rule, please review the existing suggestions: https://github.com/DavidAnson/markdownlint/issues?q=is%3Aissue+is%3Aopen+label%3A%22new+rule%22 Thank you! --> **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: ```markdown ## some:thing [link](#something) ``` **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:thing` should result in the ID `something`. **What actually happened?** The linter triggers a `MD051/link-fragments` violation: "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 valid` **How can the issue be reproduced?** Paste the following content into a Markdown file with `MD051` enabled: ```markdown ## some:thing [link](#something) ``` The linter will flag `#something` as invalid. **What version were you using?** * VS Code `markdownlint` extension version: 0.61.1 **What operating system were you using?** Windows 10 22H2
kerem 2026-03-03 01:29:53 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@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.

<!-- gh-comment-id:3904909346 --> @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.
Author
Owner

@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

<!-- gh-comment-id:3904917436 --> @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
Author
Owner

@zts2005 commented on GitHub (Feb 16, 2026):

Okay, I understand. This is the first time I have learned about this feature. Thank you.

<!-- gh-comment-id:3906904501 --> @zts2005 commented on GitHub (Feb 16, 2026): Okay, I understand. This is the first time I have learned about this feature. Thank you.
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#791
No description provided.