1.0.5 • Published 6 years ago
posthtml-noopener v1.0.5
posthtml-noopener
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-noopenerUsage
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.