mirror of
https://github.com/svg/svgo.git
synced 2025-07-31 07:44:22 +03:00
Allow element seperator to be changed in config
This resolves #557 as you can pass in a different character for element seperation (e.g. `^`
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var ELEM_SEP = ':';
|
var DEFAULT_SEPARATOR = ':';
|
||||||
|
|
||||||
exports.type = 'perItem';
|
exports.type = 'perItem';
|
||||||
|
|
||||||
@ -9,12 +9,16 @@ exports.active = false;
|
|||||||
exports.description = 'removes specified attributes';
|
exports.description = 'removes specified attributes';
|
||||||
|
|
||||||
exports.params = {
|
exports.params = {
|
||||||
|
elemSeparator: DEFAULT_SEPARATOR,
|
||||||
attrs: []
|
attrs: []
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove attributes
|
* Remove attributes
|
||||||
*
|
*
|
||||||
|
* @param elemSeparator
|
||||||
|
* format: string
|
||||||
|
*
|
||||||
* @param attrs:
|
* @param attrs:
|
||||||
*
|
*
|
||||||
* format: [ element* : attribute* ]
|
* format: [ element* : attribute* ]
|
||||||
@ -72,17 +76,18 @@ exports.fn = function(item, params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (item.isElem()) {
|
if (item.isElem()) {
|
||||||
|
var elemSeparator = typeof params.elemSeparator == 'string' ? params.elemSeparator : DEFAULT_SEPARATOR;
|
||||||
|
|
||||||
// prepare patterns
|
// prepare patterns
|
||||||
var patterns = params.attrs.map(function(pattern) {
|
var patterns = params.attrs.map(function(pattern) {
|
||||||
|
|
||||||
// apply to all elements if specifc element is omitted
|
// apply to all elements if specifc element is omitted
|
||||||
if (pattern.indexOf(ELEM_SEP) === -1) {
|
if (pattern.indexOf(elemSeparator) === -1) {
|
||||||
pattern = ['.*', ELEM_SEP, pattern].join('');
|
pattern = ['.*', elemSeparator, pattern].join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
// create regexps for element and attribute name
|
// create regexps for element and attribute name
|
||||||
return pattern.split(ELEM_SEP)
|
return pattern.split(elemSeparator)
|
||||||
.map(function(value) {
|
.map(function(value) {
|
||||||
|
|
||||||
// adjust single * to match anything
|
// adjust single * to match anything
|
||||||
|
Reference in New Issue
Block a user