forked from svg/svgo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plugin to remove elements in <defs> without id. Resolves svg#310
- Loading branch information
Showing
5 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"use strict"; | ||
|
||
exports.type = 'perItem'; | ||
|
||
exports.active = true; | ||
|
||
/** | ||
* Removes content of defs without ids and thus useless. | ||
* | ||
* @param {Object} item current iteration item | ||
* @return {Boolean} if false, item will be filtered out | ||
* | ||
* @author Lev Solntsev | ||
*/ | ||
exports.fn = function(item) { | ||
|
||
if (item.isElem('defs')) { | ||
|
||
if (!item.isEmpty()) | ||
item.content = item.content.reduce(getUsefulItems, []); | ||
|
||
if (item.isEmpty()) return false; | ||
|
||
} | ||
|
||
}; | ||
|
||
function getUsefulItems(usefulItems, item) { | ||
|
||
if (item.hasAttr('id')) { | ||
|
||
usefulItems.push(item); | ||
|
||
} else if (!item.isEmpty()) { | ||
|
||
item.content.reduce(getUsefulItems, usefulItems); | ||
|
||
} | ||
|
||
return usefulItems; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.