strip-tags
Version:
Strip specific tags from a string of HTML
29 lines (20 loc) • 482 B
JavaScript
/*!
* strip-tags <https://github.com/jonschlinkert/strip-tags>
*
* Copyright (c) 2015 Jon Schlinkert, contributors.
* Licensed under the MIT license.
*/
;
var cheerio = require('cheerio');
module.exports = function (str, tags) {
var $ = cheerio.load(str);
if (!tags || tags.length === 0) {
return str;
}
tags = !Array.isArray(tags) ? [tags] : tags;
var len = tags.length;
while (len--) {
$(tags[len]).remove();
}
return $.html();
};