Custom rule for markdownlint to validate relative links. https://www.npmjs.com/package/markdownlint-rule-relative-links
Go to file
2024-01-31 01:14:27 +01:00
.github fix: cleaner code + better error messages 2024-01-09 23:20:17 +01:00
.husky chore: cleaner configs 2024-01-29 21:24:22 +01:00
.vscode fix: update dependencies to latest 2023-12-26 21:11:07 +01:00
src feat: support line number checking in link fragment (e.g: '#L50') 2024-01-31 01:14:27 +01:00
test feat: support line number checking in link fragment (e.g: '#L50') 2024-01-31 01:14:27 +01:00
.commitlintrc.json chore: initial commit 2023-01-02 15:23:16 +01:00
.editorconfig chore: initial commit 2023-01-02 15:23:16 +01:00
.eslintrc.json chore: dependency vendoring of markdownlint-rule-helpers 2024-01-12 01:30:52 +01:00
.gitattributes chore: initial commit 2023-01-02 15:23:16 +01:00
.gitignore chore: initial commit 2023-01-02 15:23:16 +01:00
.lintstagedrc.json chore: cleaner configs 2024-01-29 21:24:22 +01:00
.markdownlint-cli2.jsonc chore: cleaner configs 2024-01-29 21:24:22 +01:00
.npmrc feat: add npm package provenance 2023-05-13 16:05:01 +02:00
.prettierrc.json chore: better Prettier config for easier reviews 2023-10-23 23:11:41 +02:00
.releaserc.json chore: initial commit 2023-01-02 15:23:16 +01:00
CODE_OF_CONDUCT.md fix: update author - Théo LUDWIG 2023-06-24 10:11:32 +02:00
CONTRIBUTING.md fix: update author - Théo LUDWIG 2023-06-24 10:11:32 +02:00
jsconfig.json chore: cleaner configs 2024-01-29 21:24:22 +01:00
LICENSE docs(license): add email address 2024-01-29 21:09:23 +01:00
package-lock.json chore: cleaner configs 2024-01-29 21:24:22 +01:00
package.json chore: cleaner configs 2024-01-29 21:24:22 +01:00
README.md refactor: simplify logic understanding 2024-01-30 23:57:38 +01:00

markdownlint-rule-relative-links

Custom rule for markdownlint to validate relative links.

CONTRIBUTING Licence MIT Contributor Covenant
Lint Test
Conventional Commits semantic-release npm version

📜 About

markdownlint-rule-relative-links is a markdownlint custom rule to validate relative links.

It ensures that relative links (using file: protocol) are working and exists in the file system of the project that uses markdownlint.

Example

File structure:

├── abc.txt
└── awesome.md

With awesome.md content:

[abc](./abc.txt)

[Invalid link](./invalid.txt)

Running markdownlint-cli2 with markdownlint-rule-relative-links will output:

awesome.md:3 relative-links Relative links should be valid ["./invalid.txt" should exist in the file system]

Additional features

  • Support images (e.g: ![Image](./image.png)).
  • Support links fragments similar to the built-in markdownlint rule - MD051 (e.g: [Link](./awesome.md#heading)).
  • Ignore external links and absolute paths as it only checks relative links (e.g: https://example.com/ or /absolute/path.png).

Limitations

  • Only images and links defined using markdown syntax are validated, html syntax is ignored (e.g: <a href="./link.txt" /> or <img src="./image.png" />).

Contributions are welcome to improve the rule, and to alleviate these limitations. See CONTRIBUTING.md for more information.

Prerequisites

Node.js >= 16.0.0

Installation

npm install --save-dev markdownlint-rule-relative-links

Configuration

There are various ways markdownlint can be configured using objects, config files etc. For more information on configuration refer to options.config.

We recommend configuring markdownlint-cli2 over markdownlint-cli for compatibility with the vscode-markdownlint extension.

.markdownlint-cli2.jsonc

{
  "config": {
    "default": true,
    "relative-links": true
  },
  "globs": ["**/*.md"],
  "ignores": ["**/node_modules"],
  "customRules": ["markdownlint-rule-relative-links"]
}

package.json

{
  "scripts": {
    "lint:markdown": "markdownlint-cli2"
  }
}

Usage

npm run lint:markdown

💡 Contributing

Anyone can help to improve the project, submit a Feature Request, a bug report or even correct a simple spelling mistake.

The steps to contribute can be found in the CONTRIBUTING.md file.

📄 License

MIT