The Big Picture - open-telemetry/opentelemetry.io - Markdown-link-check

Markdown-link-check: A Powerful Tool for Checking Markdown Links

Markdown-link-check is a versatile and essential tool for anyone working with markdown files. It checks the hyperlinks in markdown texts to ensure they are functional and up-to-date. This tool can be installed using npm, and it can be run as a module, a command-line tool, or even as a pre-commit hook. Markdown-link-check supports various options, such as URL-specific headers, timeouts, and retry mechanisms, making it highly customizable.

Usage as a Module

To use markdown-link-check as a module, first install it using npm:

npm install markdown-link-check

Then, require the module and call its markdownLinkCheck function with a markdown link as the first argument and a callback function as the second argument:

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);
});
});

The callback function is called with an error object and an array of results when the link checking process is complete. Each result object contains the link, its status (alive, ignored, or dead), its HTTP status code, and any connection errors that occurred.

Usage as a Command-Line Tool

Markdown-link-check can also be used as a command-line tool to check the links in a markdown file or folder. For example, to check the links in a local markdown file named README.md, run:

markdown-link-check ./README.md

Or, to check the links in a local markdown folder named docs, use:

find . -name '*.md' -print0 | xargs -0 -n1 markdown-link-check

This command uses find to locate all markdown files in the current directory and its subdirectories, and then passes each file to markdown-link-check using xargs.

Configuration Options

Markdown-link-check supports various options to customize its behavior. Some of the most commonly used options include:

  • --timeout: The maximum time (in milliseconds) to wait for a response from a link before considering it dead.
  • --retries: The number of times to retry a dead link before considering it permanently dead.
  • --header: A custom header to include in HTTP requests.

For a complete list of options, run markdown-link-check --help.

Integration with Other Tools

Markdown-link-check can be integrated with other tools like Mega-Linter and GitHub actions to automate the link-checking process. For more information, refer to the official documentation.

Conclusion

Markdown-link-check is a powerful and versatile tool for anyone working with markdown files. It ensures the accuracy and functionality of all the hyperlinks in the files, making it an essential addition to any project. Its various options and integration with other tools make it a valuable asset for developers and content creators alike.