npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mdast-validate-links

v1.1.1

Published

Validate links to headings and files in markdown

Downloads

103

Readme

mdast-validate-links Build Status Coverage Status

mdast plug-in to validate if links to headings and files in markdown point to existing things.

For example, this document does not have a heading named Hello. So if I link to that ([welcome](#hello)), this plug-in will warn about it.

In addition, when I link to a heading in another document (examples/foo.md#hello), if this file exists but the heading does not, or if the file does not exist, this plug-in will also warn.

Linking to other files, such as LICENSE or index.js (when they exist) is fine.

Table of Contents

Installation

npm:

npm install mdast-validate-links

Command line

Example of how mdast-validate-links looks on screen

Use mdast-validate-links together with mdast and mdast-slug:

npm install --global mdast mdast-slug mdast-validate-links

Let’s say readme.md is this document, and example.md looks as follows:

# Hello

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

This doesn’t exist either [whoops!](readme.md#foo).

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

So does this: [README](readme.md#installation).

Then, to run mdast-validate-links on example.md and readme.md:

mdast -u mdast-slug -u mdast-validate-links example.md
#
# Yields:
#
# example.md
#   3:11  warning  Link to unknown heading: `world`
#   5:27  warning  Link to unknown heading in `readme.md`: `foo`
#
# ✖ 2 problems (0 errors, 2 warnings)

Programmatic

This plug-in is not available on the API of mdast.

Configuration

You can pass a repository, containing anything package.jsons repository can handle. If this is omitted, mdast-validate-links will try the package.json in your current working directory.

mdast --use 'validate-links=repository:"foo/bar"' example.md

When a repository is given or detected, links to GitHub are normalized to the file-system. E.g., https://github.com/foo/bar/blob/master/example.md becomes example.md.

You can define this repository in .mdastrc or package.json files too. An example .mdastrc file could look as follows:

{
  "plugins": {
    "slug": {
      "library": "github"
    },
    "validate-links": {
      "repository": "foo/bar"
    }
  }
}

Related

License

MIT © Titus Wormer