posthtml-external-link-target-blank
v1.0.0
Published
Adds HTML to open external links in new windows
Downloads
3
Readme
posthtml-external-link-target-blank
Adds HTML so external links will open in a new window
Installation
npm install posthtml posthtml-external-link-target-blank
Example
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>
Options
excludeHosts
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;