posthtml-noopener
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

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

Package Sidebar

Install

npm i posthtml-noopener

Weekly Downloads

811

Version

1.0.5

License

MIT

Unpacked Size

7.51 kB

Total Files

12

Last publish

Collaborators

  • metonym