Adds HTML so external links will open in a new window
npm install posthtml posthtml-external-link-target-blank
const posthtml = require('posthtml');
const externalLinks = require('posthtml-external-link-target-blank');
const inputHTML = ;
const outputHTML = posthtml()
.use(externalLinks())
.process('<a href="http://www.example.com/">lorem ipsum dolar sit a met</div>', { sync: true })
.html;
// <a href="http://www.example.com/" target="_blank" rel="noopener">lorem ipsum dolar sit a met</div>
An array of hosts which should be excluded from opening new windows.
- Since:
1.0.0
- Property is
Optional
- Default value is:
[]
Example:
const posthtml = require('posthtml');
const externalLinks = require('posthtml-external-link-target-blank');
const inputHTML = '<a href="http://www.example.com/">lorem ipsum dolar sit a met</div>';
const outputHTML = posthtml()
.use(externalLinks({ excludeHosts: [ 'example.com', 'www.example.com' ] }))
.process(inputHTML, { sync: true })
.html;