[GH-ISSUE #121] Rule to validate links via https://github.com/tcort/markdown-link-check/ #102

Open
opened 2026-03-03 01:23:44 +03:00 by kerem · 8 comments
Owner

Originally created by @nschonni on GitHub (May 23, 2018).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/121

I've been using https://github.com/tcort/markdown-link-check/ as a separate check to validate links in markdown. I was starting to see if I could leverage the .markdownlint.json as a config format for that project too and realized maybe it might make sense to just add that functionality as a rule in this project.
Because it can go out and create network requests, I think having it off by default would make sense.
I may just do it as a custom rule in the end, but I figured I'd check to see if there is interest in this as a core rule.

Example config schema:

    "valid-links": {
      "description": "MD###/valid-links - Validate links",
      "type": [
        "boolean",
        "object"
      ],
      "default": true,
      "properties": {
        "link_types": {
          "description": "Types of links to validate",
          "type": "string",
          "enum": [
            "all",
            "internal",
            "external"
          ],
          "default": "internal"
        },
        "ignore_patterns": {
          "description": "RegExp for ignoring links",
          "type": "array",
          "items": {
            "type": "string"
          },
          "default": []
        },
        "http_headers": {
          "description": "Url and HTTP header pairs when URLs need additional parameters",
          "type": "array",
          "items": {
            "type": "object"
          },
          "default": []
      },
      "additionalProperties": false

/cc @tcort @timmkrause

Originally created by @nschonni on GitHub (May 23, 2018). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/121 I've been using https://github.com/tcort/markdown-link-check/ as a separate check to validate links in markdown. I was starting to see if I could leverage the `.markdownlint.json` as a config format for that project too and realized maybe it might make sense to just add that functionality as a rule in this project. Because it can go out and create network requests, I think having it off by default would make sense. I may just do it as a custom rule in the end, but I figured I'd check to see if there is interest in this as a core rule. Example config schema: ```json "valid-links": { "description": "MD###/valid-links - Validate links", "type": [ "boolean", "object" ], "default": true, "properties": { "link_types": { "description": "Types of links to validate", "type": "string", "enum": [ "all", "internal", "external" ], "default": "internal" }, "ignore_patterns": { "description": "RegExp for ignoring links", "type": "array", "items": { "type": "string" }, "default": [] }, "http_headers": { "description": "Url and HTTP header pairs when URLs need additional parameters", "type": "array", "items": { "type": "object" }, "default": [] }, "additionalProperties": false ``` /cc @tcort @timmkrause
Author
Owner

@DavidAnson commented on GitHub (May 23, 2018):

Love the idea! This comes up from time to time, so definitely worth thinking about. I think it would be pretty straightforward to implement as a custom rule, especially because the parser will have already pulled out each of the URLs.

What I’d like to do is start everything as a custom rule, see how it does, then look at pulling successful ones into the core library. (With the caveat that I try hard to avoid new dependencies, so maybe attempt this using only the core Node.js modules.)

If you prototype something here, I'd be happy to answer any questions that come up!

(See also https://github.com/DavidAnson/check-pages for a project of mine that checks links.)

<!-- gh-comment-id:391411314 --> @DavidAnson commented on GitHub (May 23, 2018): Love the idea! This comes up from time to time, so definitely worth thinking about. I think it would be pretty straightforward to implement as a custom rule, especially because the parser will have already pulled out each of the URLs. What I’d like to do is start everything as a custom rule, see how it does, then look at pulling successful ones into the core library. (With the caveat that I try hard to avoid new dependencies, so maybe attempt this using only the core Node.js modules.) If you prototype something here, I'd be happy to answer any questions that come up! (See also https://github.com/DavidAnson/check-pages for a project of mine that checks links.)
Author
Owner

@nschonni commented on GitHub (May 23, 2018):

Sounds good, I'll see if I can figure out setting up a separate rule repo.
Any advice on naming conventions and namespacing for rules, just to avoid any future issues if you decide it would fit in core?

<!-- gh-comment-id:391505124 --> @nschonni commented on GitHub (May 23, 2018): Sounds good, I'll see if I can figure out setting up a separate rule repo. Any advice on naming conventions and namespacing for rules, just to avoid any future issues if you decide it would fit in core?
Author
Owner

@DavidAnson commented on GitHub (May 23, 2018):

Don’t assign an MDxxx name, just use a name like validate-links and it should be possible to pull it in pretty much as-is. Some other guidance here: https://github.com/DavidAnson/markdownlint/blob/master/doc/CustomRules.md

<!-- gh-comment-id:391509940 --> @DavidAnson commented on GitHub (May 23, 2018): Don’t assign an MDxxx name, just use a name like validate-links and it should be possible to pull it in pretty much as-is. Some other guidance here: https://github.com/DavidAnson/markdownlint/blob/master/doc/CustomRules.md
Author
Owner

@amimas commented on GitHub (Feb 16, 2020):

Just wanted share my experience. I'm using both markdownlint-cli and textlint in my documentation projects. The following rule in textlint takes care of link validation:

https://github.com/textlint-rule/textlint-rule-no-dead-link

<!-- gh-comment-id:586730912 --> @amimas commented on GitHub (Feb 16, 2020): Just wanted share my experience. I'm using both markdownlint-cli and textlint in my documentation projects. The following rule in textlint takes care of link validation: https://github.com/textlint-rule/textlint-rule-no-dead-link
Author
Owner

@borekb commented on GitHub (Nov 16, 2020):

Just going to note that even a subset of this feature, which would be checking local links like see [below](#another-heading) would be quite useful.

<!-- gh-comment-id:727793828 --> @borekb commented on GitHub (Nov 16, 2020): Just going to note that even a subset of this feature, which would be **checking local links** like `see [below](#another-heading)` would be quite useful.
Author
Owner

@DavidAnson commented on GitHub (Jun 1, 2022):

Upcoming rule MD051 will implement this behavior for local links (#something).

github.com/DavidAnson/markdownlint@33ee1cd85e

<!-- gh-comment-id:1143149590 --> @DavidAnson commented on GitHub (Jun 1, 2022): Upcoming rule MD051 will implement this behavior for local links (#something). https://github.com/DavidAnson/markdownlint/commit/33ee1cd85ee1eeaaca4ba4d7f18e7e2edf67a48d
Author
Owner

@theoludwig commented on GitHub (Jan 2, 2023):

Update: I published a new npm package to add this custom rule (validating "dead" relative links): https://github.com/theoludwig/markdownlint-rule-relative-links.
Contributions are welcome! 🤗

<!-- gh-comment-id:1368997142 --> @theoludwig commented on GitHub (Jan 2, 2023): Update: I published a new npm package to add this custom rule (validating "dead" relative links): https://github.com/theoludwig/markdownlint-rule-relative-links. Contributions are welcome! :hugs:
Author
Owner

@igor-tsiglyar commented on GitHub (Jan 12, 2024):

FYI the markdownlint-rule-relative-links plugin has been updated to support links to anchors like MD051 does.

<!-- gh-comment-id:1888912784 --> @igor-tsiglyar commented on GitHub (Jan 12, 2024): FYI the markdownlint-rule-relative-links plugin has been [updated](https://github.com/theoludwig/markdownlint-rule-relative-links/releases/tag/v2.2.0) to support links to anchors like MD051 does.
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#102
No description provided.