diff options
Diffstat (limited to 'node_modules/svgo/plugins/removeDesc.js')
| -rw-r--r-- | node_modules/svgo/plugins/removeDesc.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/node_modules/svgo/plugins/removeDesc.js b/node_modules/svgo/plugins/removeDesc.js new file mode 100644 index 00000000..5d9e57ae --- /dev/null +++ b/node_modules/svgo/plugins/removeDesc.js @@ -0,0 +1,39 @@ +'use strict'; + +const { detachNodeFromParent } = require('../lib/xast.js'); + +exports.name = 'removeDesc'; +exports.description = 'removes <desc>'; + +const standardDescs = /^(Created with|Created using)/; + +/** + * Removes <desc>. + * Removes only standard editors content or empty elements 'cause it can be used for accessibility. + * Enable parameter 'removeAny' to remove any description. + * + * https://developer.mozilla.org/en-US/docs/Web/SVG/Element/desc + * + * @author Daniel Wabyick + * + * @type {import('./plugins-types').Plugin<'removeDesc'>} + */ +exports.fn = (root, params) => { + const { removeAny = true } = params; + return { + element: { + enter: (node, parentNode) => { + if (node.name === 'desc') { + if ( + removeAny || + node.children.length === 0 || + (node.children[0].type === 'text' && + standardDescs.test(node.children[0].value)) + ) { + detachNodeFromParent(node, parentNode); + } + } + }, + }, + }; +}; |
