@@ -54,8 +54,6 @@ enum InsertionMode {
54
54
IN_TABLE_BODY ,
55
55
IN_ROW ,
56
56
IN_CELL ,
57
- IN_SELECT ,
58
- IN_SELECT_IN_TABLE ,
59
57
IN_TEMPLATE ,
60
58
AFTER_BODY ,
61
59
IN_FRAMESET ,
@@ -706,10 +704,6 @@ export class Parser<T extends TreeAdapterTypeMap> implements TokenHandler, Stack
706
704
this . insertionMode = InsertionMode . IN_FRAMESET ;
707
705
return ;
708
706
}
709
- case $ . SELECT : {
710
- this . _resetInsertionModeForSelect ( i ) ;
711
- return ;
712
- }
713
707
case $ . TEMPLATE : {
714
708
this . insertionMode = this . tmplInsertionModeStack [ 0 ] ;
715
709
return ;
@@ -739,24 +733,6 @@ export class Parser<T extends TreeAdapterTypeMap> implements TokenHandler, Stack
739
733
this . insertionMode = InsertionMode . IN_BODY ;
740
734
}
741
735
742
- /** @protected */
743
- _resetInsertionModeForSelect ( selectIdx : number ) : void {
744
- if ( selectIdx > 0 ) {
745
- for ( let i = selectIdx - 1 ; i > 0 ; i -- ) {
746
- const tn = this . openElements . tagIDs [ i ] ;
747
-
748
- if ( tn === $ . TEMPLATE ) {
749
- break ;
750
- } else if ( tn === $ . TABLE ) {
751
- this . insertionMode = InsertionMode . IN_SELECT_IN_TABLE ;
752
- return ;
753
- }
754
- }
755
- }
756
-
757
- this . insertionMode = InsertionMode . IN_SELECT ;
758
- }
759
-
760
736
//Foster parenting
761
737
762
738
/** @protected */
@@ -859,9 +835,7 @@ export class Parser<T extends TreeAdapterTypeMap> implements TokenHandler, Stack
859
835
characterInBody ( this , token ) ;
860
836
break ;
861
837
}
862
- case InsertionMode . TEXT :
863
- case InsertionMode . IN_SELECT :
864
- case InsertionMode . IN_SELECT_IN_TABLE : {
838
+ case InsertionMode . TEXT : {
865
839
this . _insertCharacters ( token ) ;
866
840
break ;
867
841
}
@@ -974,8 +948,6 @@ export class Parser<T extends TreeAdapterTypeMap> implements TokenHandler, Stack
974
948
case InsertionMode . IN_TABLE_BODY :
975
949
case InsertionMode . IN_ROW :
976
950
case InsertionMode . IN_CELL :
977
- case InsertionMode . IN_SELECT :
978
- case InsertionMode . IN_SELECT_IN_TABLE :
979
951
case InsertionMode . IN_TEMPLATE :
980
952
case InsertionMode . IN_FRAMESET :
981
953
case InsertionMode . AFTER_FRAMESET : {
@@ -1110,14 +1082,6 @@ export class Parser<T extends TreeAdapterTypeMap> implements TokenHandler, Stack
1110
1082
startTagInCell ( this , token ) ;
1111
1083
break ;
1112
1084
}
1113
- case InsertionMode . IN_SELECT : {
1114
- startTagInSelect ( this , token ) ;
1115
- break ;
1116
- }
1117
- case InsertionMode . IN_SELECT_IN_TABLE : {
1118
- startTagInSelectInTable ( this , token ) ;
1119
- break ;
1120
- }
1121
1085
case InsertionMode . IN_TEMPLATE : {
1122
1086
startTagInTemplate ( this , token ) ;
1123
1087
break ;
@@ -1220,14 +1184,6 @@ export class Parser<T extends TreeAdapterTypeMap> implements TokenHandler, Stack
1220
1184
endTagInCell ( this , token ) ;
1221
1185
break ;
1222
1186
}
1223
- case InsertionMode . IN_SELECT : {
1224
- endTagInSelect ( this , token ) ;
1225
- break ;
1226
- }
1227
- case InsertionMode . IN_SELECT_IN_TABLE : {
1228
- endTagInSelectInTable ( this , token ) ;
1229
- break ;
1230
- }
1231
1187
case InsertionMode . IN_TEMPLATE : {
1232
1188
endTagInTemplate ( this , token ) ;
1233
1189
break ;
@@ -1285,9 +1241,7 @@ export class Parser<T extends TreeAdapterTypeMap> implements TokenHandler, Stack
1285
1241
case InsertionMode . IN_COLUMN_GROUP :
1286
1242
case InsertionMode . IN_TABLE_BODY :
1287
1243
case InsertionMode . IN_ROW :
1288
- case InsertionMode . IN_CELL :
1289
- case InsertionMode . IN_SELECT :
1290
- case InsertionMode . IN_SELECT_IN_TABLE : {
1244
+ case InsertionMode . IN_CELL : {
1291
1245
eofInBody ( this , token ) ;
1292
1246
break ;
1293
1247
}
@@ -1340,8 +1294,6 @@ export class Parser<T extends TreeAdapterTypeMap> implements TokenHandler, Stack
1340
1294
case InsertionMode . AFTER_HEAD :
1341
1295
case InsertionMode . TEXT :
1342
1296
case InsertionMode . IN_COLUMN_GROUP :
1343
- case InsertionMode . IN_SELECT :
1344
- case InsertionMode . IN_SELECT_IN_TABLE :
1345
1297
case InsertionMode . IN_FRAMESET :
1346
1298
case InsertionMode . AFTER_FRAMESET : {
1347
1299
this . _insertCharacters ( token ) ;
@@ -2158,6 +2110,13 @@ function hrStartTagInBody<T extends TreeAdapterTypeMap>(p: Parser<T>, token: Tag
2158
2110
p . _closePElement ( ) ;
2159
2111
}
2160
2112
2113
+ if ( p . openElements . hasInScope ( $ . SELECT ) ) {
2114
+ p . openElements . generateImpliedEndTagsWithExclusion ( $ . OPTGROUP ) ;
2115
+ if ( p . openElements . hasInScope ( $ . OPTION ) ) {
2116
+ p . _err ( token , ERR . characterReferenceOutsideUnicodeRange ) ; // TODO correct error type
2117
+ }
2118
+ }
2119
+
2161
2120
p . _appendElement ( token , NS . HTML ) ;
2162
2121
p . framesetOk = false ;
2163
2122
token . ackSelfClosing = true ;
@@ -2202,26 +2161,45 @@ function rawTextStartTagInBody<T extends TreeAdapterTypeMap>(p: Parser<T>, token
2202
2161
}
2203
2162
2204
2163
function selectStartTagInBody < T extends TreeAdapterTypeMap > ( p : Parser < T > , token : TagToken ) : void {
2164
+ if ( p . openElements . hasInScope ( $ . SELECT ) ) {
2165
+ p . _err ( token , ERR . characterReferenceOutsideUnicodeRange ) ; // TODO correct error type
2166
+ p . openElements . popUntilTagNamePopped ( $ . SELECT ) ;
2167
+ }
2168
+
2205
2169
p . _reconstructActiveFormattingElements ( ) ;
2206
2170
p . _insertElement ( token , NS . HTML ) ;
2207
2171
p . framesetOk = false ;
2172
+ }
2173
+
2174
+ function optionStartTagInBody < T extends TreeAdapterTypeMap > ( p : Parser < T > , token : TagToken ) : void {
2175
+ if ( p . openElements . hasInScope ( $ . SELECT ) ) {
2176
+ p . openElements . generateImpliedEndTagsWithExclusion ( $ . OPTGROUP ) ;
2177
+ if ( p . openElements . hasInScope ( $ . OPTION ) ) {
2178
+ p . _err ( token , ERR . characterReferenceOutsideUnicodeRange ) ; // TODO correct error type
2179
+ }
2180
+ } else {
2181
+ if ( p . openElements . currentTagId === $ . OPTION ) {
2182
+ p . openElements . pop ( ) ;
2183
+ }
2184
+ p . _reconstructActiveFormattingElements ( ) ;
2185
+ }
2208
2186
2209
- p . insertionMode =
2210
- p . insertionMode === InsertionMode . IN_TABLE ||
2211
- p . insertionMode === InsertionMode . IN_CAPTION ||
2212
- p . insertionMode === InsertionMode . IN_TABLE_BODY ||
2213
- p . insertionMode === InsertionMode . IN_ROW ||
2214
- p . insertionMode === InsertionMode . IN_CELL
2215
- ? InsertionMode . IN_SELECT_IN_TABLE
2216
- : InsertionMode . IN_SELECT ;
2187
+ p . _insertElement ( token , NS . HTML ) ;
2217
2188
}
2218
2189
2219
2190
function optgroupStartTagInBody < T extends TreeAdapterTypeMap > ( p : Parser < T > , token : TagToken ) : void {
2220
- if ( p . openElements . currentTagId === $ . OPTION ) {
2221
- p . openElements . pop ( ) ;
2191
+ if ( p . openElements . hasInScope ( $ . SELECT ) ) {
2192
+ p . openElements . generateImpliedEndTags ( ) ;
2193
+ if ( p . openElements . hasInScope ( $ . OPTION ) || p . openElements . hasInScope ( $ . OPTGROUP ) ) {
2194
+ p . _err ( token , ERR . characterReferenceOutsideUnicodeRange ) ; // TODO correct error type
2195
+ }
2196
+ } else {
2197
+ if ( p . openElements . currentTagId == $ . OPTION ) {
2198
+ p . openElements . pop ( ) ;
2199
+ }
2200
+ p . _reconstructActiveFormattingElements ( ) ;
2222
2201
}
2223
2202
2224
- p . _reconstructActiveFormattingElements ( ) ;
2225
2203
p . _insertElement ( token , NS . HTML ) ;
2226
2204
}
2227
2205
@@ -2444,7 +2422,10 @@ function startTagInBody<T extends TreeAdapterTypeMap>(p: Parser<T>, token: TagTo
2444
2422
selectStartTagInBody ( p , token ) ;
2445
2423
break ;
2446
2424
}
2447
- case $ . OPTION :
2425
+ case $ . OPTION : {
2426
+ optionStartTagInBody ( p , token ) ;
2427
+ break ;
2428
+ }
2448
2429
case $ . OPTGROUP : {
2449
2430
optgroupStartTagInBody ( p , token ) ;
2450
2431
break ;
@@ -3269,155 +3250,6 @@ function endTagInCell<T extends TreeAdapterTypeMap>(p: Parser<T>, token: TagToke
3269
3250
}
3270
3251
}
3271
3252
3272
- // The "in select" insertion mode
3273
- //------------------------------------------------------------------
3274
- function startTagInSelect < T extends TreeAdapterTypeMap > ( p : Parser < T > , token : TagToken ) : void {
3275
- switch ( token . tagID ) {
3276
- case $ . HTML : {
3277
- startTagInBody ( p , token ) ;
3278
- break ;
3279
- }
3280
- case $ . OPTION : {
3281
- if ( p . openElements . currentTagId === $ . OPTION ) {
3282
- p . openElements . pop ( ) ;
3283
- }
3284
-
3285
- p . _insertElement ( token , NS . HTML ) ;
3286
- break ;
3287
- }
3288
- case $ . OPTGROUP : {
3289
- if ( p . openElements . currentTagId === $ . OPTION ) {
3290
- p . openElements . pop ( ) ;
3291
- }
3292
-
3293
- if ( p . openElements . currentTagId === $ . OPTGROUP ) {
3294
- p . openElements . pop ( ) ;
3295
- }
3296
-
3297
- p . _insertElement ( token , NS . HTML ) ;
3298
- break ;
3299
- }
3300
- case $ . HR : {
3301
- if ( p . openElements . currentTagId === $ . OPTION ) {
3302
- p . openElements . pop ( ) ;
3303
- }
3304
-
3305
- if ( p . openElements . currentTagId === $ . OPTGROUP ) {
3306
- p . openElements . pop ( ) ;
3307
- }
3308
-
3309
- p . _appendElement ( token , NS . HTML ) ;
3310
- token . ackSelfClosing = true ;
3311
- break ;
3312
- }
3313
- case $ . INPUT :
3314
- case $ . KEYGEN :
3315
- case $ . TEXTAREA :
3316
- case $ . SELECT : {
3317
- if ( p . openElements . hasInSelectScope ( $ . SELECT ) ) {
3318
- p . openElements . popUntilTagNamePopped ( $ . SELECT ) ;
3319
- p . _resetInsertionMode ( ) ;
3320
-
3321
- if ( token . tagID !== $ . SELECT ) {
3322
- p . _processStartTag ( token ) ;
3323
- }
3324
- }
3325
- break ;
3326
- }
3327
- case $ . SCRIPT :
3328
- case $ . TEMPLATE : {
3329
- startTagInHead ( p , token ) ;
3330
- break ;
3331
- }
3332
- default :
3333
- // Do nothing
3334
- }
3335
- }
3336
-
3337
- function endTagInSelect < T extends TreeAdapterTypeMap > ( p : Parser < T > , token : TagToken ) : void {
3338
- switch ( token . tagID ) {
3339
- case $ . OPTGROUP : {
3340
- if (
3341
- p . openElements . stackTop > 0 &&
3342
- p . openElements . currentTagId === $ . OPTION &&
3343
- p . openElements . tagIDs [ p . openElements . stackTop - 1 ] === $ . OPTGROUP
3344
- ) {
3345
- p . openElements . pop ( ) ;
3346
- }
3347
-
3348
- if ( p . openElements . currentTagId === $ . OPTGROUP ) {
3349
- p . openElements . pop ( ) ;
3350
- }
3351
- break ;
3352
- }
3353
- case $ . OPTION : {
3354
- if ( p . openElements . currentTagId === $ . OPTION ) {
3355
- p . openElements . pop ( ) ;
3356
- }
3357
- break ;
3358
- }
3359
- case $ . SELECT : {
3360
- if ( p . openElements . hasInSelectScope ( $ . SELECT ) ) {
3361
- p . openElements . popUntilTagNamePopped ( $ . SELECT ) ;
3362
- p . _resetInsertionMode ( ) ;
3363
- }
3364
- break ;
3365
- }
3366
- case $ . TEMPLATE : {
3367
- templateEndTagInHead ( p , token ) ;
3368
- break ;
3369
- }
3370
- default :
3371
- // Do nothing
3372
- }
3373
- }
3374
-
3375
- // The "in select in table" insertion mode
3376
- //------------------------------------------------------------------
3377
- function startTagInSelectInTable < T extends TreeAdapterTypeMap > ( p : Parser < T > , token : TagToken ) : void {
3378
- const tn = token . tagID ;
3379
-
3380
- if (
3381
- tn === $ . CAPTION ||
3382
- tn === $ . TABLE ||
3383
- tn === $ . TBODY ||
3384
- tn === $ . TFOOT ||
3385
- tn === $ . THEAD ||
3386
- tn === $ . TR ||
3387
- tn === $ . TD ||
3388
- tn === $ . TH
3389
- ) {
3390
- p . openElements . popUntilTagNamePopped ( $ . SELECT ) ;
3391
- p . _resetInsertionMode ( ) ;
3392
- p . _processStartTag ( token ) ;
3393
- } else {
3394
- startTagInSelect ( p , token ) ;
3395
- }
3396
- }
3397
-
3398
- function endTagInSelectInTable < T extends TreeAdapterTypeMap > ( p : Parser < T > , token : TagToken ) : void {
3399
- const tn = token . tagID ;
3400
-
3401
- if (
3402
- tn === $ . CAPTION ||
3403
- tn === $ . TABLE ||
3404
- tn === $ . TBODY ||
3405
- tn === $ . TFOOT ||
3406
- tn === $ . THEAD ||
3407
- tn === $ . TR ||
3408
- tn === $ . TD ||
3409
- tn === $ . TH
3410
- ) {
3411
- if ( p . openElements . hasInTableScope ( tn ) ) {
3412
- p . openElements . popUntilTagNamePopped ( $ . SELECT ) ;
3413
- p . _resetInsertionMode ( ) ;
3414
- p . onEndTag ( token ) ;
3415
- }
3416
- } else {
3417
- endTagInSelect ( p , token ) ;
3418
- }
3419
- }
3420
-
3421
3253
// The "in template" insertion mode
3422
3254
//------------------------------------------------------------------
3423
3255
function startTagInTemplate < T extends TreeAdapterTypeMap > ( p : Parser < T > , token : TagToken ) : void {
0 commit comments