1# mdast-validate-links [](https://travis-ci.org/wooorm/mdast-validate-links) [](https://codecov.io/github/wooorm/mdast-validate-links)
3[**mdast**](https://github.com/wooorm/mdast) plug-in to validate if links to
4headings and files in markdown point to existing things.
6For example, this document does not have a heading named `Hello`. So if I
7link to that (`[welcome](#hello)`), this plug-in will warn about it.
9In addition, when I link to a heading in another document
10(`examples/foo.md#hello`), if this file exists but the heading does not,
11or if the file does not exist, this plug-in will also warn.
13Linking to other files, such as `LICENSE` or `index.js` (when they exist)
18* [Installation](#installation)
19* [Command line](#command-line)
20* [Programmatic](#programmatic)
21* [Configuration](#configuration)
27[npm](https://docs.npmjs.com/cli/install):
30npm install mdast-validate-links
35
37Use **mdast-validate-links** together with [**mdast**](https://github.com/wooorm/mdast)
38and [**mdast-slug**](https://github.com/wooorm/mdast-slug):
41npm install --global mdast mdast-slug mdast-validate-links
44Let’s say `readme.md` is this document, and `example.md` looks as follows:
49Read more [whoops, this does not exist](#world).
51This doesn’t exist either [whoops!](readme.md#foo).
53But this does exist: [LICENSE](LICENSE).
55So does this: [README](readme.md#installation).
58Then, to run **mdast-validate-links** on `example.md` and `readme.md`:
61mdast -u mdast-slug -u mdast-validate-links example.md
66# 3:11 warning Link to unknown heading: `world`
67# 5:27 warning Link to unknown heading in `readme.md`: `foo`
69# ✖ 2 problems (0 errors, 2 warnings)
74This plug-in is **not** available on the API of mdast.
78You can pass a `repository`, containing anything `package.json`s
79[`repository`](https://docs.npmjs.com/files/package.json#repository) can
80handle. If this is omitted, **mdast-validate-links** will try
81the `package.json` in your current working directory.
84mdast --use 'validate-links=repository:"foo/bar"' example.md
87When a repository is given or detected, links to GitHub are normalized
88to the file-system. E.g., `https://github.com/foo/bar/blob/master/example.md`
91You can define this repository in `.mdastrc` or `package.json` [files](https://github.com/wooorm/mdast/blob/master/doc/mdastrc.5.md)
92too. An example `.mdastrc` file could look as follows:
101 "repository": "foo/bar"
109* [`mdast-lint`](https://github.com/wooorm/mdast-lint)
110 — Markdown code style linter.
114[MIT](LICENSE) © [Titus Wormer](http://wooorm.com)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list