README
Get Markdown Links
A simple Node.js library that checks and validates URL links in a given markdown (*.md) file. It can either be used through the CLI or imported as a module to other JavaScript projects.
NPM Installation
$ npm install get-markdown-links
Note: When using the CLI, if the package was installed locally, you must use the npx mdlinks
command, otherwise it will not work. If installed globally, mdlinks
will suffice.
CLI Usage Instructions
$ mdlinks path\to\markdown\file.md
This will print to the console a list of all links found in the provided markdown (.*md) file.
$ mdlinks path\to\markdown\file.md --validate
This will validate all links found inside the provided markdown (.*md) file through a quick http(s) request and then print to the console a list of all the validated links.
$ mdlinks path\to\markdown\file.md --stats
This will print to the console the unique, as well as the total number of links found inside the provided markdown (.*md) file.
$ mdlinks path\to\markdown\file.md --validate --stats
This will print to the console the unique, broken and total number of links found inside the provided markdown (.*md) file.
$ mdlinks path\to\directory
This will print to the console a list of all the markdown files found in the provided directory.
JS Usage Instructions
const mdLinks = require("../index");
First, we import the module so we can then call the mdLinks function.
The mdLinks function can be called with one or two arguments, the file path and an option.
mdLinks(filePath).then().catch();
mdLinks(filePath, { option }).then().catch();
Some examples of valid file paths:
'./path/to/md/file.md'
'./file.md'
'file.md'
'\file.md'
'\\path\\to\\md\\file.md'
Note: In order for the file path to work, backslashes must be escaped or forward slashes must be used instead.
One, two or five link collection arrays will be returned depending on the option set as the second argument:
mdLinks('./path/to/md/file.md').then((result) => {}).catch((error) => {});
When called without an option, it will return an object with a single array parsedLinksCollection
with all the links found in the provided markdown (.*md) file.
mdLinks('./path/to/md/file.md', { validate: true }).then((result) => {}).catch((error) => {});
When the option is set to { validate: true }
, it will validate all the links through a quick http(s) request and then return an object with two arrays, parsedLinksCollection
with all the non-validated links and validatedLinksCollection
with all the validated links found inside the provided markdown (*.md) file.
mdLinks('./path/to/md/file.md', { stats: true }).then((result) => {}).catch((error) => {});
When the option is set to { stats: true }
, it will filter all the unique links and then return an object with two arrays, parsedLinksCollection
with all the non-validated links and uniqueLinksCollection
with all the unique links found inside the provided markdown (*.md) file.
mdLinks('./path/to/md/file.md', { validateStats: true }).then((result) => {}).catch((error) => {});
When the option is set to { validateStats: true }
, it will first validate all the links through a quick http(s) request, then filter all the unique, working and broken links and then return an object with five arrays, parsedLinksCollection
, with all the non-validated links, validatedLinksCollection
with all the validated links, uniqueLinksCollection
with all the unique links, workingLinksCollection
with all the links that work and finally brokenLinksCollection
with all the broken links found inside the provided markdown (*.md) file.
HELP
If you need more help, you can contact me at ugocinc (at) gmail (dot) com.
GitHub
In case you find any bugs you can create a New Issue on GitHub and I will look into it.