diff --git a/plugins/removeEditorsNSData.js b/plugins/removeEditorsNSData.js index 9e5c8cd8f..f67b66664 100644 --- a/plugins/removeEditorsNSData.js +++ b/plugins/removeEditorsNSData.js @@ -7,10 +7,12 @@ exports.active = true; exports.description = 'removes editors namespaces, elements and attributes'; var editorNamespaces = require('./_collections').editorNamespaces, - prefixes = []; + prefixes = [], + preserve = []; exports.params = { - additionalNamespaces: [] + additionalNamespaces: [], + preserve: [], // preserves elements and attributes }; /** @@ -32,6 +34,9 @@ exports.fn = function(item, params) { if (Array.isArray(params.additionalNamespaces)) { editorNamespaces = editorNamespaces.concat(params.additionalNamespaces); } + if (Array.isArray(params.preserve)) { + preserve = preserve.concat(params.preserve); + } if (item.elem) { @@ -42,7 +47,9 @@ exports.fn = function(item, params) { prefixes.push(attr.local); // - item.removeAttr(attr.name); + if (preserve.indexOf(attr.name) === -1) { + item.removeAttr(attr.name); + } } }); @@ -50,13 +57,13 @@ exports.fn = function(item, params) { // <* sodipodi:*=""> item.eachAttr(function(attr) { - if (prefixes.indexOf(attr.prefix) > -1) { + if (prefixes.indexOf(attr.prefix) > -1 && preserve.indexOf(attr.name) === -1) { item.removeAttr(attr.name); } }); // - if (prefixes.indexOf(item.prefix) > -1) { + if (prefixes.indexOf(item.prefix) > -1 && preserve.indexOf(item.elem) === -1) { return false; } diff --git a/test/plugins/removeEditorsNSData.03.svg b/test/plugins/removeEditorsNSData.03.svg new file mode 100644 index 000000000..ebad59c0c --- /dev/null +++ b/test/plugins/removeEditorsNSData.03.svg @@ -0,0 +1,27 @@ + + + + ... + + + + ... + + + + + +@@@ + + + + + ... + + + + + +@@@ + +{"preserve":["xmlns:sodipodi","sodipodi:fakeattr","sodipodi:namedview"]}