Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

markdown-link-check

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markdown-link-check

checks the all of the hyperlinks in a markdown text to determine if they are alive or dead

  • 3.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
32K
decreased by-53.52%
Maintainers
1
Weekly downloads
 
Created
Source

Extracts links from markdown texts and checks whether each link is alive (200 OK) or dead. mailto: links are validated with isemail.

Installation

To add the module to your project, run:

npm install --save markdown-link-check

To install the command line tool globally, run:

npm install -g markdown-link-check

Run using Docker

Build a Docker image:

docker build --tag markdown-link-check .

Pipe your README.md file to docker run:

docker run --rm -i markdown-link-check < README.md

API

markdownLinkCheck(markdown, [opts,] callback)

Given a string containing markdown formatted text and a callback, extract all of the links and check if they're alive or dead. Call the callback with (err, results)

Parameters:

  • markdown string containing markdown formatted text.
  • opts optional options object containing any of the following optional fields:
    • baseUrl the base URL for relative links.
    • showProgressBar enable an ASCII progress bar.
    • httpHeaders to apply URL specific headers, see example below.
  • callback function which accepts (err, results).
    • err an Error object when the operation cannot be completed, otherwise null.
    • results an array of objects with the following properties:
      • link the link provided as input
      • status a string set to either alive or dead.
      • statusCode the HTTP status code. Set to 0 if no HTTP status code was returned (e.g. when the server is down).
      • err any connection error that occurred, otherwise null.

Examples

Module

Basic usage:

'use strict';

var markdownLinkCheck = require('markdown-link-check');

markdownLinkCheck('[example](http://example.com)', function (err, results) {
    if (err) {
        console.error('Error', err);
        return;
    }
    results.forEach(function (result) {
        console.log('%s is %s', result.link, result.status);
    });
});

With options, for example using URL specific headers:

'use strict';

var markdownLinkCheck = require('markdown-link-check');

markdownLinkCheck('[example](http://example.com)', { httpHeaders: [{ urls: ['http://example.com'], headers: { 'Authorization': 'Basic Zm9vOmJhcg==' }}] }, function (err, results) {
    if (err) {
        console.error('Error', err);
        return;
    }
    results.forEach(function (result) {
        console.log('%s is %s', result.link, result.status);
    });
});

Command Line Tool

The command line tool optionally takes 1 argument, the file name or http/https URL. If not supplied, the tool reads from standard input.

markdown-link-check https://github.com/tcort/markdown-link-check/blob/master/README.md
markdown-link-check ./README.md
find . -name \*.md -exec markdown-link-check {} \;
cat *.md | markdown-link-check
Usage

  Usage: markdown-link-check [options] [filenameOrUrl]

  Options:

    -h, --help             output usage information
    -p, --progress         show progress bar
    -c, --config [config]  apply a config file (JSON), holding e.g. URL specific header configuration

Config file format

config.json:

{
    "httpHeaders": [
        {
            "urls": [
                "https://example.com"
            ],
            "headers": {
                "Authorization": "Basic Zm9vOmJhcg==",
                "Foo": "Bar"
            }
        }
    ]
}

httpHeaders: The headers are only applied to links where the link starts with one of the supplied URLs in the urls section.

Testing

npm test

License

See LICENSE.md

Keywords

FAQs

Package last updated on 15 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc