GithubHelp home page GithubHelp logo

raulingg / md-links Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 1.08 MB

find and verify links within markdown files easily.

License: ISC License

JavaScript 100.00%
nodejs markdown-links broken-link-finder broken-links

md-links's Introduction

๐Ÿ”— Markdown Links

Node.js CI Coverage Status

an implementation of Md Links project

Features

  • 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

Installing

  • globally

    npm install -g @raulingg/md-links`
  • locally, as dependency in your project

    npm install @raulingg/md-links

Using

In a project

Requiring commonjs module

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

Importing ES module

import mdLinks from require('@raulingg/md-links')

const mdlink = await mdLinks('path/to/file.md')
const results = mdlink.data()

// do whatever you want

validating broken links

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

Getting stats

/**
 * 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());

CLI

Get links

# single file
md-links <path/to/file.md>

# scan all markdown files in a folder
md-links <path/to/dir>

Validate links

md-links <path/to/dir> --validate

Get stats

md-links <path/to/dir> --stats

# validate and return stats
md-links <path/to/dir> --validate --stats

Markdown file

Extensions supported

  • .md, .markdown

Format supported

Basic Cases

[valid link](http://test.com)
[[email protected]](http://test.com/test-link?djdjd&)
[title (parenthesis)](http://www.test.com)
[title with
linebreak](http://test.com)

Extra Cases

[[extra sq bracket](https://test.com?g=154&fh=!445?)

Video Case

[![Solution Temperature converter](https://i.ytimg.com/vi/Ix6VLiBcABw/0.jpg)](https://www.youtube.com/watch?v=Ix6VLiBcABw)

Unsupported Cases

[extra sq bracket - invalid]](https://test.com)

[link with linebreak - invalid](http:
//test.com)

md-links's People

Contributors

dependabot[bot] avatar raulingg avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

yfears

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.