js-striphtml

1.1.2 • Public • Published

js-striphtml

JavaScript module for stripping HTML tags and/or HTML element attributes from strings.

Install

$ npm install js-striphtml

.stripTags(string subject, [ array of strings allowableTags ] );

This function tries to return a string with all HTML tags stripped from a given str.

You can use the optional second parameter to specify tags which should not be stripped.

Example:

var striphtml = require('js-striphtml');
striphtml.striptags('<body>I am a <b>HTML</b> string.<div class="clear"></div></body>', [ 'b' ]);
// Returns "I am a <b>HTML</b> string."

.stripAttr(string subject, [ object of arrays of strings allowableAttributes ] );

This function tries to return a string with all HTML tag attributes stripped, but with the very HTML tags intact.

You can use the optional second parameter to specify attributes which should not be stripped.

Example:

var striphtml = require('js-striphtml');
striphtml.stripAttr('<p style="background:green">I am a <b>HTML</b> string. <img src="stringimg.jpg" align="right" /></p>', { 'img': [ 'src' ] } );
// Returns "<p>I am a <b>HTML</b> string. <img src="stringimg.jpg" /></p>"

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.2
    241
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.1.2
    241
  • 1.1.1
    0
  • 1.1.0
    1
  • 1.0.0
    0

Package Sidebar

Install

npm i js-striphtml

Weekly Downloads

242

Version

1.1.2

License

GPLv3

Last publish

Collaborators

  • alfredgodoy