File tree Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change 1
- var attrRE = / ( [ \w - ] + ) | ( [ ' " ] ) ( [ . \s \S ] * ?) \2/ g;
1
+ var attrRE = / ( [ \w - ] + ) | = | ( [ ' " ] ) ( [ . \s \S ] * ?) \2/ g;
2
2
var voidElements = require ( 'void-elements' ) ;
3
3
4
4
module . exports = function ( tag ) {
5
5
var i = 0 ;
6
6
var key ;
7
+ var expectingValueAfterEquals = true ;
7
8
var res = {
8
9
type : 'tag' ,
9
10
name : '' ,
@@ -13,8 +14,17 @@ module.exports = function (tag) {
13
14
} ;
14
15
15
16
tag . replace ( attrRE , function ( match ) {
16
- if ( i % 2 ) {
17
- key = match ;
17
+ if ( match === '=' ) {
18
+ expectingValueAfterEquals = true ;
19
+ i ++ ;
20
+ return ;
21
+ }
22
+
23
+ if ( ! expectingValueAfterEquals ) {
24
+ if ( key ) {
25
+ res . attrs [ key ] = key ; // boolean attribute
26
+ }
27
+ key = match ;
18
28
} else {
19
29
if ( i === 0 ) {
20
30
if ( voidElements [ match ] || tag . charAt ( tag . length - 2 ) === '/' ) {
@@ -23,9 +33,11 @@ module.exports = function (tag) {
23
33
res . name = match ;
24
34
} else {
25
35
res . attrs [ key ] = match . replace ( / ^ [ ' " ] | [ ' " ] $ / g, '' ) ;
36
+ key = undefined ;
26
37
}
27
38
}
28
39
i ++ ;
40
+ expectingValueAfterEquals = false ;
29
41
} ) ;
30
42
31
43
return res ;
Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ test('parseTag', function (t) {
66
66
voidElement : false ,
67
67
children : [ ]
68
68
} ) ;
69
-
69
+
70
70
tag = '<textarea placeholder=\'Hey Usher, \n\nAre these modals for real?!\' class=\'placeholder-value\'>' ;
71
71
72
72
t . deepEqual ( parseTag ( tag ) , {
@@ -80,5 +80,19 @@ test('parseTag', function (t) {
80
80
children : [ ]
81
81
} ) ;
82
82
83
+ tag = '<input checked name="sad" type="checkbox">' ;
84
+
85
+ t . deepEqual ( parseTag ( tag ) , {
86
+ type : 'tag' ,
87
+ attrs : {
88
+ type : 'checkbox' ,
89
+ checked : 'checked' ,
90
+ name : 'sad'
91
+ } ,
92
+ name : 'input' ,
93
+ voidElement : true ,
94
+ children : [ ]
95
+ } ) ;
96
+
83
97
t . end ( ) ;
84
98
} ) ;
You can’t perform that action at this time.
0 commit comments