1 | 'use strict';
|
2 |
|
3 | exports.type = 'perItem';
|
4 |
|
5 | exports.active = true;
|
6 |
|
7 | exports.description = 'removes elements in <defs> without id';
|
8 |
|
9 | var nonRendering = require('./_collections').elemsGroups.nonRendering;
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | exports.fn = function(item) {
|
20 |
|
21 | if (item.isElem('defs')) {
|
22 |
|
23 | if (item.content) {
|
24 | item.content = getUsefulItems(item, []);
|
25 | }
|
26 |
|
27 | if (item.isEmpty()) return false;
|
28 |
|
29 | } else if (item.isElem(nonRendering) && !item.hasAttr('id')) {
|
30 |
|
31 | return false;
|
32 |
|
33 | }
|
34 |
|
35 | };
|
36 |
|
37 | function getUsefulItems(item, usefulItems) {
|
38 |
|
39 | item.content.forEach(function(child) {
|
40 | if (child.hasAttr('id') || child.isElem('style')) {
|
41 |
|
42 | usefulItems.push(child);
|
43 | child.parentNode = item;
|
44 |
|
45 | } else if (!child.isEmpty()) {
|
46 |
|
47 | child.content = getUsefulItems(child, usefulItems);
|
48 |
|
49 | }
|
50 | });
|
51 |
|
52 | return usefulItems;
|
53 | }
|