1.0.0 • Published 6 years ago

posthtml-external-link-target-blank v1.0.0

Weekly downloads
1
License
MIT
Repository
-
Last release
6 years ago

posthtml-external-link-target-blank

npm version build status

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;