Markdown-Links-Validator provides a Javascript API that parses, lists and validates the Markdown links contained in a directory or file, it also provides a Command Line that, in addition to the above, displays its statistics.
path
: relative or absolute path string to points to a directory or file.options
: an object{ validate: true}
to validate links.
It returns an array
of objects
, where each object contains properties of a link.
href
: URL found.text
: text that appeared within the link<a>
.path
: path of the file where the link was found.
const mdLinks = require("md-links-validator");
mdLinks("./some/example.md")
.then(links => {
// => [{ href, text, file }]
})
.catch(console.error);
mdLinks("./some/example.md", { validate: true })
.then(links => {
// => [{ href, text, file, status, message }]
})
.catch(console.error);
mdLinks("./some/dir")
.then(links => {
// => [{ href, text, file }]
})
.catch(console.error);
The command line is run in two ways through the terminal:
To get started, run the following command line:
If you select this option, the first step will be to enter a valid path (it must exist and be a string) that points to your file or directory containing markdown files, otherwise these errors will appear.
If you entered a valid path, the following options will appear:
Select one of those and then the result will be displayed:
You can select another option after that and repeat the process.
If you want to do it on this way, you can start all the process with the next command line and structure.
The options are:
--validate: check status links.
If you pass --validate
or --v
option, the module will make an HTTP request to find out if the link works or not. If the link results in a redirect to a URL that responds "OK", then the link is considered "OK", otherwise the respective status will appear in red and if the request was rejected it will appear "FAIL".
--stats: display statistics of total and unique links.
If you pass the option --stats
or --s
the output will be a text with basic statistics about the links.
--validate --stats: display statistics of total, unique and broken links
You can also combine --stats
and --validate
to get needed statistics from the validation results.