posthtml-shorten

1.0.0 • Public • Published

posthtml-shorten

Build Status Coverage Status

A PostHTML plugin to shorten URLs in HTML elements.

Usage

var posthtml = require('posthtml');
var shorten = require('posthtml-shorten');
 
var shortener = {
  shorten: function(url, callback) {
    callback(null, url.replace('goog', 'gog'));
  }
};
 
var options = {
  shortener: shortener, // Must contain a `shorten` function
  tag: ['a', 'img', 'body'] // Allowed tags for URL shortening
  attribute: ['href', 'src'], // Attributes to replace on the elements
};
 
posthtml()
  .use(shorten(options))
  .process('<a href="google.com">Google</a>')
  .then(function(result) {
    console.log(result.html); //=> '<a href="gogle.com">Google</a>'
  });

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    130
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    130
  • 0.2.0
    1
  • 0.1.0
    2

Package Sidebar

Install

npm i posthtml-shorten

Weekly Downloads

39

Version

1.0.0

License

ISC

Last publish

Collaborators

  • devinus