markdown-link-check
is a powerful tool used to check the hyperlinks in a markdown text to determine if they are alive or dead. This package is essential for ensuring the accuracy and functionality of links in your markdown files.
Description
The latest version of markdown-link-check
is 3.12.1, and it was last published a month ago. To start using it in your project, simply run npm i markdown-link-check
. There are currently 8 other projects in the npm registry that utilize this package.
Why Use It?
markdown-link-check
is an indispensable tool for developers and content creators who work with markdown files. It helps ensure that all the links in your markdown files are functional and up-to-date. This can save you time and effort by identifying broken links before publishing or sharing your content.
Installation
To add the module to your project, run:
npm install --save-dev markdown-link-check
To install the command-line tool globally, run:
npm install -g markdown-link-check
Usage
API
markdownLinkCheck
is a Node.js module that accepts a markdown string and a callback function. It extracts all the links from the markdown text and checks if they are alive or dead.
const 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);
});
});
Options
The markdownLinkCheck
function accepts an optional opts
object with the following fields:
showProgressBar
: Enable an ASCII progress bar.timeout
: Timeout in zeit/ms format. Default 10s.httpHeaders
: To apply URL-specific headers, see the example below.ignorePatterns
: An array of objects holding regular expressions which a link is checked against and skipped for checking in case of a match.replacementPatterns
: An array of objects holding regular expressions which are replaced in a link with their corresponding replacement string.projectBaseUrl
: The URL to use for {{BASEURL}} replacement.ignoreDisable
: If this is true, then disable comments are ignored.retryOn429
: If this is true, then retry request when response is an HTTP code 429 after the duration indicated by retry-after header.retryCount
: The number of retries to be made on a 429 response. Default 2.fallbackRetryDelay
: The delay in zeit/ms format for retries on a 429 response when no retry-after header is returned or when it has an invalid value. Default is 60s.aliveStatusCodes
: A list of HTTP codes to consider as alive.
Disable comments
You can write HTML comments to disable markdown-link-check
for parts of the text.
<!-- markdown-link-check-disable -->
[disabled link](http://example.com)
<!-- markdown-link-check-enable -->
[enabled link](http://example.com)
Examples
Module
Basic usage
const 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
const 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 one argument, the file name or URL. If not supplied, the tool reads from standard input.
# Check links from a markdown file hosted on the web
markdown-link-check https://github.com/tcort/markdown-link-check/blob/master/README.md
# Check links from a local markdown file
markdown-link-check ./README.md
# Check links from a local markdown folder (recursive)
find . -name '*.md' -print0 | xargs -0 -n1 markdown-link-check
License
markdown-link-check
is released under the MIT License.