You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.1 KiB

4 years ago
  1. 'use strict';
  2. exports.type = 'perItem';
  3. exports.active = true;
  4. exports.description = 'removes empty <text> elements';
  5. exports.params = {
  6. text: true,
  7. tspan: true,
  8. tref: true
  9. };
  10. /**
  11. * Remove empty Text elements.
  12. *
  13. * @see http://www.w3.org/TR/SVG/text.html
  14. *
  15. * @example
  16. * Remove empty text element:
  17. * <text/>
  18. *
  19. * Remove empty tspan element:
  20. * <tspan/>
  21. *
  22. * Remove tref with empty xlink:href attribute:
  23. * <tref xlink:href=""/>
  24. *
  25. * @param {Object} item current iteration item
  26. * @param {Object} params plugin params
  27. * @return {Boolean} if false, item will be filtered out
  28. *
  29. * @author Kir Belevich
  30. */
  31. exports.fn = function(item, params) {
  32. // Remove empty text element
  33. if (
  34. params.text &&
  35. item.isElem('text') &&
  36. item.isEmpty()
  37. ) return false;
  38. // Remove empty tspan element
  39. if (
  40. params.tspan &&
  41. item.isElem('tspan') &&
  42. item.isEmpty()
  43. ) return false;
  44. // Remove tref with empty xlink:href attribute
  45. if (
  46. params.tref &&
  47. item.isElem('tref') &&
  48. !item.hasAttrLocal('href')
  49. ) return false;
  50. };