Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

posthtml-noopener

metonym3.8kMIT1.0.5TypeScript support: included

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

html, posthtml, posthtml-plugin, noopener, noreferrer

readme

posthtml-noopener

NPM Deps Build Coverage

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.

Read more about the rel="noopener" attribute.

Before:

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

After:

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

Install

yarn add -D posthtml-noopener
# OR
npm i 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.

Changelog

License

MIT

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased

  • Add option to only add "noopener" attribute

1.0.5 - 2019-10-13

  • Upgrade posthtml version from 0.11.16 to 0.12

  • Upgrade development dependencies (pretty-quick, husky, typescript)

1.0.4 - 2019-09-20

  • Upgrade posthtml version from 0.11.15 to 0.11.16

  • Refactor typings

1.0.3 - 2019-08-27

  • Upgrade PostHTML to 0.11.5 for TS typings

1.0.2 - 2019-08-17

  • Update documentation

1.0.1 - 2019-06-28

  • Add alias default export as noopener and posthtmlNoopener to allow more intuitive importing (fb990fc)

1.0.0 - 2019-06-27

  • Initial release