remark-relative-links

0.0.6 • Public • Published

remark-relative-links

Rewrites absolute URLs to relative ones with remark

Installation

yarn add remark-relative-links

Usage

Source

const html = require('remark-html');
const remark = require('remark');
const relativeLinks = require('remark-relative-links');
 
remark()
  .use(relativeLinks, {
    domainRegex: /http[s]*:\/\/[www.]*yoursite\.com[/]?/,
  })
  .use(html)
  .process('[Blog](https://yoursite.com/blog/article/)', (err, file) => {
    if (err) throw err
    console.log(String(file))
  });

Yields

<p><a href="/blog/article/">Blog</a></p>

API

remark.use(relativeLinks[, options])

Add target and rel attributes to external links.

options.domainRegex Required

Regex used to decipher what domain to "relative-ize". The example provided should handle most cases.

License

MIT

Package Sidebar

Install

npm i remark-relative-links

Weekly Downloads

395

Version

0.0.6

License

MIT

Unpacked Size

3.26 kB

Total Files

4

Last publish

Collaborators

  • zachschnackel