Skip to content

Commit

Permalink
Prevent removing IDs in SVGs only with defs
Browse files Browse the repository at this point in the history
  • Loading branch information
GreLI committed Oct 22, 2017
1 parent 3b6fa1e commit f8234fd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
21 changes: 18 additions & 3 deletions plugins/cleanupIDs.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,24 @@ exports.fn = function(data, params) {
var item = items.content[i];

// quit if <style> of <script> presents ('force' param prevents quitting)
if (!params.force && item.isElem(styleOrScript)) {
hasStyleOrScript = true;
continue;
if (!params.force) {
if (item.isElem(styleOrScript)) {
hasStyleOrScript = true;
continue;
}
// Don't remove IDs if the whole SVG consists only of defs.
if (item.isElem('defs') && item.parentNode.isElem('svg')) {
var hasDefsOnly = true;
for (var j = i + 1; j < items.content.length; j++) {
if (items.content[j].isElem()) {
hasDefsOnly = false;
break;
}
}
if (hasDefsOnly) {
break;
}
}
}
// …and don't remove any ID if yes
if (item.isElem()) {
Expand Down
17 changes: 17 additions & 0 deletions test/plugins/cleanupIDs.11.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f8234fd

Please sign in to comment.