zslabs / remark-relative-links

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

License:MIT License


Languages

Language:JavaScript 100.0%