js-striphtml
v1.1.2
Published
Strip HTML tags and/or attributes from a string.
Downloads
716
Readme
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>"