1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-29 20:21:14 +03:00

Prevent removing IDs in SVGs only with defs

This commit is contained in:
GreLI
2017-10-22 18:38:56 +03:00
parent 3b6fa1ed31
commit f8234fd3f8
2 changed files with 35 additions and 3 deletions

View File

@ -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()) {