removeComments.js 634 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. const { detachNodeFromParent } = require('../lib/xast.js');
  3. exports.name = 'removeComments';
  4. exports.type = 'visitor';
  5. exports.active = true;
  6. exports.description = 'removes comments';
  7. /**
  8. * Remove comments.
  9. *
  10. * @example
  11. * <!-- Generator: Adobe Illustrator 15.0.0, SVG Export
  12. * Plug-In . SVG Version: 6.00 Build 0) -->
  13. *
  14. * @author Kir Belevich
  15. *
  16. * @type {import('../lib/types').Plugin<void>}
  17. */
  18. exports.fn = () => {
  19. return {
  20. comment: {
  21. enter: (node, parentNode) => {
  22. if (node.value.charAt(0) !== '!') {
  23. detachNodeFromParent(node, parentNode);
  24. }
  25. },
  26. },
  27. };
  28. };