mirror of
https://github.com/svg/svgo.git
synced 2025-07-29 20:21:14 +03:00
Refactor basic plugins with visitor api (#1518)
- cleanupAttrs - convertEllipseToCircle - removeDesc - removeDoctype - removeEmptyText - removeMetadata - removeRasterImages - removeScriptElement - removeStyleElement - removeTitle - removeXMLProcInst
This commit is contained in:
@ -1,16 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
exports.type = 'perItem';
|
||||
const { detachNodeFromParent } = require('../lib/xast.js');
|
||||
|
||||
exports.type = 'visitor';
|
||||
exports.active = true;
|
||||
|
||||
exports.params = {
|
||||
removeAny: true,
|
||||
};
|
||||
|
||||
exports.description = 'removes <desc>';
|
||||
|
||||
var standardDescs = /^(Created with|Created using)/;
|
||||
const standardDescs = /^(Created with|Created using)/;
|
||||
|
||||
/**
|
||||
* Removes <desc>.
|
||||
@ -19,19 +15,24 @@ var standardDescs = /^(Created with|Created using)/;
|
||||
*
|
||||
* https://developer.mozilla.org/en-US/docs/Web/SVG/Element/desc
|
||||
*
|
||||
* @param {Object} item current iteration item
|
||||
* @return {Boolean} if false, item will be filtered out
|
||||
*
|
||||
* @author Daniel Wabyick
|
||||
*/
|
||||
exports.fn = function (item, params) {
|
||||
return (
|
||||
!item.isElem('desc') ||
|
||||
!(
|
||||
params.removeAny ||
|
||||
item.children.length === 0 ||
|
||||
(item.children[0].type === 'text' &&
|
||||
standardDescs.test(item.children[0].value))
|
||||
)
|
||||
);
|
||||
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);
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user