# textlint-rule-no-dead-relative-link

> Textlint rule to validate relative links(including anchor links) in markdown documents

Latest version **1.0.3** (published 2022-03-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install textlint-rule-no-dead-relative-link
pnpm add textlint-rule-no-dead-relative-link
yarn add textlint-rule-no-dead-relative-link
bun add textlint-rule-no-dead-relative-link
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2022-03-15 |
| First published | 2019-05-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 3 |
| Unpacked size | 25.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Parth Patel |
| Maintainers | parthpp |
| Keywords | textlintrule, textlint, validate relative link, validate anchor link |

## Links

- npm: https://www.npmjs.com/package/textlint-rule-no-dead-relative-link
- Repository: https://github.com/parthpp/textlint-rule-no-dead-relative-link
- Homepage: https://github.com/parthpp/textlint-rule-no-dead-relative-link#readme
- Issues: https://github.com/parthpp/textlint-rule-no-dead-relative-link/issues
- npm.io page: https://npm.io/package/textlint-rule-no-dead-relative-link

## Dependencies (3)

- [github-slugger](https://npm.io/package/github-slugger.md) ^1.2.1
- [@babel/polyfill](https://npm.io/package/@babel/polyfill.md) ^7.4.4
- [textlint-rule-helper](https://npm.io/package/textlint-rule-helper.md) ^2.1.1

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2022-03-15
- 1.0.2 — 2020-01-07
- 1.0.1 — 2019-07-12
- 1.0.0 — 2019-05-15

## README

# textlint-rule-no-dead-relative-link

This is a [textlint rule](https://github.com/textlint/textlint/wiki/Collection-of-textlint-rule) that validate links in markdown documents. It does the following
- It ignores external link. The `RegExp` used to filter out such links is `/^[a-z][a-z0-9+.-]*:/i`
- For all relative links, it checks that there is a file specified by the link. The relative links are resolved relative to the file containing the link.
- For all relative links with anchors or just anchor within the same file, it checks that the anchor exists. It treats anchor links to markdown documents the same way as github does i.e. the rule uses [github-slugger](https://github.com/Flet/github-slugger) to do validation.  

## Installation
- Since this is a textlint rule, first install textlint by following the [textlint getting started guide](https://textlint.github.io/docs/getting-started.html).  
- This rule is available as an npm package and can be installed using 
    - `npm install --save-dev textlint-rule-no-dead-relative-link`  
     or 
    - `yarn add --dev textlint-rule-no-dead-relative-link`  and then `yarn install`

## Usage

If you are unfamiliar with textlint then refer to [configuring textlint](https://textlint.github.io/docs/configuring.html) for textlint configuration details.  

Add one of the following to `.textlintrc` file
- without any options

```json
{
    "rules": {
        "no-dead-relative-link": true
    }
}
```
or 
- with options

```json
{
    "rules": {
        "no-dead-relative-link": {
            "resolve-as-markdown": "[.html]"
        }
    }
}
```

To use it via command line arguments

```
textlint --rule textlint-rule-no-dead-relative-link README.md
```

## Options

### resolve-as-markdown

This option takes an array of file extension values and treats files with those extensions as if they are markdown files.  

For e.g. With the following configuration
```json
{
    "rules": {
        "no-dead-relative-link": {
            "resolve-as-markdown": [".html"]
        }
    }
}
```

and `[README](README.html)` as input, this rule will check for the existence of `README.md` file.

### route-map
Use this option when relative links need to be validated using an alternate file path. 

This option takes an array of source and destination pairs. The source value is a `Regex`, and the destination value is 
a `String` that can include capture groups from the `source` using the `$` notation. 

For e.g. With the following configuration
```json
{
    "rules": {
        "no-dead-relative-link": {
            "route-map": [
                {
                    "source": "^../javadocs/(\\d+\\.\\d+\\.\\w+)", 
                    "destination": "../../static/javadocs/$1"
                }
            ]
        }
    }
}
```

and `../javadocs/1.0.x/overview-summary.html` as the link being checked, this rule checks for the existence of the 
`overview-summary.html` file at `../../static/javadocs/1.0.x/overview-summary.html`.

##### Note #####
Ensure each `route-map` pair is specific because the route-map option will validate relative links using the first 
matching regex found in the configuration.

For e.g. With the following configuration
```json
{
    "rules": {
        "no-dead-relative-link": {
            "route-map": [
                {
                    "source": "../../javadocs/",
                    "destination": "../website/static/javadocs/"
                },
                {
                    "source": "../javadocs/1.0.x/",
                    "destination": "../../static/javadocs/1.0.x/"
                }
            ]
        }
    }
}
```

and `../../javadocs/1.0.x/overview-summary.html` as the link being checked, this rule checks for the existence of the
`overview-summary.html` file at the first destination `../website/static/javadocs/1.0.x/overview-summary.html` instead 
of the second destination `../../static/javadocs/1.0.x/overview-summary.html`.

## License

MIT © parthopensource@gmail.com

---
_Source: https://npm.io/package/textlint-rule-no-dead-relative-link · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
