1.1.2 • Published 10 years ago

js-striphtml v1.1.2

Weekly downloads
2,936
License
GPLv3
Repository
github
Last release
10 years ago

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>"
1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago