removeRasterImages.js 775 B

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. const { detachNodeFromParent } = require('../lib/xast.js');
  3. exports.name = 'removeRasterImages';
  4. exports.type = 'visitor';
  5. exports.active = false;
  6. exports.description = 'removes raster images (disabled by default)';
  7. /**
  8. * Remove raster images references in <image>.
  9. *
  10. * @see https://bugs.webkit.org/show_bug.cgi?id=63548
  11. *
  12. * @author Kir Belevich
  13. *
  14. * @type {import('../lib/types').Plugin<void>}
  15. */
  16. exports.fn = () => {
  17. return {
  18. element: {
  19. enter: (node, parentNode) => {
  20. if (
  21. node.name === 'image' &&
  22. node.attributes['xlink:href'] != null &&
  23. /(\.|image\/)(jpg|png|gif)/.test(node.attributes['xlink:href'])
  24. ) {
  25. detachNodeFromParent(node, parentNode);
  26. }
  27. },
  28. },
  29. };
  30. };