PostHTML plugin to add 'rel="noopener noreferrer"' to links that open in a new tab
npm install posthtml-noopener[![NPM][npm]][npm-url]
[![Deps][deps]][deps-url]
[![Build][build]][build-badge]
[![Coverage][codecov-shield]][codecov]
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:
``html`
Link
After:
`html`
Link
`bash`
yarn add -D posthtml-noopenerOR
npm i posthtml-noopener
`js
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));
``
See the PostHTML Guidelines.
[npm]: https://img.shields.io/npm/v/posthtml-noopener.svg?color=blue
[npm-url]: https://npmjs.com/package/posthtml-noopener
[deps]: https://david-dm.org/metonym/posthtml-noopener.svg
[deps-url]: https://david-dm.org/metonym/posthtml-noopener
[build]: https://travis-ci.com/metonym/posthtml-noopener.svg?branch=master
[build-badge]: https://travis-ci.com/metonym/posthtml-noopener
[codecov]: https://codecov.io/gh/metonym/posthtml-noopener
[codecov-shield]: https://img.shields.io/codecov/c/github/metonym/posthtml-noopener.svg