Need private packages and team management tools?Check out npm Teams »

remark-external-links

5.0.0 • Public • Published

remark-external-links

Build Coverage Downloads Size Sponsors Backers Chat

remark plugin to automatically add target and rel attributes to external links.

Install

npm:

npm install remark-external-links

Use

Say we have the following file, example.js:

var remark = require('remark')
var html = require('remark-html')
var externalLinks = require('remark-external-links')
 
remark()
  .use(externalLinks, {target: false, rel: ['nofollow']})
  .use(html)
  .process('[remark](https://github.com/remarkjs/remark)', function(err, file) {
    if (err) throw err
    console.log(String(file))
  })

Now, running node example yields:

<p><a href="https://github.com/remarkjs/remark" rel="nofollow">remark</a></p>

API

remark().use(externalLinks[, options])

Automatically add target and rel attributes to external links.

options
options.target

How to display referenced documents (string?: _self, _blank, _parent, or _top, default: _blank). Pass false to not set targets on links.

options.rel

Link types to hint about the referenced documents (Array.<string> or string, default: ['nofollow', 'noopener', 'noreferrer']). Pass false to not set rels on links.

When using a target, add noopener and noreferrer to avoid exploitation of the window.opener API.

options.protocols

Protocols to check, such as mailto or tel (Array.<string>, default: ['http', 'https']).

options.content

hast content to insert at the end of external links (Node or Children). Will be inserted in a <span> element.

Useful for improving accessibility by giving users advanced warning when opening a new window.

Contribute

See contributing.md in remarkjs/.github for ways to get started. See support.md for ways to get help.

This project has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.

License

MIT © Cédric Delpoux

Install

npm i remark-external-links

DownloadsWeekly Downloads

134,025

Version

5.0.0

License

MIT

Unpacked Size

9.07 kB

Total Files

4

Last publish

Collaborators

  • avatar
  • avatar