@@ -15,8 +15,7 @@ import { isNonPhrasingTag, canBeLeftOpenTag } from 'web/util/index'
15
15
16
16
// Regular Expressions for parsing tags and attributes
17
17
const singleAttrIdentifier = / ( [ ^ \s " ' < > \/ = ] + ) /
18
- const singleAttrAssign = / = /
19
- const singleAttrAssigns = [ singleAttrAssign ]
18
+ const singleAttrAssign = / (?: = ) /
20
19
const singleAttrValues = [
21
20
// attr value double quotes
22
21
/ " ( [ ^ " ] * ) " + / . source ,
@@ -25,6 +24,12 @@ const singleAttrValues = [
25
24
// attr value, no quotes
26
25
/ ( [ ^ \s " ' = < > ` ] + ) / . source
27
26
]
27
+ const attribute = new RegExp (
28
+ '^\\s*' + singleAttrIdentifier . source +
29
+ '(?:\\s*(' + singleAttrAssign . source + ')' +
30
+ '\\s*(?:' + singleAttrValues . join ( '|' ) + '))?'
31
+ )
32
+
28
33
// could use https://www.w3.org/TR/1999/REC-xml-names-19990114/#NT-QName
29
34
// but for Vue templates we can enforce a simple charset
30
35
const ncname = '[a-zA-Z_][\\w\\-\\.]*'
@@ -44,24 +49,11 @@ const isSpecialTag = makeMap('script,style', true)
44
49
45
50
const reCache = { }
46
51
47
- function attrForHandler ( handler ) {
48
- const pattern = singleAttrIdentifier . source +
49
- '(?:\\s*(' + joinSingleAttrAssigns ( handler ) + ')' +
50
- '\\s*(?:' + singleAttrValues . join ( '|' ) + '))?'
51
- return new RegExp ( '^\\s*' + pattern )
52
- }
53
-
54
- function joinSingleAttrAssigns ( handler ) {
55
- return singleAttrAssigns . map ( function ( assign ) {
56
- return '(?:' + assign . source + ')'
57
- } ) . join ( '|' )
58
- }
59
-
60
- export function parseHTML ( html , handler ) {
52
+ export function parseHTML ( html , options ) {
61
53
const stack = [ ]
62
- const attribute = attrForHandler ( handler )
63
- const expectHTML = handler . expectHTML
64
- const isUnaryTag = handler . isUnaryTag || no
54
+ const expectHTML = options . expectHTML
55
+ const isUnaryTag = options . isUnaryTag || no
56
+ const shouldDecodeAttr = options . shouldDecodeAttr
65
57
let index = 0
66
58
let last , lastTag
67
59
while ( html ) {
@@ -93,9 +85,6 @@ export function parseHTML (html, handler) {
93
85
// Doctype:
94
86
const doctypeMatch = html . match ( doctype )
95
87
if ( doctypeMatch ) {
96
- if ( handler . doctype ) {
97
- handler . doctype ( doctypeMatch [ 0 ] )
98
- }
99
88
advance ( doctypeMatch [ 0 ] . length )
100
89
continue
101
90
}
@@ -126,8 +115,8 @@ export function parseHTML (html, handler) {
126
115
html = ''
127
116
}
128
117
129
- if ( handler . chars ) {
130
- handler . chars ( text )
118
+ if ( options . chars ) {
119
+ options . chars ( text )
131
120
}
132
121
} else {
133
122
const stackedTag = lastTag . toLowerCase ( )
@@ -140,8 +129,8 @@ export function parseHTML (html, handler) {
140
129
. replace ( / < ! - - ( [ \s \S ] * ?) - - > / g, '$1' )
141
130
. replace ( / < ! \[ C D A T A \[ ( [ \s \S ] * ?) \] \] > / g, '$1' )
142
131
}
143
- if ( handler . chars ) {
144
- handler . chars ( text )
132
+ if ( options . chars ) {
133
+ options . chars ( text )
145
134
}
146
135
return ''
147
136
} )
@@ -211,9 +200,10 @@ export function parseHTML (html, handler) {
211
200
if ( args [ 4 ] === '' ) { delete args [ 4 ] }
212
201
if ( args [ 5 ] === '' ) { delete args [ 5 ] }
213
202
}
203
+ const value = args [ 3 ] || args [ 4 ] || args [ 5 ] || ''
214
204
attrs [ i ] = {
215
205
name : args [ 1 ] ,
216
- value : decodeHTML ( args [ 3 ] || args [ 4 ] || args [ 5 ] || '' )
206
+ value : shouldDecodeAttr ? decodeHTML ( value , true ) : value
217
207
}
218
208
}
219
209
@@ -223,8 +213,8 @@ export function parseHTML (html, handler) {
223
213
unarySlash = ''
224
214
}
225
215
226
- if ( handler . start ) {
227
- handler . start ( tagName , attrs , unary , match . start , match . end )
216
+ if ( options . start ) {
217
+ options . start ( tagName , attrs , unary , match . start , match . end )
228
218
}
229
219
}
230
220
@@ -249,24 +239,24 @@ export function parseHTML (html, handler) {
249
239
if ( pos >= 0 ) {
250
240
// Close all the open elements, up the stack
251
241
for ( let i = stack . length - 1 ; i >= pos ; i -- ) {
252
- if ( handler . end ) {
253
- handler . end ( stack [ i ] . tag , start , end )
242
+ if ( options . end ) {
243
+ options . end ( stack [ i ] . tag , start , end )
254
244
}
255
245
}
256
246
257
247
// Remove the open elements from the stack
258
248
stack . length = pos
259
249
lastTag = pos && stack [ pos - 1 ] . tag
260
250
} else if ( tagName . toLowerCase ( ) === 'br' ) {
261
- if ( handler . start ) {
262
- handler . start ( tagName , [ ] , true , start , end )
251
+ if ( options . start ) {
252
+ options . start ( tagName , [ ] , true , start , end )
263
253
}
264
254
} else if ( tagName . toLowerCase ( ) === 'p' ) {
265
- if ( handler . start ) {
266
- handler . start ( tagName , [ ] , false , start , end )
255
+ if ( options . start ) {
256
+ options . start ( tagName , [ ] , false , start , end )
267
257
}
268
- if ( handler . end ) {
269
- handler . end ( tagName , start , end )
258
+ if ( options . end ) {
259
+ options . end ( tagName , start , end )
270
260
}
271
261
}
272
262
}
0 commit comments