@@ -21,10 +21,11 @@ exports.params = {
21
21
*
22
22
* @param attrs:
23
23
*
24
- * format: [ element* : attribute* ]
24
+ * format: [ element* : attribute* : value* ]
25
25
*
26
- * element : regexp (wrapped into ^...$), single * or omitted > all elements
26
+ * element : regexp (wrapped into ^...$), single * or omitted > all elements (must be present when value is used)
27
27
* attribute : regexp (wrapped into ^...$)
28
+ * value : regexp (wrapped into ^...$), single * or omitted > all values
28
29
*
29
30
* examples:
30
31
*
@@ -37,6 +38,10 @@ exports.params = {
37
38
* ---
38
39
* attrs: 'path:fill'
39
40
*
41
+ * > remove fill attribute on path element where value is none
42
+ * ---
43
+ * attrs: 'path:fill:none'
44
+ *
40
45
*
41
46
* > remove all fill and stroke attribute
42
47
* ---
@@ -56,6 +61,10 @@ exports.params = {
56
61
*
57
62
* attrs: '.*:(fill|stroke)'
58
63
*
64
+ * [is same as]
65
+ *
66
+ * attrs: '.*:(fill|stroke):.*'
67
+ *
59
68
*
60
69
* > remove all stroke related attributes
61
70
* ----
@@ -81,12 +90,16 @@ exports.fn = function(item, params) {
81
90
// prepare patterns
82
91
var patterns = params . attrs . map ( function ( pattern ) {
83
92
84
- // apply to all elements if specifc element is omitted
93
+ // if no element separators (:), assume it's attribute name, and apply to all elements *regardless of value*
85
94
if ( pattern . indexOf ( elemSeparator ) === - 1 ) {
86
- pattern = [ '.*' , elemSeparator , pattern ] . join ( '' ) ;
95
+ pattern = [ '.*' , elemSeparator , pattern , elemSeparator , '.*' ] . join ( '' ) ;
96
+
97
+ // if only 1 separator, assume it's element and attribute name, and apply regardless of attribute value
98
+ } else if ( pattern . split ( elemSeparator ) . length < 3 ) {
99
+ pattern = [ pattern , elemSeparator , '.*' ] . join ( '' ) ;
87
100
}
88
101
89
- // create regexps for element and attribute name
102
+ // create regexps for element, attribute name, and attribute value
90
103
return pattern . split ( elemSeparator )
91
104
. map ( function ( value ) {
92
105
@@ -110,7 +123,11 @@ exports.fn = function(item, params) {
110
123
111
124
// matches attribute name
112
125
if ( pattern [ 1 ] . test ( name ) ) {
113
- item . removeAttr ( name ) ;
126
+
127
+ // matches attribute value
128
+ if ( pattern [ 2 ] . test ( attr . value ) ) {
129
+ item . removeAttr ( name ) ;
130
+ }
114
131
}
115
132
116
133
} ) ;
0 commit comments