alicruz-mdlinks

Contributor Covenant

alicruz-mdlinks is a module and command-line interface that verifies the links that a markdown file contains, validates that they are unbroken, and reports some statistics. Github repository AlissonCH

Installation

It is recommendable global install, to use both: API and command-line interface correctly.

npm module

alicruz-mdlinks

$ npm install --global alicruz-mdlinks

API

Parameters:

Returns:

Examples

const mdLinks = require('alicruz-mdlinks'); // if install is local
const mdLinks = require('../alicruz-mdlinks'); // if install is global

mdLinks('./some/example.md').then( links => {
 // => [{ href, text, file }, ...]
})
.catch( err => console.error(err))

mdLinks('./some/example.md', {validate : true }).then( links => {
 // => [{ href, text, file, status, statusText}, ...]
})
.catch( err => console.error(err))

mdLinks('./some/dir').then( links => {
 // => [{ href, text, file}, ...]
})
.catch( err => console.error(err))

mdLinks('./some/dir', {validate : true}).then(arrayOfLinks => {
 // => [{ href, text, file, status, statusText}, ...]
})
.catch( err => console.error(err))

mdLinks('./some/example.md', {stats : true }).then(arrayOfLinks => {
 // => {Total, Unique}
})
.catch( err => console.error(err))

mdLinks('./some/example.md', {stats : true, validate:true }).then(arrayOfLinks => {
 // => {Total, Unique, Broken}
})
.catch( err => console.error(err))

RESPONSE

Examples

mdLinks('./some/example.md').then( links => console.log(links))

// Console
[
 { href : 'http://somelink.com', 
   text : 'Some Link', 
   file: './some/example.md'
 },
 { href : 'http://otherthing.com', 
   text : 'Other Thing', 
   file: './some/example.md'
 },
 { href : 'http://google.com ', 
   text : 'Google', 
   file: './some/example.md'
 }
]

mdLinks('./some/example.md', {validate : true}).then( links => console.log(links))

// Console
[
 { href : 'http://somelink.com', 
   text : 'Some Link', 
   file: './some/example.md'
   status: 200,
   statusText : 'OK'
 },
 { href : 'http://otherthing.com', 
   text : 'Other Thing', 
   file: './some/example.md',
   status: 400,
   statusText : 'FAIL'
 },
 { href : 'http://google.com ', 
   text : 'Google', 
   file: './some/example.md',
   status: 200,
   statusText : 'OK'
 }
]

mdLinks('./some/example.md', {stats : true}).then( result => console.log(result))

// Console
 { 
  Total: 3, 
  Unique: 3
 }  

mdLinks('./some/example.md', {stats : true, vaidate: true}).then( result => console.log(result))

// Console
 { 
  Total: 3, 
  Unique: 3,
  Broken: 1
 } 

COMMAND LINE INTERFACE - CLI

md-links <path-to-file> [options]

Parameters:

Examples

$ md-links './some/example.md'
./some/example.md http://somelink.com Some Link
./some/example.md http://otherthing.com Other Thing
./some/example.md http://google.com Google
./some/example.md http://google.com Google

$ md-links './some/example.md' --validate 
./some/example.md http://somelink.com OK 200 Some Link 
./some/example.md http://otherthing.com FAIL 400 Other Thing
./some/example.md http://google.com OK 200 Google
./some/example.md http://google.com OK 200 Google

$ md-links './some/example.md' --stats
Total : 4
Unique : 3

$ md-links './some/example.md' --stats --validate
Total : 4
Unique : 3
Broken : 1

Contributing

Pull requests are welcome. For major changes, please open an issues first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT