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

Remove prefix/local support in elements and attributes (#1413)

These parts of element and attribute name are easy to extract.
Now we can easily replace attrs with xast attributes object.
This commit is contained in:
Bogdan Chadkin
2021-03-10 13:26:15 +03:00
committed by GitHub
parent 2458b70f31
commit d1d6e5efe8
21 changed files with 76 additions and 126 deletions

View File

@ -1,5 +1,7 @@
'use strict';
const { parseName } = require('../lib/svgo/tools.js');
exports.type = 'full';
exports.active = true;
@ -48,9 +50,10 @@ exports.fn = function (data) {
if (item.isElem('svg')) {
item.eachAttr(function (attr) {
const { prefix, local } = parseName(attr.name);
// collect namespaces
if (attr.prefix === 'xmlns' && attr.local) {
xmlnsCollection.push(attr.local);
if (prefix === 'xmlns' && local) {
xmlnsCollection.push(local);
}
});
@ -62,14 +65,16 @@ exports.fn = function (data) {
}
if (xmlnsCollection.length) {
const { prefix } = parseName(item.elem);
// check item for the ns-attrs
if (item.prefix) {
removeNSfromCollection(item.prefix);
if (prefix) {
removeNSfromCollection(prefix);
}
// check each attr for the ns-attrs
item.eachAttr(function (attr) {
removeNSfromCollection(attr.prefix);
const { prefix } = parseName(attr.name);
removeNSfromCollection(prefix);
});
}