Skip to content

zslabs/remark-relative-links

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published