|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -exports.type = 'full'; |
| 3 | +const { closestByName } = require('../lib/xast.js'); |
| 4 | + |
| 5 | +exports.type = 'perItem'; |
4 | 6 |
|
5 | 7 | exports.active = false; |
6 | 8 |
|
@@ -50,30 +52,32 @@ plugins: [ |
50 | 52 | * |
51 | 53 | * @author April Arcus |
52 | 54 | */ |
53 | | -exports.fn = function (data, params) { |
54 | | - if (!params || !(Array.isArray(params.attributes) || params.attribute)) { |
55 | | - console.error(ENOCLS); |
56 | | - return data; |
57 | | - } |
| 55 | +exports.fn = (node, params) => { |
| 56 | + if ( |
| 57 | + node.type === 'element' && |
| 58 | + node.name === 'svg' && |
| 59 | + closestByName(node.parentNode, 'svg') == null |
| 60 | + ) { |
| 61 | + if (!params || !(Array.isArray(params.attributes) || params.attribute)) { |
| 62 | + console.error(ENOCLS); |
| 63 | + return; |
| 64 | + } |
58 | 65 |
|
59 | | - var attributes = params.attributes || [params.attribute], |
60 | | - svg = data.children[0]; |
| 66 | + const attributes = params.attributes || [params.attribute]; |
61 | 67 |
|
62 | | - if (svg.isElem('svg')) { |
63 | | - attributes.forEach(function (attribute) { |
| 68 | + for (const attribute of attributes) { |
64 | 69 | if (typeof attribute === 'string') { |
65 | | - if (svg.attributes[attribute] == null) { |
66 | | - svg.attributes[attribute] = undefined; |
| 70 | + if (node.attributes[attribute] == null) { |
| 71 | + node.attributes[attribute] = undefined; |
67 | 72 | } |
68 | | - } else if (typeof attribute === 'object') { |
69 | | - Object.keys(attribute).forEach(function (key) { |
70 | | - if (svg.attributes[key] == null) { |
71 | | - svg.attributes[key] = attribute[key]; |
| 73 | + } |
| 74 | + if (typeof attribute === 'object') { |
| 75 | + for (const key of Object.keys(attribute)) { |
| 76 | + if (node.attributes[key] == null) { |
| 77 | + node.attributes[key] = attribute[key]; |
72 | 78 | } |
73 | | - }); |
| 79 | + } |
74 | 80 | } |
75 | | - }); |
| 81 | + } |
76 | 82 | } |
77 | | - |
78 | | - return data; |
79 | 83 | }; |
0 commit comments