Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions plugins/removeEditorsNSData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

/**
Expand All @@ -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) {

Expand All @@ -42,21 +47,23 @@ exports.fn = function(item, params) {
prefixes.push(attr.local);

// <svg xmlns:sodipodi="">
item.removeAttr(attr.name);
if (preserve.indexOf(attr.name) === -1) {
item.removeAttr(attr.name);
}
}
});

}

// <* 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);
}
});

// <sodipodi:*>
if (prefixes.indexOf(item.prefix) > -1) {
if (prefixes.indexOf(item.prefix) > -1 && preserve.indexOf(item.elem) === -1) {
return false;
}

Expand Down
27 changes: 27 additions & 0 deletions test/plugins/removeEditorsNSData.03.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.