strip-tags.js 648 B

12345678910111213141516171819202122232425262728293031323334
  1. /*!
  2. * strip-tags <https://github.com/jonschlinkert/strip-tags>
  3. *
  4. * Copyright (c) 2015 Jon Schlinkert, contributors.
  5. * Licensed under the MIT license.
  6. */
  7. 'use strict';
  8. var cheerio = require('cheerio');
  9. exports.strip = function(str, tags) {
  10. var $ = cheerio.load(str, {decodeEntities: false});
  11. if (!tags || tags.length === 0) {
  12. return str;
  13. }
  14. tags = !Array.isArray(tags) ? [tags] : tags;
  15. var len = tags.length;
  16. while (len--) {
  17. $(tags[len]).remove();
  18. }
  19. return $.html();
  20. };
  21. exports.fetch = function(str, tag) {
  22. var $ = cheerio.load(str, {decodeEntities: false});
  23. if (!tag) return str;
  24. return $(tag).html();
  25. };