Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rehype-external-links

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype-external-links

rehype plugin to automatically add `target` and `rel` attributes to external links

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6M
decreased by-9.26%
Maintainers
2
Weekly downloads
 
Created

What is rehype-external-links?

The rehype-external-links package is a plugin for the rehype ecosystem that allows you to easily add attributes to external links in your HTML. This can be useful for adding security features like `rel='noopener noreferrer'` or styling external links differently.

What are rehype-external-links's main functionalities?

Add target='_blank' to external links

This feature allows you to automatically add `target='_blank'` to all external links, making them open in a new tab.

const rehype = require('rehype');
const rehypeExternalLinks = require('rehype-external-links');

rehype()
  .use(rehypeExternalLinks, { target: '_blank' })
  .process('<a href="https://example.com">Example</a>', function (err, file) {
    if (err) throw err;
    console.log(String(file));
  });

Add rel='noopener noreferrer' to external links

This feature allows you to add `rel='noopener noreferrer'` to all external links, which is a security best practice to prevent the new page from being able to access the window.opener property.

const rehype = require('rehype');
const rehypeExternalLinks = require('rehype-external-links');

rehype()
  .use(rehypeExternalLinks, { rel: ['noopener', 'noreferrer'] })
  .process('<a href="https://example.com">Example</a>', function (err, file) {
    if (err) throw err;
    console.log(String(file));
  });

Customize attributes for external links

This feature allows you to customize multiple attributes for external links, including adding custom content like ' (external)' to the link text.

const rehype = require('rehype');
const rehypeExternalLinks = require('rehype-external-links');

rehype()
  .use(rehypeExternalLinks, { target: '_blank', rel: ['noopener', 'noreferrer'], content: ' (external)' })
  .process('<a href="https://example.com">Example</a>', function (err, file) {
    if (err) throw err;
    console.log(String(file));
  });

Other packages similar to rehype-external-links

Keywords

FAQs

Package last updated on 03 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc