mirror of
https://github.com/svg/svgo.git
synced 2025-07-29 20:21:14 +03:00
[plugin] sortAttrs: add xmlns order option (#984)
This commit is contained in:
@ -30,7 +30,8 @@ exports.fn = function(item, params) {
|
||||
|
||||
var attrs = [],
|
||||
sorted = {},
|
||||
orderlen = params.order.length + 1;
|
||||
orderlen = params.order.length + 1,
|
||||
xmlnsOrder = params.xmlnsOrder || 'front';
|
||||
|
||||
if (item.elem) {
|
||||
|
||||
@ -41,10 +42,12 @@ exports.fn = function(item, params) {
|
||||
attrs.sort(function(a, b) {
|
||||
if (a.prefix != b.prefix) {
|
||||
// xmlns attributes implicitly have the prefix xmlns
|
||||
if (a.prefix == 'xmlns')
|
||||
return -1;
|
||||
if (b.prefix == 'xmlns')
|
||||
return 1;
|
||||
if (xmlnsOrder == 'front') {
|
||||
if (a.prefix == 'xmlns')
|
||||
return -1;
|
||||
if (b.prefix == 'xmlns')
|
||||
return 1;
|
||||
}
|
||||
return a.prefix < b.prefix ? -1 : 1;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user