markdownlint-rule-relative-links

3.0.0 • Public • Published

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.

Related links

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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
3.0.0
1,624latest

Version History

VersionDownloads (Last 7 Days)Published
3.0.0
1,624
2.3.2
12
2.3.1
10
2.3.0
3
2.2.0
0
2.1.3
0
2.1.2
1
2.1.1
3
2.1.0
1
2.0.0
0
1.2.0
30
1.1.20
1.1.10
1.1.00
1.0.00

Package Sidebar

Install

npm i markdownlint-rule-relative-links

Weekly Downloads

1,684

Version

3.0.0

License

MIT

Unpacked Size

18 kB

Total Files

6

Last publish

Collaborators

  • theoludwig