markdownlint-rule-relative-.../README.md

122 lines
4.7 KiB
Markdown
Raw Normal View History

2023-01-02 15:23:16 +01:00
<h1 align="center">markdownlint-rule-relative-links</h1>
<p align="center">
<strong>Custom rule for <a href="https://github.com/DavidAnson/markdownlint">markdownlint</a> to validate relative links.</strong>
</p>
<p align="center">
2023-11-23 00:40:34 +01:00
<a href="./CONTRIBUTING.md"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" alt="CONTRIBUTING" /></a>
2023-01-02 15:23:16 +01:00
<a href="./LICENSE"><img src="https://img.shields.io/badge/licence-MIT-blue.svg" alt="Licence MIT"/></a>
<a href="./CODE_OF_CONDUCT.md"><img src="https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg" alt="Contributor Covenant" /></a>
<br />
2023-11-23 00:40:34 +01:00
<a href="https://github.com/theoludwig/markdownlint-rule-relative-links/actions/workflows/lint.yml"><img src="https://github.com/theoludwig/markdownlint-rule-relative-links/actions/workflows/lint.yml/badge.svg?branch=develop" alt="Lint" /></a>
2024-01-10 21:09:11 +01:00
<a href="https://github.com/theoludwig/markdownlint-rule-relative-links/actions/workflows/test.yml"><img src="https://github.com/theoludwig/markdownlint-rule-relative-links/actions/workflows/test.yml/badge.svg?branch=develop" alt="Test" /></a>
2023-01-02 15:23:16 +01:00
<br />
<a href="https://conventionalcommits.org"><img src="https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg" alt="Conventional Commits" /></a>
<a href="https://github.com/semantic-release/semantic-release"><img src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg" alt="semantic-release" /></a>
<a href="https://www.npmjs.com/package/markdownlint-rule-relative-links"><img src="https://img.shields.io/npm/v/markdownlint-rule-relative-links.svg" alt="npm version"></a>
</p>
## 📜 About
**markdownlint-rule-relative-links** is a [markdownlint](https://github.com/DavidAnson/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](https://github.com/DavidAnson/markdownlint).
2023-01-02 15:23:16 +01:00
### Example
File structure:
```txt
├── abc.txt
└── awesome.md
```
With `awesome.md` content:
```md
[abc](./abc.txt)
[Invalid link](./invalid.txt)
```
2023-05-13 16:03:06 +02:00
Running [markdownlint-cli2](https://github.com/DavidAnson/markdownlint-cli2) with `markdownlint-rule-relative-links` will output:
```sh
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)`).
2024-01-12 00:50:17 +01:00
- Support links fragments similar to the [built-in `markdownlint` rule - MD051](https://github.com/DavidAnson/markdownlint/blob/main/doc/md051.md) (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
2024-01-12 00:50:17 +01:00
- 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](./CONTRIBUTING.md) for more information.
### Related links
2023-01-02 15:23:16 +01:00
- [DavidAnson/markdownlint#253](https://github.com/DavidAnson/markdownlint/issues/253)
- [DavidAnson/markdownlint#121](https://github.com/DavidAnson/markdownlint/issues/121)
- [nschonni/markdownlint-valid-links](https://github.com/nschonni/markdownlint-valid-links)
## Prerequisites
2024-01-30 23:57:38 +01:00
[Node.js](https://nodejs.org/) >= 16.0.0
2023-01-02 15:23:16 +01:00
## Installation
```sh
npm install --save-dev markdownlint-rule-relative-links
```
## Configuration
2023-05-13 16:03:06 +02:00
There are various ways [markdownlint](https://github.com/DavidAnson/markdownlint) can be configured using objects, config files etc. For more information on configuration refer to [options.config](https://github.com/DavidAnson/markdownlint#optionsconfig).
2023-01-02 15:23:16 +01:00
2023-05-13 16:03:06 +02:00
We recommend configuring [markdownlint-cli2](https://github.com/DavidAnson/markdownlint-cli2) over [markdownlint-cli](https://github.com/igorshubovych/markdownlint-cli) for compatibility with the [vscode-markdownlint](https://github.com/DavidAnson/vscode-markdownlint) extension.
2023-01-02 15:23:16 +01:00
`.markdownlint-cli2.jsonc`
```json
{
"config": {
"default": true,
"relative-links": true
},
2024-01-30 23:57:38 +01:00
"globs": ["**/*.md"],
2023-01-02 15:23:16 +01:00
"ignores": ["**/node_modules"],
"customRules": ["markdownlint-rule-relative-links"]
}
```
`package.json`
```json
{
"scripts": {
"lint:markdown": "markdownlint-cli2"
}
}
```
## Usage
```sh
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](./CONTRIBUTING.md) file.
## 📄 License
[MIT](./LICENSE)