an implementation of Md Links project
- Finds links in a markdown file (.md | .markdown)
- Finds links in a folder recursively.
- Validate links by making a HTTP GET request and checking the response's status code.
- Runs from CLI
-
globally
npm install -g @raulingg/md-links`
-
locally, as dependency in your project
npm install @raulingg/md-links
const mdLinks = require('@raulingg/md-links')
mdLinks('path/to/file.md')
.then(mdlink => {
// Return an object with two methods data and stats
// data() return an array with results
mdlink.data().forEach(item => {
console.log(item.path, item.href, item.text)
})
});
// find links in all markdown files inside a directory
mdLinks('path/to/directory').data().then(data => {});
import mdLinks from require('@raulingg/md-links')
const mdlink = await mdLinks('path/to/file.md')
const results = mdlink.data()
// do whatever you want
mdLinks('path/to/file.md', { validate: true}).then((mdlink) => {
mdlink.data().forEach((item) => {
console.log(item.path, item.text, item.href, item.status, item.statusCode)
})
});
/**
* Stats Object
* {
* total: <#linksFound>
* unique: <#LinksUnique>
* broken: <#LinksBroken>
* }
*/
mdLinks('path/to/file.md').then(mdlink => mdlink.stats());
// get stats from broken links
mdLinks('path/to/file.md', { validate: true}).then(mdlink => mdlink.stats());
# single file
md-links <path/to/file.md>
# scan all markdown files in a folder
md-links <path/to/dir>
md-links <path/to/dir> --validate
md-links <path/to/dir> --stats
# validate and return stats
md-links <path/to/dir> --validate --stats
.md
,.markdown
[valid link](http://test.com)
[test-link@test.com](http://test.com/test-link?djdjd&)
[title (parenthesis)](http://www.test.com)
[title with
linebreak](http://test.com)
[[extra sq bracket](https://test.com?g=154&fh=!445?)
[![Solution Temperature converter](https://i.ytimg.com/vi/Ix6VLiBcABw/0.jpg)](https://www.youtube.com/watch?v=Ix6VLiBcABw)
[extra sq bracket - invalid]](https://test.com)
[link with linebreak - invalid](http:
//test.com)