Skip to content

posthtml/posthtml-noopener

Repository files navigation

posthtml-noopener

NPM

posthtml-noopener is a PostHTML plugin to add rel="noopener noreferrer" to links that open in a new tab.

Anchor links with the target="_blank" attribute are recommended to include a rel="noopener" or rel="noreferrer" attribute to protect against cross-origin sites from exploiting window.opener. By default, this plugin includes both attribute values.

Before:

<a href="http://example.com/" target="_blank">Link</a>

After:

<a href="http://example.com/" target="_blank" rel="noopener noreferrer">Link</a>

Installation

# Yarn
yarn add -D posthtml-noopener

# NPM
npm i -D posthtml-noopener

# pnpm
pnpm i -D posthtml-noopener

Usage

const fs = require("fs");
const posthtml = require("posthtml");
const { noopener } = require("posthtml-noopener");

const html = fs.readFileSync("./index.html");

posthtml()
  .use(noopener())
  .process(html)
  .then((result) => fs.writeFileSync("./after.html", result.html));

Contributing

See the PostHTML Guidelines.

License

MIT

About

PostHTML plugin to add 'rel="noopener noreferrer"' to links that open in a new tab

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •