TypeScript icon, indicating that this package has built-in type declarations

12.1.1 • Public • Published


Build Coverage Downloads Size Sponsors Backers Chat

remark plugin to check that markdown links and images point to existing local files and headings in a Git repo.

For example, this document does not have a heading named Hello. So if we’d link to it ([welcome](#hello)), we’d get a warning. Links to headings in other markdown documents (examples/ and links to files (license or index.js) are also checked.


What is this?

This package is a unified (remark) plugin to check local links in a Git repo.

unified is a project that transforms content with abstract syntax trees (ASTs). remark adds support for markdown to unified. mdast is the markdown AST that remark uses. This is a remark plugin that inspects mdast.

When should I use this?

This project is useful if you have a Git repo, such as this one, with docs in markdown and links to headings and other files, and want to check whether they’re correct. Compared to other links checkers, this project can work offline (making it fast en prone to fewer false positives), and is specifically made for local links in Git repos. This plugin does not check external URLs (see remark-lint-no-dead-urls) or undefined references (see remark-lint-no-undefined-references).


This package is ESM only. In Node.js (version 14.14+, or 16.0+), install with npm:

npm install remark-validate-links

In Deno with

import remarkValidateLinks from ''

In browsers with

<script type="module">
  import remarkValidateLinks from ''


Say we have the following file,

# Alpha

Links are checked:

This [exists](#alpha).
This [one does not](#does-not).

# Bravo

Headings in `` are [checked](
And [missing files are reported](missing-example.js).

Definitions are also checked:

[alpha]: #alpha
[charlie]: #charlie

References w/o definitions are not checked: [delta]

And a module, example.js:

import {read} from 'to-vfile'
import {remark} from 'remark'
import remarkValidateLinks from 'remark-validate-links'


async function main() {
  const file = await remark()
    .process(await read(''))


Now, running node example yields:
    6:6-6:31  warning  Link to unknown heading: `does-not`         missing-heading  remark-validate-links
  11:5-11:53  warning  Link to unknown file: `missing-example.js`  missing-file     remark-validate-links
  16:1-16:20  warning  Link to unknown heading: `charlie`          missing-heading  remark-validate-links

⚠ 3 warnings

(Note that is not warned about, because the API does not check headings in other Markdown files).


This package exports no identifiers. The default export is remarkValidateLinks.

unified().use(remarkValidateLinks[, options])

Check that markdown links and images point to existing local files and headings in a Git repo.

⚠️ Important: The API in Node.js checks links to headings and files but does not check whether headings in other files exist. The API in browsers only checks links to headings in the same file. The CLI can check everything.


Typically, you don’t need to configure remark-validate-links, as it detects local Git repositories.


URL to hosted Git (string? or false). If repository is nullish, the Git origin remote is detected. If the repository resolves to something npm understands as a Git host such as GitHub, GitLab, or Bitbucket, then full URLs to that host (say, can also be checked. If you’re not in a Git repository, you must pass repository: false explicitly.


A root (string?) can also be passed, referencing the local Git root directory (the folder that contains .git). If both root and repository are nullish, the Git root is detected. If root is not given but repository is, file.cwd is used.


If your project is hosted on,, or, this plugin can automatically detect the url configuration. Otherwise, use urlConfig to specify this manually. For this repository (remarkjs/remark-validate-links on GitHub) urlConfig looks as follows:

  // Domain of URLs:
  hostname: '',
  // Path prefix before files:
  prefix: '/remarkjs/remark-validate-links/blob/',
  // Prefix of headings:
  headingPrefix: '#',
  // Hash to top of markdown documents:
  topAnchor: '#readme',
  // Whether lines in files can be linked:
  lines: true

If this project were hosted on Bitbucket, it would be:

  hostname: '',
  prefix: '/remarkjs/remark-validate-links/src/',
  headingPrefix: '#markdown-header-',
  lines: false


Example: CLI

It’s recommended to use remark-validate-links on the CLI with remark-cli. Install both with npm:

npm install remark-cli remark-validate-links --save-dev

Let’s say we have a (this current document) and an with the following text:

# Hello

Read more [whoops, this does not exist](#world).

This doesn’t exist either [whoops!](

But this does exist: [license](license).

So does this: [readme](

Now, running ./node_modules/.bin/remark --use remark-validate-links . yields:
  3:11-3:48  warning  Link to unknown heading: `world`               missing-heading          remark-validate-links
  5:27-5:51  warning  Link to unknown heading in ``: `foo`  missing-heading-in-file  remark-validate-links no issues found

⚠ 2 warnings

Example: CLI in npm scripts

You can use remark-validate-links and remark-cli in an npm script to check and format markdown in your project. Install both with npm:

npm install remark-cli remark-validate-links --save-dev

Then, add a format script and configuration to package.json:

  // …
  "scripts": {
    // …
    "format": "remark . --quiet --frail --output",
    // …
  "remarkConfig": {
    "plugins": [
  // …

💡 Tip: Add other tools such as prettier or ESLint to check and format other files.

💡 Tip: Run ./node_modules/.bin/remark --help for help with remark-cli.

Now you check and format markdown in your project with:

npm run format


remark-validate-links can detect anchors on nodes through several properties on nodes:

  • — Used by mdast-util-to-hast to create a name attribute, which anchors can link to
  • — Used by mdast-util-to-hast to create an id attribute, which anchors can link to
  • — Used potentially in the future by other tools to signal unique identifiers on nodes


This package is fully typed with TypeScript. It exports an Options type, which specifies the interface of the accepted options, and an UrlConfig type, which specifies the interface of its corresponding option.


Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+, and 16.0+. Our projects sometimes work with older versions, but this is not guaranteed.

This plugin works with unified version 6+, remark version 7+, and remark-cli version 8+.


remark-validate-links, in Node, accesses the file system based on user content, and this may be dangerous. In Node git remote and git rev-parse also runs for processed files.

The tree is not modified, so there are no openings for cross-site scripting (XSS) attacks.



See in remarkjs/.github for ways to get started. See for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.


MIT © Titus Wormer


npm i remark-validate-links

DownloadsWeekly Downloads






Unpacked Size

46.7 kB

Total Files


Last publish


  • johno
  • wooorm