tcort / markdown-link-extractor

extracts links from markdown texts
ISC License
23 stars 19 forks source link

Returns an Object of Data from the Links #9

Closed th3n00bc0d3r closed 3 years ago

th3n00bc0d3r commented 4 years ago

Rather than having a single link, it will now return an object which can be traversed for more control over the data.

th3n00bc0d3r commented 4 years ago

I would really need help in the unit tests....

tcort commented 3 years ago

I've implemented an extended output option.

The second argument is used to enable extended output mode which returns an object rather than just a URL string...

const details = markdownLinkExtractor(markdown, true);
details.forEach(detail => console.log(detail));

The object takes this form:

{ type: 'link',
  raw:
   '[LICENSE.md](https://github.com/tcort/markdown-link-extractor/blob/master/LICENSE.md)',
  href:
   'https://github.com/tcort/markdown-link-extractor/blob/master/LICENSE.md',
  title: null,
  text: 'LICENSE.md',
  tokens: [ { type: 'text', raw: 'LICENSE.md', text: 'LICENSE.md' } ] }