New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@raulingg/md-links

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@raulingg/md-links

This library allows you to find links within markdown files

  • 0.5.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

This repository is an implementation of this proposal

Node.js CI Coverage Status

Find all links included in a markdown file or in all markdown files inside a folder.

Installation

to install globally

npm install -g @raulingg/md-links

to install as a dependency in your project

npm install @raulingg/md-links

Usage

  • Requiring dependency

    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 using ES6

    import mdLinks from require('@raulingg/md-links')
    
    const mdlink = await mdLinks('path/to/file.md')
    const results = mdlink.data()
    
    // do whatever you want
    
  • validate 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)
      })
    });
    
  • Get 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

  • Basic usage

    # single file
    md-links <path/to/file.md>
    
    # scan all markdown files in directory
    md-links <path/to/directory>
    
  • Adding a validation option (--validate or -val)

    md-links <path/to/directory> --validate
    
  • Get stats about how many links and broken links exist

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

Markdown file

Extensions supported

  • .md
  • .markdown

Format supported

  • Basic Cases

    [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 Cases

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

    Find image and video url

    [![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)
    

Keywords

FAQs

Package last updated on 02 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc