tree-construction.html
213 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en-US-x-Hixie" ><head><title>8.2.5 Tree construction — HTML5 </title><style type="text/css">
pre { margin-left: 2em; white-space: pre-wrap; }
h2 { margin: 3em 0 1em 0; }
h3 { margin: 2.5em 0 1em 0; }
h4 { margin: 2.5em 0 0.75em 0; }
h5, h6 { margin: 2.5em 0 1em; }
h1 + h2, h1 + h2 + h2 { margin: 0.75em 0 0.75em; }
h2 + h3, h3 + h4, h4 + h5, h5 + h6 { margin-top: 0.5em; }
p { margin: 1em 0; }
hr:not(.top) { display: block; background: none; border: none; padding: 0; margin: 2em 0; height: auto; }
dl, dd { margin-top: 0; margin-bottom: 0; }
dt { margin-top: 0.75em; margin-bottom: 0.25em; clear: left; }
dt + dt { margin-top: 0; }
dd dt { margin-top: 0.25em; margin-bottom: 0; }
dd p { margin-top: 0; }
dd dl + p { margin-top: 1em; }
dd table + p { margin-top: 1em; }
p + * > li, dd li { margin: 1em 0; }
dt, dfn { font-weight: bold; font-style: normal; }
dt dfn { font-style: italic; }
pre, code { font-size: inherit; font-family: monospace; font-variant: normal; }
pre strong { color: black; font: inherit; font-weight: bold; background: yellow; }
pre em { font-weight: bolder; font-style: normal; }
@media screen { code { color: orangered; } code :link, code :visited { color: inherit; } }
var sub { vertical-align: bottom; font-size: smaller; position: relative; top: 0.1em; }
table { border-collapse: collapse; border-style: hidden hidden none hidden; }
table thead, table tbody { border-bottom: solid; }
table tbody th:first-child { border-left: solid; }
table tbody th { text-align: left; }
table td, table th { border-left: solid; border-right: solid; border-bottom: solid thin; vertical-align: top; padding: 0.2em; }
blockquote { margin: 0 0 0 2em; border: 0; padding: 0; font-style: italic; }
.bad, .bad *:not(.XXX) { color: gray; border-color: gray; background: transparent; }
.matrix, .matrix td { border: none; text-align: right; }
.matrix { margin-left: 2em; }
.dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
.dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
.dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
.toc dfn, h1 dfn, h2 dfn, h3 dfn, h4 dfn, h5 dfn, h6 dfn { font: inherit; }
img.extra { float: right; }
pre.idl { border: solid thin; background: #EEEEEE; color: black; padding: 0.5em 1em; }
pre.idl :link, pre.idl :visited { color: inherit; background: transparent; }
pre.css { border: solid thin; background: #FFFFEE; color: black; padding: 0.5em 1em; }
pre.css:first-line { color: #AAAA50; }
dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #DDFFDD; }
hr + dl.domintro, div.impl + dl.domintro { margin-top: 2.5em; margin-bottom: 1.5em; }
dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
dl.domintro dd p { margin: 0.5em 0; }
dl.switch { padding-left: 2em; }
dl.switch > dt { text-indent: -1.5em; }
dl.switch > dt:before { content: '\21AA'; padding: 0 0.5em 0 0; display: inline-block; width: 1em; text-align: right; line-height: 0.5em; }
dl.triple { padding: 0 0 0 1em; }
dl.triple dt, dl.triple dd { margin: 0; display: inline }
dl.triple dt:after { content: ':'; }
dl.triple dd:after { content: '\A'; white-space: pre; }
.diff-old { text-decoration: line-through; color: silver; background: transparent; }
.diff-chg, .diff-new { text-decoration: underline; color: green; background: transparent; }
a .diff-new { border-bottom: 1px blue solid; }
h2 { page-break-before: always; }
h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
h1 + h2, hr + h2.no-toc { page-break-before: auto; }
p > span:not([title=""]):not([class="XXX"]):not([class="impl"]):not([class="note"]),
li > span:not([title=""]):not([class="XXX"]):not([class="impl"]):not([class="note"]), { border-bottom: solid #9999CC; }
div.head { margin: 0 0 1em; padding: 1em 0 0 0; }
div.head p { margin: 0; }
div.head h1 { margin: 0; }
div.head .logo { float: right; margin: 0 1em; }
div.head .logo img { border: none } /* remove border from top image */
div.head dl { margin: 1em 0; }
div.head p.copyright, div.head p.alt { font-size: x-small; font-style: oblique; margin: 0; }
body > .toc > li { margin-top: 1em; margin-bottom: 1em; }
body > .toc.brief > li { margin-top: 0.35em; margin-bottom: 0.35em; }
body > .toc > li > * { margin-bottom: 0.5em; }
body > .toc > li > * > li > * { margin-bottom: 0.25em; }
.toc, .toc li { list-style: none; }
.brief { margin-top: 1em; margin-bottom: 1em; line-height: 1.1; }
.brief li { margin: 0; padding: 0; }
.brief li p { margin: 0; padding: 0; }
.category-list { margin-top: -0.75em; margin-bottom: 1em; line-height: 1.5; }
.category-list::before { content: '\21D2\A0'; font-size: 1.2em; font-weight: 900; }
.category-list li { display: inline; }
.category-list li:not(:last-child)::after { content: ', '; }
.category-list li > span, .category-list li > a { text-transform: lowercase; }
.category-list li * { text-transform: none; } /* don't affect <code> nested in <a> */
.XXX { color: #E50000; background: white; border: solid red; padding: 0.5em; margin: 1em 0; }
.XXX > :first-child { margin-top: 0; }
p .XXX { line-height: 3em; }
.annotation { border: solid thin black; background: #0C479D; color: white; position: relative; margin: 8px 0 20px 0; }
.annotation:before { position: absolute; left: 0; top: 0; width: 100%; height: 100%; margin: 6px -6px -6px 6px; background: #333333; z-index: -1; content: ''; }
.annotation :link, .annotation :visited { color: inherit; }
.annotation :link:hover, .annotation :visited:hover { background: transparent; }
.annotation span { border: none ! important; }
.note { color: green; background: transparent; font-family: sans-serif; }
.warning { color: red; background: transparent; }
.note, .warning { font-weight: bolder; font-style: italic; }
p.note, div.note { padding: 0.5em 2em; }
span.note { padding: 0 2em; }
.note p:first-child, .warning p:first-child { margin-top: 0; }
.note p:last-child, .warning p:last-child { margin-bottom: 0; }
.warning:before { font-style: normal; }
p.note:before { content: 'Note: '; }
p.warning:before { content: '\26A0 Warning! '; }
.bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
.bookkeeping { font-size: 0.8em; margin: 2em 0; }
.bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }
.bookkeeping dt { margin: 0.5em 2em 0; }
.bookkeeping dd { margin: 0 3em 0.5em; }
h4 { position: relative; z-index: 3; }
h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
.element {
background: #EEEEFF;
color: black;
margin: 0 0 1em 0.15em;
padding: 0 1em 0.25em 0.75em;
border-left: solid #9999FF 0.25em;
position: relative;
z-index: 1;
}
.element:before {
position: absolute;
z-index: 2;
top: 0;
left: -1.15em;
height: 2em;
width: 0.9em;
background: #EEEEFF;
content: ' ';
border-style: none none solid solid;
border-color: #9999FF;
border-width: 0.25em;
}
.example { display: block; color: #222222; background: #FCFCFC; border-left: double; margin-left: 2em; padding-left: 1em; }
td > .example:only-child { margin: 0 0 0 0.1em; }
ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
ul.domTree li li { list-style: none; }
ul.domTree li:first-child::before { position: absolute; top: 0; height: 0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
ul.domTree li:not(:last-child)::after { position: absolute; top: 0; bottom: -0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
ul.domTree span { font-style: italic; font-family: serif; }
ul.domTree .t1 code { color: purple; font-weight: bold; }
ul.domTree .t2 { font-style: normal; font-family: monospace; }
ul.domTree .t2 .name { color: black; font-weight: bold; }
ul.domTree .t2 .value { color: blue; font-weight: normal; }
ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
ul.domTree .t7 code, .domTree .t8 code { color: green; }
ul.domTree .t10 code { color: teal; }
body.dfnEnabled dfn { cursor: pointer; }
.dfnPanel {
display: inline;
position: absolute;
z-index: 10;
height: auto;
width: auto;
padding: 0.5em 0.75em;
font: small sans-serif, Droid Sans Fallback;
background: #DDDDDD;
color: black;
border: outset 0.2em;
}
.dfnPanel * { margin: 0; padding: 0; font: inherit; text-indent: 0; }
.dfnPanel :link, .dfnPanel :visited { color: black; }
.dfnPanel p { font-weight: bolder; }
.dfnPanel * + p { margin-top: 0.25em; }
.dfnPanel li { list-style-position: inside; }
#configUI { position: absolute; z-index: 20; top: 10em; right: 1em; width: 11em; font-size: small; }
#configUI p { margin: 0.5em 0; padding: 0.3em; background: #EEEEEE; color: black; border: inset thin; }
#configUI p label { display: block; }
#configUI #updateUI, #configUI .loginUI { text-align: center; }
#configUI input[type=button] { display: block; margin: auto; }
fieldset { margin: 1em; padding: 0.5em 1em; }
fieldset > legend + * { margin-top: 0; }
fieldset > :last-child { margin-bottom: 0; }
fieldset p { margin: 0.5em 0; }
.stability {
position: fixed;
bottom: 0;
left: 0; right: 0;
margin: 0 auto 0 auto !important;
z-index: 1000;
width: 50%;
background: maroon; color: yellow;
-webkit-border-radius: 1em 1em 0 0;
-moz-border-radius: 1em 1em 0 0;
border-radius: 1em 1em 0 0;
-moz-box-shadow: 0 0 1em #500;
-webkit-box-shadow: 0 0 1em #500;
box-shadow: 0 0 1em red;
padding: 0.5em 1em;
text-align: center;
}
.stability strong {
display: block;
}
.stability input {
appearance: none; margin: 0; border: 0; padding: 0.25em 0.5em; background: transparent; color: black;
position: absolute; top: -0.5em; right: 0; font: 1.25em sans-serif; text-align: center;
}
.stability input:hover {
color: white;
text-shadow: 0 0 2px black;
}
.stability input:active {
padding: 0.3em 0.45em 0.2em 0.55em;
}
.stability :link, .stability :visited,
.stability :link:hover, .stability :visited:hover {
background: transparent;
color: white;
}
</style><link href="data:text/css,.impl%20%7B%20display:%20none;%20%7D%0Ahtml%20%7B%20border:%20solid%20yellow;%20%7D%20.domintro:before%20%7B%20display:%20none;%20%7D" id="author" rel="alternate stylesheet" title="Author documentation only"><link href="data:text/css,.impl%20%7B%20background:%20%23FFEEEE;%20%7D%20.domintro:before%20%7B%20background:%20%23FFEEEE;%20%7D" id="highlight" rel="alternate stylesheet" title="Highlight implementation
requirements"><link href="http://www.w3.org/StyleSheets/TR/W3C-WD" rel="stylesheet" type="text/css"><style type="text/css">
.applies thead th > * { display: block; }
.applies thead code { display: block; }
.applies tbody th { whitespace: nowrap; }
.applies td { text-align: center; }
.applies .yes { background: yellow; }
.matrix, .matrix td { border: hidden; text-align: right; }
.matrix { margin-left: 2em; }
.dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
.dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
.dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
td.eg { border-width: thin; text-align: center; }
#table-example-1 { border: solid thin; border-collapse: collapse; margin-left: 3em; }
#table-example-1 * { font-family: "Essays1743", serif; line-height: 1.01em; }
#table-example-1 caption { padding-bottom: 0.5em; }
#table-example-1 thead, #table-example-1 tbody { border: none; }
#table-example-1 th, #table-example-1 td { border: solid thin; }
#table-example-1 th { font-weight: normal; }
#table-example-1 td { border-style: none solid; vertical-align: top; }
#table-example-1 th { padding: 0.5em; vertical-align: middle; text-align: center; }
#table-example-1 tbody tr:first-child td { padding-top: 0.5em; }
#table-example-1 tbody tr:last-child td { padding-bottom: 1.5em; }
#table-example-1 tbody td:first-child { padding-left: 2.5em; padding-right: 0; width: 9em; }
#table-example-1 tbody td:first-child::after { content: leader(". "); }
#table-example-1 tbody td { padding-left: 2em; padding-right: 2em; }
#table-example-1 tbody td:first-child + td { width: 10em; }
#table-example-1 tbody td:first-child + td ~ td { width: 2.5em; }
#table-example-1 tbody td:first-child + td + td + td ~ td { width: 1.25em; }
.apple-table-examples { border: none; border-collapse: separate; border-spacing: 1.5em 0em; width: 40em; margin-left: 3em; }
.apple-table-examples * { font-family: "Times", serif; }
.apple-table-examples td, .apple-table-examples th { border: none; white-space: nowrap; padding-top: 0; padding-bottom: 0; }
.apple-table-examples tbody th:first-child { border-left: none; width: 100%; }
.apple-table-examples thead th:first-child ~ th { font-size: smaller; font-weight: bolder; border-bottom: solid 2px; text-align: center; }
.apple-table-examples tbody th::after, .apple-table-examples tfoot th::after { content: leader(". ") }
.apple-table-examples tbody th, .apple-table-examples tfoot th { font: inherit; text-align: left; }
.apple-table-examples td { text-align: right; vertical-align: top; }
.apple-table-examples.e1 tbody tr:last-child td { border-bottom: solid 1px; }
.apple-table-examples.e1 tbody + tbody tr:last-child td { border-bottom: double 3px; }
.apple-table-examples.e2 th[scope=row] { padding-left: 1em; }
.apple-table-examples sup { line-height: 0; }
.details-example img { vertical-align: top; }
#base64-table {
white-space: nowrap;
font-size: 0.6em;
column-width: 6em;
column-count: 5;
column-gap: 1em;
-moz-column-width: 6em;
-moz-column-count: 5;
-moz-column-gap: 1em;
-webkit-column-width: 6em;
-webkit-column-count: 5;
-webkit-column-gap: 1em;
}
#base64-table thead { display: none; }
#base64-table * { border: none; }
#base64-table tbody td:first-child:after { content: ':'; }
#base64-table tbody td:last-child { text-align: right; }
#named-character-references-table {
white-space: nowrap;
font-size: 0.6em;
column-width: 30em;
column-gap: 1em;
-moz-column-width: 30em;
-moz-column-gap: 1em;
-webkit-column-width: 30em;
-webkit-column-gap: 1em;
}
#named-character-references-table > table > tbody > tr > td:first-child + td,
#named-character-references-table > table > tbody > tr > td:last-child { text-align: center; }
#named-character-references-table > table > tbody > tr > td:last-child:hover > span { position: absolute; top: auto; left: auto; margin-left: 0.5em; line-height: 1.2; font-size: 5em; border: outset; padding: 0.25em 0.5em; background: white; width: 1.25em; height: auto; text-align: center; }
#named-character-references-table > table > tbody > tr#entity-CounterClockwiseContourIntegral > td:first-child { font-size: 0.5em; }
.glyph.control { color: red; }
@font-face {
font-family: 'Essays1743';
src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743.ttf');
}
@font-face {
font-family: 'Essays1743';
font-weight: bold;
src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-Bold.ttf');
}
@font-face {
font-family: 'Essays1743';
font-style: italic;
src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-Italic.ttf');
}
@font-face {
font-family: 'Essays1743';
font-style: italic;
font-weight: bold;
src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-BoldItalic.ttf');
}
</style><style type="text/css">
.domintro:before { display: table; margin: -1em -0.5em -0.5em auto; width: auto; content: 'This box is non-normative. Implementation requirements are given below this box.'; color: black; font-style: italic; border: solid 2px; background: white; padding: 0 0.25em; }
</style><script type="text/javascript">
function getCookie(name) {
var params = location.search.substr(1).split("&");
for (var index = 0; index < params.length; index++) {
if (params[index] == name)
return "1";
var data = params[index].split("=");
if (data[0] == name)
return unescape(data[1]);
}
var cookies = document.cookie.split("; ");
for (var index = 0; index < cookies.length; index++) {
var data = cookies[index].split("=");
if (data[0] == name)
return unescape(data[1]);
}
return null;
}
</script>
<script src="link-fixup.js" type="text/javascript"></script>
<link href="style.css" rel="stylesheet"><link href="tokenization.html" title="8.2.4 Tokenization" rel="prev">
<link href="spec.html#contents" title="Table of contents" rel="index">
<link href="the-end.html" title="8.2.6 The end" rel="next">
</head><body><div class="head" id="head">
<div id="multipage-common">
<p class="stability" id="wip"><strong>This is a work in
progress!</strong> For the latest updates from the HTML WG, possibly
including important bug fixes, please look at the <a href="http://dev.w3.org/html5/spec/Overview.html">editor's draft</a> instead.
There may also be a more
<a href="http://www.w3.org/TR/html5">up-to-date Working Draft</a>
with changes based on resolution of Last Call issues.
<input onclick="closeWarning(this.parentNode)" type="button" value="╳⃝"></p>
<script type="text/javascript">
function closeWarning(element) {
element.parentNode.removeChild(element);
var date = new Date();
date.setDate(date.getDate()+4);
document.cookie = 'hide-obsolescence-warning=1; expires=' + date.toGMTString();
}
if (getCookie('hide-obsolescence-warning') == '1')
setTimeout(function () { document.getElementById('wip').parentNode.removeChild(document.getElementById('wip')); }, 2000);
</script></div>
<p><a href="http://www.w3.org/"><img alt="W3C" height="48" src="http://www.w3.org/Icons/w3c_home" width="72"></a></p>
<h1>HTML5</h1>
</div><div>
<a href="tokenization.html" class="prev">8.2.4 Tokenization</a> –
<a href="spec.html#contents">Table of contents</a> –
<a href="the-end.html" class="next">8.2.6 The end</a>
<ol class="toc"><li><ol><li><ol><li><a href="tree-construction.html#tree-construction"><span class="secno">8.2.5 </span>Tree construction</a>
<ol><li><a href="tree-construction.html#creating-and-inserting-elements"><span class="secno">8.2.5.1 </span>Creating and inserting elements</a></li><li><a href="tree-construction.html#closing-elements-that-have-implied-end-tags"><span class="secno">8.2.5.2 </span>Closing elements that have implied end tags</a></li><li><a href="tree-construction.html#foster-parenting"><span class="secno">8.2.5.3 </span>Foster parenting</a></li><li><a href="tree-construction.html#parsing-main-inhtml"><span class="secno">8.2.5.4 </span>The rules for parsing tokens in HTML content</a>
<ol><li><a href="tree-construction.html#the-initial-insertion-mode"><span class="secno">8.2.5.4.1 </span>The "initial" insertion mode</a></li><li><a href="tree-construction.html#the-before-html-insertion-mode"><span class="secno">8.2.5.4.2 </span>The "before html" insertion mode</a></li><li><a href="tree-construction.html#the-before-head-insertion-mode"><span class="secno">8.2.5.4.3 </span>The "before head" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-inhead"><span class="secno">8.2.5.4.4 </span>The "in head" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-inheadnoscript"><span class="secno">8.2.5.4.5 </span>The "in head noscript" insertion mode</a></li><li><a href="tree-construction.html#the-after-head-insertion-mode"><span class="secno">8.2.5.4.6 </span>The "after head" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-inbody"><span class="secno">8.2.5.4.7 </span>The "in body" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-incdata"><span class="secno">8.2.5.4.8 </span>The "text" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-intable"><span class="secno">8.2.5.4.9 </span>The "in table" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-intabletext"><span class="secno">8.2.5.4.10 </span>The "in table text" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-incaption"><span class="secno">8.2.5.4.11 </span>The "in caption" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-incolgroup"><span class="secno">8.2.5.4.12 </span>The "in column group" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-intbody"><span class="secno">8.2.5.4.13 </span>The "in table body" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-intr"><span class="secno">8.2.5.4.14 </span>The "in row" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-intd"><span class="secno">8.2.5.4.15 </span>The "in cell" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-inselect"><span class="secno">8.2.5.4.16 </span>The "in select" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-inselectintable"><span class="secno">8.2.5.4.17 </span>The "in select in table" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-afterbody"><span class="secno">8.2.5.4.18 </span>The "after body" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-inframeset"><span class="secno">8.2.5.4.19 </span>The "in frameset" insertion mode</a></li><li><a href="tree-construction.html#parsing-main-afterframeset"><span class="secno">8.2.5.4.20 </span>The "after frameset" insertion mode</a></li><li><a href="tree-construction.html#the-after-after-body-insertion-mode"><span class="secno">8.2.5.4.21 </span>The "after after body" insertion mode</a></li><li><a href="tree-construction.html#the-after-after-frameset-insertion-mode"><span class="secno">8.2.5.4.22 </span>The "after after frameset" insertion mode</a></li></ol></li><li><a href="tree-construction.html#parsing-main-inforeign"><span class="secno">8.2.5.5 </span>The rules for parsing tokens in foreign content</a></li></ol></li></ol></li></ol></li></ol></div>
<div class="impl">
<h4 id="tree-construction"><span class="secno">8.2.5 </span><dfn>Tree construction</dfn></h4>
<p>The input to the tree construction stage is a sequence of tokens
from the <a href="tokenization.html#tokenization">tokenization</a> stage. The tree construction
stage is associated with a DOM <code><a href="infrastructure.html#document">Document</a></code> object when a
parser is created. The "output" of this stage consists of
dynamically modifying or extending that document's DOM tree.</p>
<p>This specification does not define when an interactive user agent
has to render the <code><a href="infrastructure.html#document">Document</a></code> so that it is available to
the user, or when it has to begin accepting user input.</p>
<hr><p>As each token is emitted from the tokenizer, the user agent must
follow the appropriate steps from the following list:</p>
<dl class="switch"><dt>If there is no <a href="parsing.html#current-node">current node</a></dt>
<dt>If the <a href="parsing.html#current-node">current node</a> is an element in the <a href="namespaces.html#html-namespace-0">HTML namespace</a></dt>
<dt>If the <a href="parsing.html#current-node">current node</a> is a <a href="#mathml-text-integration-point">MathML text integration point</a> and the token is a start tag whose tag name is neither "mglyph" nor "malignmark"</dt>
<dt>If the <a href="parsing.html#current-node">current node</a> is an <code title="">annotation-xml</code> element in the <a href="namespaces.html#mathml-namespace">MathML namespace</a> and the token is a start tag whose tag name is "svg"</dt>
<dt>If the <a href="parsing.html#current-node">current node</a> is an <a href="#html-integration-point">HTML integration point</a> and the token is a start tag</dt>
<dt>If the <a href="parsing.html#current-node">current node</a> is an <a href="#html-integration-point">HTML integration point</a> and the token is a character token</dt>
<dt>If the token is an end-of-file token</dt>
<dd>Process the token according to the rules given in the section
corresponding to the current <a href="parsing.html#insertion-mode">insertion mode</a> in HTML
content.</dd>
<dt>Otherwise</dt>
<dd>Process the token according to the rules given in the section
for parsing tokens <a href="#parsing-main-inforeign" title="insertion mode: in foreign
content">in foreign content</a>.</dd>
</dl><p>The <a href="parsing.html#current-node">current node</a> is a <dfn id="mathml-text-integration-point">MathML text
integration point</dfn> if it is one of the following elements:</p>
<ul class="brief"><li>An <code title="">mi</code> element in the <a href="namespaces.html#mathml-namespace">MathML namespace</a></li>
<li>An <code title="">mo</code> element in the <a href="namespaces.html#mathml-namespace">MathML namespace</a></li>
<li>An <code title="">mn</code> element in the <a href="namespaces.html#mathml-namespace">MathML namespace</a></li>
<li>An <code title="">ms</code> element in the <a href="namespaces.html#mathml-namespace">MathML namespace</a></li>
<li>An <code title="">mtext</code> element in the <a href="namespaces.html#mathml-namespace">MathML namespace</a></li>
</ul><p>The <a href="parsing.html#current-node">current node</a> is an <dfn id="html-integration-point">HTML
integration point</dfn> if it is one of the following elements:</p>
<ul class="brief"><li>An <code title="">annotation-xml</code> element in the <a href="namespaces.html#mathml-namespace">MathML namespace</a> whose start tag token had an attribute with the name "encoding" whose value was an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">text/html</code>"</li>
<li>An <code title="">annotation-xml</code> element in the <a href="namespaces.html#mathml-namespace">MathML namespace</a> whose start tag token had an attribute with the name "encoding" whose value was an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">application/xhtml+xml</code>"</li>
<li>A <code title="">foreignObject</code> element in the <a href="namespaces.html#svg-namespace">SVG namespace</a></li>
<li>A <code title="">desc</code> element in the <a href="namespaces.html#svg-namespace">SVG namespace</a></li>
<li>A <code title="">title</code> element in the <a href="namespaces.html#svg-namespace">SVG namespace</a></li>
</ul><hr><p>When the steps below require the UA to <dfn id="insert-a-character">insert a
character</dfn> into a node, if that node has a child immediately
before where the character is to be inserted, and that child is a
<code><a href="infrastructure.html#text">Text</a></code> node, then the character must be appended to that
<code><a href="infrastructure.html#text">Text</a></code> node; otherwise, a new <code><a href="infrastructure.html#text">Text</a></code> node
whose data is just that character must be inserted in the
appropriate place.</p>
<div class="example">
<p>Here are some sample inputs to the parser and the corresponding
number of text nodes that they result in, assuming a user agent
that executes scripts.</p>
<table><thead><tr><th>Input </th><th>Number of text nodes
</th></tr></thead><tbody><tr><td><pre>A<script>
var script = document.getElementsByTagName('script')[0];
document.body.removeChild(script);
</script>B</pre>
</td><td>One text node in the document, containing "AB".
</td></tr><tr><td><pre>A<script>
var text = document.createTextNode('B');
document.body.appendChild(text);
</script>C</pre>
</td><td>Three text nodes; "A" before the script, the script's contents, and "BC" after the script (the parser appends to the text node created by the script).
</td></tr><tr><td><pre>A<script>
var text = document.getElementsByTagName('script')[0].firstChild;
text.data = 'B';
document.body.appendChild(text);
</script>C</pre>
</td><td>Two adjacent text nodes in the document, containing "A" and "BC".
</td></tr><tr><td><pre>A<table>B<tr>C</tr>D</table></pre>
</td><td>One text node before the table, containing "ABCD". (This is caused by <a href="#foster-parent" title="foster parent">foster parenting</a>.)
</td></tr><tr><td><pre>A<table><tr> B</tr> C</table></pre>
</td><td>One text node before the table, containing "A B C" (A-space-B-space-C). (This is caused by <a href="#foster-parent" title="foster parent">foster parenting</a>.)
</td></tr><tr><td><pre>A<table><tr> B</tr> </em>C</table></pre>
</td><td>One text node before the table, containing "A BC" (A-space-B-C), and one text node inside the table (as a child of a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>) with a single space character. (Space characters separated from non-space characters by non-character tokens are not affected by <a href="#foster-parent" title="foster parent">foster parenting</a>, even if those other tokens then get ignored.)
</td></tr></tbody></table></div>
<p id="mutation-during-parsing">DOM mutation events must not fire
for changes caused by the UA parsing the document. (Conceptually,
the parser is not mutating the DOM, it is constructing it.) This
includes the parsing of any content inserted using <code title="dom-document-write"><a href="apis-in-html-documents.html#dom-document-write">document.write()</a></code> and <code title="dom-document-writeln"><a href="apis-in-html-documents.html#dom-document-writeln">document.writeln()</a></code> calls. <a href="references.html#refsDOMEVENTS">[DOMEVENTS]</a></p>
<p class="note">Not all of the tag names mentioned below are
conformant tag names in this specification; many are included to
handle legacy content. They still form part of the algorithm that
implementations are required to implement to claim conformance.</p>
<p class="note">The algorithm described below places no limit on the
depth of the DOM tree generated, or on the length of tag names,
attribute names, attribute values, text nodes, etc. While
implementors are encouraged to avoid arbitrary limits, it is
recognized that <a href="infrastructure.html#hardwareLimitations">practical
concerns</a> will likely force user agents to impose nesting depth
constraints.</p>
<h5 id="creating-and-inserting-elements"><span class="secno">8.2.5.1 </span>Creating and inserting elements</h5>
<p>When the steps below require the UA to <dfn id="create-an-element-for-the-token" title="create an
element for the token">create an element for a token</dfn> in a
particular namespace, the UA must create a node implementing the
interface appropriate for the element type corresponding to the tag
name of the token in the given namespace (as given in the
specification that defines that element, e.g. for an <code><a href="text-level-semantics.html#the-a-element">a</a></code>
element in the <a href="namespaces.html#html-namespace-0">HTML namespace</a>, this specification
defines it to be the <code><a href="text-level-semantics.html#htmlanchorelement">HTMLAnchorElement</a></code> interface), with
the tag name being the name of that element, with the node being in
the given namespace, and with the attributes on the node being those
given in the given token.</p>
<p>The interface appropriate for an element in the <a href="namespaces.html#html-namespace-0">HTML
namespace</a> that is not defined in this specification (or
<a href="infrastructure.html#other-applicable-specifications">other applicable specifications</a>) is
<code><a href="elements.html#htmlunknownelement">HTMLUnknownElement</a></code>. Element in other namespaces whose
interface is not defined by that namespace's specification must use
the interface <code><a href="infrastructure.html#element">Element</a></code>.</p>
<p>When a <a href="forms.html#category-reset" title="category-reset">resettable element</a> is
created in this manner, its <a href="association-of-controls-and-forms.html#concept-form-reset-control" title="concept-form-reset-control">reset algorithm</a> must be
invoked once the attributes are set. (This initializes the element's
<a href="association-of-controls-and-forms.html#concept-fe-value" title="concept-fe-value">value</a> and <a href="association-of-controls-and-forms.html#concept-fe-checked" title="concept-fe-checked">checkedness</a> based on the element's
attributes.)</p>
<hr><p>When the steps below require the UA to <dfn id="insert-an-html-element">insert an HTML
element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
for the token</a> in the <a href="namespaces.html#html-namespace-0">HTML namespace</a>, and then
append this node to the <a href="parsing.html#current-node">current node</a>, and push it onto
the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> so that it is the new
<a href="parsing.html#current-node">current node</a>.</p>
<p>The steps below may also require that the UA insert an HTML
element in a particular place, in which case the UA must follow the
same steps except that it must insert or append the new node in the
location specified instead of appending it to the <a href="parsing.html#current-node">current
node</a>. (This happens in particular during the parsing of
tables with invalid content.)</p>
<p>If an element created by the <a href="#insert-an-html-element">insert an HTML element</a>
algorithm is a <a href="forms.html#form-associated-element">form-associated element</a>, and the
<a href="parsing.html#form-element-pointer"><code title="">form</code> element pointer</a> is not null,
and the newly created element doesn't have a <code title="attr-fae-form"><a href="association-of-controls-and-forms.html#attr-fae-form">form</a></code> attribute, the user agent must
<a href="association-of-controls-and-forms.html#concept-form-association" title="concept-form-association">associate</a> the newly
created element with the <code><a href="forms.html#the-form-element">form</a></code> element pointed to by the
<a href="parsing.html#form-element-pointer"><code title="">form</code> element pointer</a> when the
element is inserted, instead of running the <a href="association-of-controls-and-forms.html#reset-the-form-owner">reset the form
owner</a> algorithm.</p>
<hr><p>When the steps below require the UA to <dfn id="insert-a-foreign-element">insert a foreign
element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
for the token</a> in the given namespace, and then append this
node to the <a href="parsing.html#current-node">current node</a>, and push it onto the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a> so that it is the new
<a href="parsing.html#current-node">current node</a>. If the newly created element has an <code title="">xmlns</code> attribute in the <a href="namespaces.html#xmlns-namespace">XMLNS namespace</a>
whose value is not exactly the same as the element's namespace, that
is a <a href="parsing.html#parse-error">parse error</a>. Similarly, if the newly created
element has an <code title="">xmlns:xlink</code> attribute in the
<a href="namespaces.html#xmlns-namespace">XMLNS namespace</a> whose value is not the <a href="namespaces.html#xlink-namespace">XLink
Namespace</a>, that is a <a href="parsing.html#parse-error">parse error</a>.</p>
<p>When the steps below require the user agent to <dfn id="adjust-mathml-attributes">adjust MathML
attributes</dfn> for a token, then, if the token has an attribute
named <code title="">definitionurl</code>, change its name to <code title="">definitionURL</code> (note the case difference).</p>
<p>When the steps below require the user agent to <dfn id="adjust-svg-attributes">adjust SVG
attributes</dfn> for a token, then, for each attribute on the token
whose attribute name is one of the ones in the first column of the
following table, change the attribute's name to the name given in
the corresponding cell in the second column. (This fixes the case of
SVG attributes that are not all lowercase.)</p>
<table><thead><tr><th> Attribute name on token </th><th> Attribute name on element
</th></tr></thead><tbody><tr><td> <code title="">attributename</code> </td><td> <code title="">attributeName</code>
</td></tr><tr><td> <code title="">attributetype</code> </td><td> <code title="">attributeType</code>
</td></tr><tr><td> <code title="">basefrequency</code> </td><td> <code title="">baseFrequency</code>
</td></tr><tr><td> <code title="">baseprofile</code> </td><td> <code title="">baseProfile</code>
</td></tr><tr><td> <code title="">calcmode</code> </td><td> <code title="">calcMode</code>
</td></tr><tr><td> <code title="">clippathunits</code> </td><td> <code title="">clipPathUnits</code>
</td></tr><tr><td> <code title="">contentscripttype</code> </td><td> <code title="">contentScriptType</code>
</td></tr><tr><td> <code title="">contentstyletype</code> </td><td> <code title="">contentStyleType</code>
</td></tr><tr><td> <code title="">diffuseconstant</code> </td><td> <code title="">diffuseConstant</code>
</td></tr><tr><td> <code title="">edgemode</code> </td><td> <code title="">edgeMode</code>
</td></tr><tr><td> <code title="">externalresourcesrequired</code> </td><td> <code title="">externalResourcesRequired</code>
</td></tr><tr><td> <code title="">filterres</code> </td><td> <code title="">filterRes</code>
</td></tr><tr><td> <code title="">filterunits</code> </td><td> <code title="">filterUnits</code>
</td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
</td></tr><tr><td> <code title="">gradienttransform</code> </td><td> <code title="">gradientTransform</code>
</td></tr><tr><td> <code title="">gradientunits</code> </td><td> <code title="">gradientUnits</code>
</td></tr><tr><td> <code title="">kernelmatrix</code> </td><td> <code title="">kernelMatrix</code>
</td></tr><tr><td> <code title="">kernelunitlength</code> </td><td> <code title="">kernelUnitLength</code>
</td></tr><tr><td> <code title="">keypoints</code> </td><td> <code title="">keyPoints</code>
</td></tr><tr><td> <code title="">keysplines</code> </td><td> <code title="">keySplines</code>
</td></tr><tr><td> <code title="">keytimes</code> </td><td> <code title="">keyTimes</code>
</td></tr><tr><td> <code title="">lengthadjust</code> </td><td> <code title="">lengthAdjust</code>
</td></tr><tr><td> <code title="">limitingconeangle</code> </td><td> <code title="">limitingConeAngle</code>
</td></tr><tr><td> <code title="">markerheight</code> </td><td> <code title="">markerHeight</code>
</td></tr><tr><td> <code title="">markerunits</code> </td><td> <code title="">markerUnits</code>
</td></tr><tr><td> <code title="">markerwidth</code> </td><td> <code title="">markerWidth</code>
</td></tr><tr><td> <code title="">maskcontentunits</code> </td><td> <code title="">maskContentUnits</code>
</td></tr><tr><td> <code title="">maskunits</code> </td><td> <code title="">maskUnits</code>
</td></tr><tr><td> <code title="">numoctaves</code> </td><td> <code title="">numOctaves</code>
</td></tr><tr><td> <code title="">pathlength</code> </td><td> <code title="">pathLength</code>
</td></tr><tr><td> <code title="">patterncontentunits</code> </td><td> <code title="">patternContentUnits</code>
</td></tr><tr><td> <code title="">patterntransform</code> </td><td> <code title="">patternTransform</code>
</td></tr><tr><td> <code title="">patternunits</code> </td><td> <code title="">patternUnits</code>
</td></tr><tr><td> <code title="">pointsatx</code> </td><td> <code title="">pointsAtX</code>
</td></tr><tr><td> <code title="">pointsaty</code> </td><td> <code title="">pointsAtY</code>
</td></tr><tr><td> <code title="">pointsatz</code> </td><td> <code title="">pointsAtZ</code>
</td></tr><tr><td> <code title="">preservealpha</code> </td><td> <code title="">preserveAlpha</code>
</td></tr><tr><td> <code title="">preserveaspectratio</code> </td><td> <code title="">preserveAspectRatio</code>
</td></tr><tr><td> <code title="">primitiveunits</code> </td><td> <code title="">primitiveUnits</code>
</td></tr><tr><td> <code title="">refx</code> </td><td> <code title="">refX</code>
</td></tr><tr><td> <code title="">refy</code> </td><td> <code title="">refY</code>
</td></tr><tr><td> <code title="">repeatcount</code> </td><td> <code title="">repeatCount</code>
</td></tr><tr><td> <code title="">repeatdur</code> </td><td> <code title="">repeatDur</code>
</td></tr><tr><td> <code title="">requiredextensions</code> </td><td> <code title="">requiredExtensions</code>
</td></tr><tr><td> <code title="">requiredfeatures</code> </td><td> <code title="">requiredFeatures</code>
</td></tr><tr><td> <code title="">specularconstant</code> </td><td> <code title="">specularConstant</code>
</td></tr><tr><td> <code title="">specularexponent</code> </td><td> <code title="">specularExponent</code>
</td></tr><tr><td> <code title="">spreadmethod</code> </td><td> <code title="">spreadMethod</code>
</td></tr><tr><td> <code title="">startoffset</code> </td><td> <code title="">startOffset</code>
</td></tr><tr><td> <code title="">stddeviation</code> </td><td> <code title="">stdDeviation</code>
</td></tr><tr><td> <code title="">stitchtiles</code> </td><td> <code title="">stitchTiles</code>
</td></tr><tr><td> <code title="">surfacescale</code> </td><td> <code title="">surfaceScale</code>
</td></tr><tr><td> <code title="">systemlanguage</code> </td><td> <code title="">systemLanguage</code>
</td></tr><tr><td> <code title="">tablevalues</code> </td><td> <code title="">tableValues</code>
</td></tr><tr><td> <code title="">targetx</code> </td><td> <code title="">targetX</code>
</td></tr><tr><td> <code title="">targety</code> </td><td> <code title="">targetY</code>
</td></tr><tr><td> <code title="">textlength</code> </td><td> <code title="">textLength</code>
</td></tr><tr><td> <code title="">viewbox</code> </td><td> <code title="">viewBox</code>
</td></tr><tr><td> <code title="">viewtarget</code> </td><td> <code title="">viewTarget</code>
</td></tr><tr><td> <code title="">xchannelselector</code> </td><td> <code title="">xChannelSelector</code>
</td></tr><tr><td> <code title="">ychannelselector</code> </td><td> <code title="">yChannelSelector</code>
</td></tr><tr><td> <code title="">zoomandpan</code> </td><td> <code title="">zoomAndPan</code>
</td></tr></tbody></table><p>When the steps below require the user agent to <dfn id="adjust-foreign-attributes">adjust
foreign attributes</dfn> for a token, then, if any of the attributes
on the token match the strings given in the first column of the
following table, let the attribute be a namespaced attribute, with
the prefix being the string given in the corresponding cell in the
second column, the local name being the string given in the
corresponding cell in the third column, and the namespace being the
namespace given in the corresponding cell in the fourth
column. (This fixes the use of namespaced attributes, in particular
<a href="elements.html#attr-xml-lang" title="attr-xml-lang"><code title="">lang</code> attributes in
the <span>XML namespace</span></a>.)</p>
<table><thead><tr><th> Attribute name </th><th> Prefix </th><th> Local name </th><th> Namespace
</th></tr></thead><tbody><tr><td> <code title="">xlink:actuate</code> </td><td> <code title="">xlink</code> </td><td> <code title="">actuate</code> </td><td> <a href="namespaces.html#xlink-namespace">XLink namespace</a>
</td></tr><tr><td> <code title="">xlink:arcrole</code> </td><td> <code title="">xlink</code> </td><td> <code title="">arcrole</code> </td><td> <a href="namespaces.html#xlink-namespace">XLink namespace</a>
</td></tr><tr><td> <code title="">xlink:href</code> </td><td> <code title="">xlink</code> </td><td> <code title="">href</code> </td><td> <a href="namespaces.html#xlink-namespace">XLink namespace</a>
</td></tr><tr><td> <code title="">xlink:role</code> </td><td> <code title="">xlink</code> </td><td> <code title="">role</code> </td><td> <a href="namespaces.html#xlink-namespace">XLink namespace</a>
</td></tr><tr><td> <code title="">xlink:show</code> </td><td> <code title="">xlink</code> </td><td> <code title="">show</code> </td><td> <a href="namespaces.html#xlink-namespace">XLink namespace</a>
</td></tr><tr><td> <code title="">xlink:title</code> </td><td> <code title="">xlink</code> </td><td> <code title="">title</code> </td><td> <a href="namespaces.html#xlink-namespace">XLink namespace</a>
</td></tr><tr><td> <code title="">xlink:type</code> </td><td> <code title="">xlink</code> </td><td> <code title="">type</code> </td><td> <a href="namespaces.html#xlink-namespace">XLink namespace</a>
</td></tr><tr><td> <code title="">xml:base</code> </td><td> <code title="">xml</code> </td><td> <code title="">base</code> </td><td> <a href="namespaces.html#xml-namespace">XML namespace</a>
</td></tr><tr><td> <code title="">xml:lang</code> </td><td> <code title="">xml</code> </td><td> <code title="">lang</code> </td><td> <a href="namespaces.html#xml-namespace">XML namespace</a>
</td></tr><tr><td> <code title="">xml:space</code> </td><td> <code title="">xml</code> </td><td> <code title="">space</code> </td><td> <a href="namespaces.html#xml-namespace">XML namespace</a>
</td></tr><tr><td> <code title="">xmlns</code> </td><td> (none) </td><td> <code title="">xmlns</code> </td><td> <a href="namespaces.html#xmlns-namespace">XMLNS namespace</a>
</td></tr><tr><td> <code title="">xmlns:xlink</code> </td><td> <code title="">xmlns</code> </td><td> <code title="">xlink</code> </td><td> <a href="namespaces.html#xmlns-namespace">XMLNS namespace</a>
</td></tr></tbody></table><hr><p>The <dfn id="generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</dfn> and the
<dfn id="generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</dfn> consist of the
following steps. These algorithms are always invoked in response to
a start tag token.</p>
<ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p></li>
<li><p>If the algorithm that was invoked is the <a href="#generic-raw-text-element-parsing-algorithm">generic raw
text element parsing algorithm</a>, switch the tokenizer to the
<a href="tokenization.html#rawtext-state">RAWTEXT state</a>; otherwise the algorithm invoked
was the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</a>,
switch the tokenizer to the <a href="tokenization.html#rcdata-state">RCDATA state</a>.</p></li>
<li><p>Let the <a href="parsing.html#original-insertion-mode">original insertion mode</a> be the current
<a href="parsing.html#insertion-mode">insertion mode</a>.</p>
</li><li><p>Then, switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: text">text</a>".</p></li>
</ol><h5 id="closing-elements-that-have-implied-end-tags"><span class="secno">8.2.5.2 </span>Closing elements that have implied end tags</h5>
<p>When the steps below require the UA to <dfn id="generate-implied-end-tags">generate implied end
tags</dfn>, then, while the <a href="parsing.html#current-node">current node</a> is a
<code><a href="grouping-content.html#the-dd-element">dd</a></code> element, a <code><a href="grouping-content.html#the-dt-element">dt</a></code> element, an
<code><a href="grouping-content.html#the-li-element">li</a></code> element, an <code><a href="the-button-element.html#the-option-element">option</a></code> element, an
<code><a href="the-button-element.html#the-optgroup-element">optgroup</a></code> element, a <code><a href="grouping-content.html#the-p-element">p</a></code> element, an
<code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element, or an <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element, the UA must
pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p>If a step requires the UA to generate implied end tags but lists
an element to exclude from the process, then the UA must perform the
above steps as if that element was not in the above list.</p>
<h5 id="foster-parenting"><span class="secno">8.2.5.3 </span>Foster parenting</h5>
<p>Foster parenting happens when content is misnested in tables.</p>
<p>When a node <var title="">node</var> is to be <dfn id="foster-parent" title="foster
parent">foster parented</dfn>, the node <var title="">node</var>
must be inserted into the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
<p>The <dfn id="foster-parent-element">foster parent element</dfn> is the parent element of the
last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>, if there is a <code><a href="tabular-data.html#the-table-element">table</a></code> element and it has
such a parent element.</p>
<p class="note">It might have no parent or some other kind parent if
a script manipulated the DOM after the element was inserted by the
parser.</p>
<p>If there is no <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="parsing.html#stack-of-open-elements">stack of
open elements</a> (<a href="the-end.html#fragment-case">fragment case</a>), then the
<i><a href="#foster-parent-element">foster parent element</a></i> is the first element in the <a href="parsing.html#stack-of-open-elements">stack
of open elements</a> (the <code><a href="semantics.html#the-html-element">html</a></code> element). Otherwise,
if there is a <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>, but the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a> has no parent, or its parent
node is not an element, then the <i><a href="#foster-parent-element">foster parent element</a></i> is the
element before the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>.</p>
<p>If the <i><a href="#foster-parent-element">foster parent element</a></i> is the parent element of the
last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>, then <var title="">node</var> must be inserted into
the <i><a href="#foster-parent-element">foster parent element</a></i>, immediately <em>before</em> the
last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>; otherwise, <var title="">node</var> must be
<em>appended</em> to the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
<h5 id="parsing-main-inhtml"><span class="secno">8.2.5.4 </span>The rules for parsing tokens in HTML content</h5>
<h6 id="the-initial-insertion-mode"><span class="secno">8.2.5.4.1 </span>The "<dfn title="insertion mode: initial">initial</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#the-initial-insertion-mode" title="insertion mode: initial">initial</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p>Ignore the token.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <code><a href="infrastructure.html#document">Document</a></code>
object with the <code title="">data</code> attribute set to the
data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p>If the DOCTYPE token's name is not a
<a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string "<code title="">html</code>", or the token's public identifier is not
missing, or the token's system identifier is neither missing nor a
<a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string
"<code><a href="urls.html#about:legacy-compat">about:legacy-compat</a></code>", and none of the sets of
conditions in the following list are matched, then there is a
<a href="parsing.html#parse-error">parse error</a>.</p>
<ul><li>The DOCTYPE token's name is a <a href="infrastructure.html#case-sensitive">case-sensitive</a>
match for the string "<code title="">html</code>", the token's
public identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a> string
"<code title="">-//W3C//DTD HTML 4.0//EN</code>", and
the token's system identifier is either missing or the
<a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/REC-html40/strict.dtd</code>".</li>
<li>The DOCTYPE token's name is a <a href="infrastructure.html#case-sensitive">case-sensitive</a>
match for the string "<code title="">html</code>", the token's
public identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a> string
"<code title="">-//W3C//DTD HTML 4.01//EN</code>", and
the token's system identifier is either missing or the
<a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/html4/strict.dtd</code>".</li>
<li>The DOCTYPE token's name is a <a href="infrastructure.html#case-sensitive">case-sensitive</a>
match for the string "<code title="">html</code>", the token's
public identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a> string
"<code title="">-//W3C//DTD XHTML 1.0 Strict//EN</code>",
and the token's system identifier is the
<a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</code>".</li>
<li>The DOCTYPE token's name is a <a href="infrastructure.html#case-sensitive">case-sensitive</a>
match for the string "<code title="">html</code>", the token's
public identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a> string
"<code title="">-//W3C//DTD XHTML 1.1//EN</code>", and
the token's system identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a>
string "<code title="">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd</code>".</li>
</ul><p>Conformance checkers may, based on the values (including
presence or lack thereof) of the DOCTYPE token's name, public
identifier, or system identifier, switch to a conformance checking
mode for another language (e.g. based on the DOCTYPE token a
conformance checker could recognize that the document is an
HTML4-era document, and defer to an HTML4 conformance
checker.)</p>
<p>Append a <code><a href="infrastructure.html#documenttype">DocumentType</a></code> node to the
<code><a href="infrastructure.html#document">Document</a></code> node, with the <code title="">name</code>
attribute set to the name given in the DOCTYPE token, or the empty
string if the name was missing; the <code title="">publicId</code>
attribute set to the public identifier given in the DOCTYPE token,
or the empty string if the public identifier was missing; the
<code title="">systemId</code> attribute set to the system
identifier given in the DOCTYPE token, or the empty string if the
system identifier was missing; and the other attributes specific
to <code><a href="infrastructure.html#documenttype">DocumentType</a></code> objects set to null and empty lists
as appropriate. Associate the <code><a href="infrastructure.html#documenttype">DocumentType</a></code> node with
the <code><a href="infrastructure.html#document">Document</a></code> object so that it is returned as the
value of the <code title="">doctype</code> attribute of the
<code><a href="infrastructure.html#document">Document</a></code> object.</p>
<p id="quirks-mode-doctypes">Then, if the DOCTYPE token matches
one of the conditions in the following list, then set the
<code><a href="infrastructure.html#document">Document</a></code> to <a href="dom.html#quirks-mode">quirks mode</a>:</p>
<ul class="brief"><li> The <i>force-quirks flag</i> is set to <i>on</i>. </li>
<li> The name is set to anything other than "<code title="">html</code>" (compared <a href="infrastructure.html#case-sensitive" title="case-sensitive">case-sensitively</a>). </li>
<li> The public identifier starts with: "<code title="">+//Silmaril//dtd html Pro v0r11 19970101//</code>" </li>
<li> The public identifier starts with: "<code title="">-//AdvaSoft Ltd//DTD HTML 3.0 asWedit + extensions//</code>" </li>
<li> The public identifier starts with: "<code title="">-//AS//DTD HTML 3.0 asWedit + extensions//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 1//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 2//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 1//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 2//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.1E//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.0//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2 Final//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 0//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 1//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 2//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 3//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 0//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 1//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 2//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 3//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict//</code>" </li>
<li> The public identifier starts with: "<code title="">-//IETF//DTD HTML//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Metrius//DTD Metrius Presentational//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML Strict//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 Tables//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML Strict//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 Tables//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD HTML//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD Strict HTML//</code>" </li>
<li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML 2.0//</code>" </li>
<li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended 1.0//</code>" </li>
<li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended Relaxed 1.0//</code>" </li>
<li> The public identifier starts with: "<code title="">-//SoftQuad Software//DTD HoTMetaL PRO 6.0::19990601::extensions to HTML 4.0//</code>" </li>
<li> The public identifier starts with: "<code title="">-//SoftQuad//DTD HoTMetaL PRO 4.0::19971010::extensions to HTML 4.0//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Spyglass//DTD HTML 2.0 Extended//</code>" </li>
<li> The public identifier starts with: "<code title="">-//SQ//DTD HTML 2.0 HoTMetaL + extensions//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava HTML//</code>" </li>
<li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava Strict HTML//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3 1995-03-24//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Draft//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Final//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2S Draft//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Frameset//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Transitional//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 19960712//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 970421//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD W3 HTML//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3O//DTD W3 HTML 3.0//</code>" </li>
<li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML Strict 3.0//EN//</code>" </li>
<li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML 2.0//</code>" </li>
<li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML//</code>" </li>
<li> The public identifier is set to: "<code title="">-/W3C/DTD HTML 4.0 Transitional/EN</code>" </li>
<li> The public identifier is set to: "<code title="">HTML</code>" </li>
<li> The system identifier is set to: "<code title="">http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd</code>" </li>
<li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//</code>" </li>
<li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//</code>" </li>
</ul><p>Otherwise, if the DOCTYPE token matches one of the conditions
in the following list, then set the <code><a href="infrastructure.html#document">Document</a></code> to
<a href="dom.html#limited-quirks-mode">limited-quirks mode</a>:</p>
<ul class="brief"><li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Frameset//</code>" </li>
<li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Transitional//</code>" </li>
<li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//</code>" </li>
<li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//</code>" </li>
</ul><p>The system identifier and public identifier strings must be
compared to the values given in the lists above in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
case-insensitive</a> manner. A system identifier whose value is
the empty string is not considered missing for the purposes of the
conditions above.</p>
<p>Then, switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>".</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>If the document is <em>not</em> <a href="the-iframe-element.html#an-iframe-srcdoc-document">an <code>iframe</code>
<code title="attr-iframe-srcdoc">srcdoc</code> document</a>,
then this is a <a href="parsing.html#parse-error">parse error</a>; set the
<code><a href="infrastructure.html#document">Document</a></code> to <a href="dom.html#quirks-mode">quirks mode</a>.</p>
<p>In any case, switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>", then
reprocess the current token.</p>
</dd>
</dl><h6 id="the-before-html-insertion-mode"><span class="secno">8.2.5.4.2 </span>The "<dfn title="insertion mode: before html">before html</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <code><a href="infrastructure.html#document">Document</a></code>
object with the <code title="">data</code> attribute set to the
data given in the comment token.</p>
</dd>
<dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p>Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the <a href="namespaces.html#html-namespace-0">HTML
namespace</a>. Append it to the <code><a href="infrastructure.html#document">Document</a></code>
object. Put this element in the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p id="parser-appcache">If the <code><a href="infrastructure.html#document">Document</a></code> is being
loaded as part of <a href="history.html#navigate" title="navigate">navigation</a> of a
<a href="browsers.html#browsing-context">browsing context</a>, then: if the newly created element
has a <code title="attr-html-manifest"><a href="semantics.html#attr-html-manifest">manifest</a></code> attribute
whose value is not the empty string, then <a href="urls.html#resolve-a-url" title="resolve a
url">resolve</a> the value of that attribute to an
<a href="urls.html#absolute-url">absolute URL</a>, relative to the newly created element,
and if that is successful, run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
algorithm</a> with the resulting <a href="urls.html#absolute-url">absolute URL</a> with
any <a href="urls.html#url-fragment" title="url-fragment"><fragment></a> component
removed; otherwise, if there is no such attribute, or its value is
the empty string, or resolving its value fails, run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
algorithm</a> with no manifest. The algorithm must be passed
the <code><a href="infrastructure.html#document">Document</a></code> object.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>".</p>
</dd>
<dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
<dd>
<p>Act as described in the "anything else" entry below.</p>
</dd>
<dt>Any other end tag</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>Create an <code><a href="semantics.html#the-html-element">html</a></code> element. Append it to the
<code><a href="infrastructure.html#document">Document</a></code> object. Put this element in the <a href="parsing.html#stack-of-open-elements">stack
of open elements</a>.</p>
<p>If the <code><a href="infrastructure.html#document">Document</a></code> is being loaded as part of <a href="history.html#navigate" title="navigate">navigation</a> of a <a href="browsers.html#browsing-context">browsing
context</a>, then: run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
algorithm</a> with no manifest, passing it the
<code><a href="infrastructure.html#document">Document</a></code> object.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>", then
reprocess the current token.</p>
</dd>
</dl><p>The root element can end up being removed from the
<code><a href="infrastructure.html#document">Document</a></code> object, e.g. by scripts; nothing in particular
happens in such cases, content continues being appended to the nodes
as described in the next section.</p>
<h6 id="the-before-head-insertion-mode"><span class="secno">8.2.5.4.3 </span>The "<dfn title="insertion mode: before head">before head</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p>Ignore the token.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <a href="parsing.html#current-node">current
node</a> with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>A start tag whose tag name is "head"</dt>
<dd>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>Set the <a href="parsing.html#head-element-pointer"><code title="">head</code> element pointer</a>
to the newly created <code><a href="semantics.html#the-head-element">head</a></code> element.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>".</p>
</dd>
<dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
<dd>
<p>Act as if a start tag token with the tag name "head" and no
attributes had been seen, then reprocess the current token.</p>
</dd>
<dt>Any other end tag</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>Act as if a start tag token with the tag name "head" and no
attributes had been seen, then reprocess the current
token.</p>
</dd>
</dl><h6 id="parsing-main-inhead"><span class="secno">8.2.5.4.4 </span>The "<dfn title="insertion mode: in head">in head</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
the <a href="parsing.html#current-node">current node</a>.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <a href="parsing.html#current-node">current
node</a> with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>A start tag whose tag name is one of: "base", "basefont",
"bgsound", "command", "link"</dt>
<dd>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p><a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
token's <i>self-closing flag</i></a>, if it is set.</p>
</dd>
<dt>A start tag whose tag name is "meta"</dt>
<dd>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p><a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
token's <i>self-closing flag</i></a>, if it is set.</p>
<p id="meta-charset-during-parse">If the element has a <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">charset</a></code> attribute, and its value
is either a supported <a href="infrastructure.html#ascii-compatible-character-encoding">ASCII-compatible character
encoding</a> or a UTF-16 encoding, and the <a href="parsing.html#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is currently
<i>tentative</i>, then <a href="parsing.html#change-the-encoding">change the encoding</a> to the
encoding given by the value of the <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">charset</a></code> attribute.</p>
<p>Otherwise, if the element has an <code title="attr-meta-http-equiv"><a href="semantics.html#attr-meta-http-equiv">http-equiv</a></code> attribute whose
value is an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the
string "<code title="">Content-Type</code>", and the element has a
<code title="attr-meta-content"><a href="semantics.html#attr-meta-content">content</a></code> attribute, and
applying the <a href="fetching-resources.html#algorithm-for-extracting-an-encoding-from-a-meta-element">algorithm for extracting an encoding from a
<code>meta</code> element</a> to that attribute's value returns
a supported <a href="infrastructure.html#ascii-compatible-character-encoding">ASCII-compatible character encoding</a> or a
UTF-16 encoding, and the <a href="parsing.html#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is currently
<i>tentative</i>, then <a href="parsing.html#change-the-encoding">change the encoding</a> to the
extracted encoding.</p>
</dd>
<dt>A start tag whose tag name is "title"</dt>
<dd>
<p>Follow the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</a>.</p>
</dd>
<dt>A start tag whose tag name is "noscript", if the <a href="parsing.html#scripting-flag">scripting flag</a> is enabled</dt>
<dt>A start tag whose tag name is one of: "noframes", "style"</dt>
<dd>
<p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
</dd>
<dt>A start tag whose tag name is "noscript", if the <a href="parsing.html#scripting-flag">scripting flag</a> is disabled</dt>
<dd>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inheadnoscript" title="insertion mode: in head noscript">in head
noscript</a>".</p>
</dd>
<dt id="scriptTag">A start tag whose tag name is "script"</dt>
<dd>
<p>Run these steps:</p>
<ol><li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the
<a href="namespaces.html#html-namespace-0">HTML namespace</a>.</p></li>
<li>
<p>Mark the element as being <a href="scripting-1.html#parser-inserted">"parser-inserted"</a> and
unset the element's <a href="scripting-1.html#force-async">"force-async"</a> flag.</p>
<p class="note">This ensures that, if the script is external,
any <code title="dom-document-write"><a href="apis-in-html-documents.html#dom-document-write">document.write()</a></code>
calls in the script will execute in-line, instead of blowing the
document away, as would happen in most other cases. It also
prevents the script from executing until the end tag is
seen.</p>
</li>
<li><p>If the parser was originally created for the <a href="the-end.html#html-fragment-parsing-algorithm">HTML
fragment parsing algorithm</a>, then mark the
<code><a href="scripting-1.html#the-script-element">script</a></code> element as <a href="scripting-1.html#already-started">"already
started"</a>. (<a href="the-end.html#fragment-case">fragment case</a>)</p></li>
<li><p>Append the new element to the <a href="parsing.html#current-node">current node</a>
and push it onto the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p></li>
<li><p>Switch the tokenizer to the <a href="tokenization.html#script-data-state">script data
state</a>.</p></li>
<li><p>Let the <a href="parsing.html#original-insertion-mode">original insertion mode</a> be the current
<a href="parsing.html#insertion-mode">insertion mode</a>.</p>
</li><li><p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: text">text</a>".</p></li>
</ol></dd>
<dt>An end tag whose tag name is "head"</dt>
<dd>
<p>Pop the <a href="parsing.html#current-node">current node</a> (which will be the
<code><a href="semantics.html#the-head-element">head</a></code> element) off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#the-after-head-insertion-mode" title="insertion mode: after head">after head</a>".</p>
</dd>
<dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
<dd>
<p>Act as described in the "anything else" entry below.</p>
</dd>
<dt>A start tag whose tag name is "head"</dt>
<dt>Any other end tag</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>Act as if an end tag token with the tag name "head" had
been seen, and reprocess the current token.</p>
</dd>
</dl><h6 id="parsing-main-inheadnoscript"><span class="secno">8.2.5.4.5 </span>The "<dfn title="insertion mode: in head noscript">in head noscript</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-inheadnoscript" title="insertion mode: in head noscript">in head noscript</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>An end tag whose tag name is "noscript"</dt>
<dd>
<p>Pop the <a href="parsing.html#current-node">current node</a> (which will be a
<code><a href="scripting-1.html#the-noscript-element">noscript</a></code> element) from the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>; the new <a href="parsing.html#current-node">current node</a> will be a
<code><a href="semantics.html#the-head-element">head</a></code> element.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>".</p>
</dd>
<dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dt>A comment token</dt>
<dt>A start tag whose tag name is one of: "basefont", "bgsound",
"link", "meta", "noframes", "style"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>An end tag whose tag name is "br"</dt>
<dd>
<p>Act as described in the "anything else" entry below.</p>
</dd>
<dt>A start tag whose tag name is one of: "head", "noscript"</dt>
<dt>Any other end tag</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Act as if an end tag with the tag
name "noscript" had been seen and reprocess the current
token.</p>
</dd>
</dl><h6 id="the-after-head-insertion-mode"><span class="secno">8.2.5.4.6 </span>The "<dfn title="insertion mode: after head">after head</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#the-after-head-insertion-mode" title="insertion mode: after head">after head</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
the <a href="parsing.html#current-node">current node</a>.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <a href="parsing.html#current-node">current
node</a> with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>A start tag whose tag name is "body"</dt>
<dd>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>".</p>
</dd>
<dt>A start tag whose tag name is "frameset"</dt>
<dd>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inframeset" title="insertion mode: in frameset">in frameset</a>".</p>
</dd>
<dt>A start tag token whose tag name is one of: "base", "basefont",
"bgsound", "link", "meta", "noframes", "script", "style",
"title"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>.</p>
<p>Push the node pointed to by the <a href="parsing.html#head-element-pointer"><code title="">head</code> element pointer</a> onto the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>.</p>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
<p>Remove the node pointed to by the <a href="parsing.html#head-element-pointer"><code title="">head</code> element pointer</a> from the <a href="parsing.html#stack-of-open-elements">stack
of open elements</a>.</p>
<p class="note">The <a href="parsing.html#head-element-pointer"><code title="">head</code> element
pointer</a> cannot be null at this point.</p>
</dd>
<dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
<dd>
<p>Act as described in the "anything else" entry below.</p>
</dd>
<dt>A start tag whose tag name is "head"</dt>
<dt>Any other end tag</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>Act as if a start tag token with the tag name "body" and no
attributes had been seen, then set the <a href="parsing.html#frameset-ok-flag">frameset-ok
flag</a> back to "ok", and then reprocess the current
token.</p>
</dd>
</dl><h6 id="parsing-main-inbody"><span class="secno">8.2.5.4.7 </span>The "<dfn title="insertion mode: in body">in body</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is U+0000 NULL</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A character token that is one of U+0009 CHARACTER TABULATION,
U+000A LINE FEED (LF), U+000C FORM FEED (FF), U+000D CARRIAGE
RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-a-character" title="insert a character">Insert the token's
character</a> into the <a href="parsing.html#current-node">current node</a>.</p>
</dd>
<dt>Any other character token</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-a-character" title="insert a character">Insert the token's
character</a> into the <a href="parsing.html#current-node">current node</a>.</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <a href="parsing.html#current-node">current
node</a> with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. For each attribute on the token,
check to see if the attribute is already present on the top
element of the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>. If it is not,
add the attribute and its corresponding value to that element.</p>
</dd>
<dt>A start tag token whose tag name is one of: "base", "basefont",
"bgsound", "command", "link", "meta", "noframes", "script",
"style", "title"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>A start tag whose tag name is "body"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>.</p>
<p>If the second element on the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> is not a <code><a href="sections.html#the-body-element">body</a></code> element, or, if the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a> has only one node on it,
then ignore the token. (<a href="the-end.html#fragment-case">fragment case</a>)</p>
<p>Otherwise, set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok";
then, for each attribute on the token, check to see if the
attribute is already present on the <code><a href="sections.html#the-body-element">body</a></code> element (the
second element) on the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>, and if
it is not, add the attribute and its corresponding value to that
element.</p>
</dd>
<dt>A start tag whose tag name is "frameset"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>.</p>
<p>If the second element on the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> is not a <code><a href="sections.html#the-body-element">body</a></code> element, or, if the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a> has only one node on it,
then ignore the token. (<a href="the-end.html#fragment-case">fragment case</a>)</p>
<p>If the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> is set to "not ok", ignore
the token.</p>
<p>Otherwise, run the following steps:</p>
<ol><li><p>Remove the second element on the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> from its parent node, if it has one.</p></li>
<li><p>Pop all the nodes from the bottom of the <a href="parsing.html#stack-of-open-elements">stack of
open elements</a>, from the <a href="parsing.html#current-node">current node</a> up to,
but not including, the root <code><a href="semantics.html#the-html-element">html</a></code> element.</p>
</li><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
token.</p></li>
<li><p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inframeset" title="insertion mode: in frameset">in frameset</a>".</p>
</li></ol></dd>
<dt>An end-of-file token</dt>
<dd>
<p>If there is a node in the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>
that is not either a <code><a href="grouping-content.html#the-dd-element">dd</a></code> element, a <code><a href="grouping-content.html#the-dt-element">dt</a></code>
element, an <code><a href="grouping-content.html#the-li-element">li</a></code> element, a <code><a href="grouping-content.html#the-p-element">p</a></code> element, a
<code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element, a <code><a href="tabular-data.html#the-td-element">td</a></code> element, a
<code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element, a <code><a href="tabular-data.html#the-th-element">th</a></code> element, a
<code><a href="tabular-data.html#the-thead-element">thead</a></code> element, a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, the
<code><a href="sections.html#the-body-element">body</a></code> element, or the <code><a href="semantics.html#the-html-element">html</a></code> element, then
this is a <a href="parsing.html#parse-error">parse error</a>.</p>
<p><a href="the-end.html#stop-parsing">Stop parsing</a>.</p>
</dd>
<dt>An end tag whose tag name is "body"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-scope" title="has an element in scope">have a <code>body</code> element
in scope</a>, this is a <a href="parsing.html#parse-error">parse error</a>; ignore the
token.</p>
<p>Otherwise, if there is a node in the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> that is not either a <code><a href="grouping-content.html#the-dd-element">dd</a></code> element, a
<code><a href="grouping-content.html#the-dt-element">dt</a></code> element, an <code><a href="grouping-content.html#the-li-element">li</a></code> element, an
<code><a href="the-button-element.html#the-optgroup-element">optgroup</a></code> element, an <code><a href="the-button-element.html#the-option-element">option</a></code> element, a
<code><a href="grouping-content.html#the-p-element">p</a></code> element, an <code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element, an
<code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element, a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element, a
<code><a href="tabular-data.html#the-td-element">td</a></code> element, a <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element, a
<code><a href="tabular-data.html#the-th-element">th</a></code> element, a <code><a href="tabular-data.html#the-thead-element">thead</a></code> element, a
<code><a href="tabular-data.html#the-tr-element">tr</a></code> element, the <code><a href="sections.html#the-body-element">body</a></code> element, or the
<code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="parsing.html#parse-error">parse
error</a>.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-afterbody" title="insertion mode: after body">after body</a>".</p>
</dd>
<dt>An end tag whose tag name is "html"</dt>
<dd>
<p>Act as if an end tag with tag name "body" had been seen,
then, if that token wasn't ignored, reprocess the current
token.</p>
</dd>
<dt>A start tag whose tag name is one of: "address", "article",
"aside", "blockquote", "center", "details", "dir", "div", "dl",
"fieldset", "figcaption", "figure", "footer", "header", "hgroup",
"menu", "nav", "ol", "p", "section", "summary", "ul"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-button-scope" title="has an
element in button scope">has a <code>p</code> element in button
scope</a>, then act as if an end tag with the tag name "p" had
been seen.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
</dd>
<dt>A start tag whose tag name is one of: "h1", "h2", "h3", "h4",
"h5", "h6"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-button-scope" title="has
an element in button scope">has a <code>p</code> element in button
scope</a>, then act as if an end tag with the tag name
"p" had been seen.</p>
<p>If the <a href="parsing.html#current-node">current node</a> is an element whose tag name
is one of "h1", "h2", "h3", "h4", "h5", or "h6", then this is a
<a href="parsing.html#parse-error">parse error</a>; pop the <a href="parsing.html#current-node">current node</a> off
the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
</dd>
<dt>A start tag whose tag name is one of: "pre", "listing"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-button-scope" title="has
an element in button scope">has a <code>p</code> element in button
scope</a>, then act as if an end tag with the tag name
"p" had been seen.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>If the next token is a U+000A LINE FEED (LF) character
token, then ignore that token and move on to the next
one. (Newlines at the start of <code><a href="grouping-content.html#the-pre-element">pre</a></code> blocks are
ignored as an authoring convenience.)</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
</dd>
<dt>A start tag whose tag name is "form"</dt>
<dd>
<p>If the <a href="parsing.html#form-element-pointer"><code title="form">form</code> element
pointer</a> is not null, then this is a <a href="parsing.html#parse-error">parse
error</a>; ignore the token.</p>
<p>Otherwise:</p>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-button-scope" title="has
an element in button scope">has a <code>p</code> element in button
scope</a>, then act as if an end tag with the tag name
"p" had been seen.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, and set the
<a href="parsing.html#form-element-pointer"><code title="form">form</code> element pointer</a> to
point to the element created.</p>
</dd>
<dt>A start tag whose tag name is "li"</dt>
<dd>
<p>Run these steps:</p>
<ol><li><p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
<li><p>Initialize <var title="">node</var> to be the <a href="parsing.html#current-node">current
node</a> (the bottommost node of the stack).</p></li>
<li><p><i>Loop</i>: If <var title="">node</var> is an
<code><a href="grouping-content.html#the-li-element">li</a></code> element, then act as if an end tag with the tag
name "li" had been seen, then jump to the last step.</p></li>
<li><p>If <var title="">node</var> is in the <a href="parsing.html#special">special</a>
category, but is not an <code><a href="sections.html#the-address-element">address</a></code>, <code><a href="grouping-content.html#the-div-element">div</a></code>,
or <code><a href="grouping-content.html#the-p-element">p</a></code> element, then jump to the last step.</p></li>
<li><p>Otherwise, set <var title="">node</var> to the previous
entry in the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> and return to
the step labeled <i>loop</i>.</p></li>
<li>
<p>This is the last step.</p>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-button-scope" title="has
an element in button scope">has a <code>p</code> element in button
scope</a>, then act as if an end tag with the tag name
"p" had been seen.</p>
<p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
token.</p>
</li>
</ol></dd>
<dt>A start tag whose tag name is one of: "dd", "dt"</dt>
<dd>
<p>Run these steps:</p>
<ol><li><p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
<li><p>Initialize <var title="">node</var> to be the <a href="parsing.html#current-node">current
node</a> (the bottommost node of the stack).</p></li>
<li><p><i>Loop</i>: If <var title="">node</var> is a
<code><a href="grouping-content.html#the-dd-element">dd</a></code> or <code><a href="grouping-content.html#the-dt-element">dt</a></code> element, then act as if an end
tag with the same tag name as <var title="">node</var> had been
seen, then jump to the last step.</p></li>
<li><p>If <var title="">node</var> is in the <a href="parsing.html#special">special</a>
category, but is not an <code><a href="sections.html#the-address-element">address</a></code>, <code><a href="grouping-content.html#the-div-element">div</a></code>,
or <code><a href="grouping-content.html#the-p-element">p</a></code> element, then jump to the last step.</p></li>
<li><p>Otherwise, set <var title="">node</var> to the previous
entry in the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> and return to
the step labeled <i>loop</i>.</p></li>
<li>
<p>This is the last step.</p>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-button-scope" title="has
an element in button scope">has a <code>p</code> element in button
scope</a>, then act as if an end tag with the tag name
"p" had been seen.</p>
<p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
token.</p>
</li>
</ol></dd>
<dt>A start tag whose tag name is "plaintext"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-button-scope" title="has
an element in button scope">has a <code>p</code> element in button
scope</a>, then act as if an end tag with the tag name
"p" had been seen.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>Switch the tokenizer to the <a href="tokenization.html#plaintext-state">PLAINTEXT state</a>.</p>
<p class="note">Once a start tag with the tag name "plaintext" has
been seen, that will be the last token ever seen other than
character tokens (and the end-of-file token), because there is no
way to switch out of the <a href="tokenization.html#plaintext-state">PLAINTEXT state</a>.</p>
</dd>
<dt>A start tag whose tag name is "button"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-scope" title="has
an element in scope">has a <code>button</code> element in
scope</a>, then this is a <a href="parsing.html#parse-error">parse error</a>;
act as if an end tag with the tag name "button" had been seen,
then reprocess the token.</p>
<p>Otherwise:</p>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
</dd>
<dt>An end tag whose tag name is one of: "address", "article",
"aside", "blockquote", "button", "center", "details", "dir", "div",
"dl", "fieldset", "figcaption", "figure", "footer", "header",
"hgroup", "listing", "menu", "nav", "ol", "pre", "section",
"summary", "ul"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-scope" title="has an element in scope">have an element in scope</a>
with the same tag name as that of the token, then this is a
<a href="parsing.html#parse-error">parse error</a>; ignore the token.</p>
<p>Otherwise, run these steps:</p>
<ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
<li><p>If the <a href="parsing.html#current-node">current node</a> is not an element with
the same tag name as that of the token, then this is a
<a href="parsing.html#parse-error">parse error</a>.</p></li>
<li><p>Pop elements from the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>
until an element with the same tag name as the token has been
popped from the stack.</p></li>
</ol></dd>
<dt>An end tag whose tag name is "form"</dt>
<dd>
<p>Let <var title="">node</var> be the element that the
<a href="parsing.html#form-element-pointer"><code title="">form</code> element pointer</a> is set
to.</p>
<p>Set the <a href="parsing.html#form-element-pointer"><code title="">form</code> element pointer</a>
to null.</p>
<p>If <var title="">node</var> is null or the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> does not <a href="parsing.html#has-an-element-in-scope" title="has an element in
scope">have <var title="">node</var> in scope</a>, then this is
a <a href="parsing.html#parse-error">parse error</a>; ignore the token.</p>
<p>Otherwise, run these steps:</p>
<ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
<li><p>If the <a href="parsing.html#current-node">current node</a> is not <var title="">node</var>, then this is a <a href="parsing.html#parse-error">parse
error</a>.</p></li>
<li><p>Remove <var title="">node</var> from the <a href="parsing.html#stack-of-open-elements">stack of
open elements</a>.</p></li>
</ol></dd>
<dt>An end tag whose tag name is "p"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-button-scope" title="has an element in button scope">have an element in button
scope</a> with the same tag name as that of the token, then this
is a <a href="parsing.html#parse-error">parse error</a>; act as if a start tag with the tag
name "p" had been seen, then reprocess the current token.</p>
<p>Otherwise, run these steps:</p>
<ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
for elements with the same tag name as the token.</p></li>
<li><p>If the <a href="parsing.html#current-node">current node</a> is not an element with
the same tag name as that of the token, then this is a
<a href="parsing.html#parse-error">parse error</a>.</p></li>
<li><p>Pop elements from the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>
until an element with the same tag name as the token has been
popped from the stack.</p></li>
</ol></dd>
<dt>An end tag whose tag name is "li"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-list-item-scope" title="has an element in list item scope">have an element in list
item scope</a> with the same tag name as that of the token,
then this is a <a href="parsing.html#parse-error">parse error</a>; ignore the token.</p>
<p>Otherwise, run these steps:</p>
<ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
for elements with the same tag name as the token.</p></li>
<li><p>If the <a href="parsing.html#current-node">current node</a> is not an element with
the same tag name as that of the token, then this is a
<a href="parsing.html#parse-error">parse error</a>.</p></li>
<li><p>Pop elements from the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>
until an element with the same tag name as the token has been
popped from the stack.</p></li>
</ol></dd>
<dt>An end tag whose tag name is one of: "dd", "dt"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-scope" title="has an element in scope">have an element in scope</a>
with the same tag name as that of the token, then this is a
<a href="parsing.html#parse-error">parse error</a>; ignore the token.</p>
<p>Otherwise, run these steps:</p>
<ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
for elements with the same tag name as the token.</p></li>
<li><p>If the <a href="parsing.html#current-node">current node</a> is not an element with
the same tag name as that of the token, then this is a
<a href="parsing.html#parse-error">parse error</a>.</p></li>
<li><p>Pop elements from the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>
until an element with the same tag name as the token has been
popped from the stack.</p></li>
</ol></dd>
<dt>An end tag whose tag name is one of: "h1", "h2", "h3", "h4", "h5", "h6"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-scope" title="has an element in scope">have an element in scope</a>
whose tag name is one of "h1", "h2", "h3", "h4", "h5", or "h6",
then this is a <a href="parsing.html#parse-error">parse error</a>; ignore the token.</p>
<p>Otherwise, run these steps:</p>
<ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
<li><p>If the <a href="parsing.html#current-node">current node</a> is not an element with
the same tag name as that of the token, then this is a
<a href="parsing.html#parse-error">parse error</a>.</p></li>
<li><p>Pop elements from the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>
until an element whose tag name is one of "h1", "h2", "h3", "h4",
"h5", or "h6" has been popped from the stack.</p></li>
</ol></dd>
<dt>An end tag whose tag name is "sarcasm"</dt>
<dd>
<p>Take a deep breath, then act as described in the "any other end
tag" entry below.</p>
</dd>
<dt>A start tag whose tag name is "a"</dt>
<dd>
<p>If the <a href="parsing.html#list-of-active-formatting-elements">list of active formatting elements</a>
contains an element whose tag name is "a" between the end of
the list and the last marker on the list (or the start of the
list if there is no marker on the list), then this is a
<a href="parsing.html#parse-error">parse error</a>; act as if an end tag with the tag
name "a" had been seen, then remove that element from the
<a href="parsing.html#list-of-active-formatting-elements">list of active formatting elements</a> and the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a> if the end tag didn't
already remove it (it might not have if the element is not
<a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">in table
scope</a>).</p>
<p class="example">In the non-conforming stream
<code><a href="a">a<table><a href="b">b</table>x</code>,
the first <code><a href="text-level-semantics.html#the-a-element">a</a></code> element would be closed upon seeing the
second one, and the "x" character would be inside a link to "b",
not to "a". This is despite the fact that the outer <code><a href="text-level-semantics.html#the-a-element">a</a></code>
element is not in table scope (meaning that a regular
<code></a></code> end tag at the start of the table wouldn't
close the outer <code><a href="text-level-semantics.html#the-a-element">a</a></code> element). The result is that the
two <code><a href="text-level-semantics.html#the-a-element">a</a></code> elements are indirectly nested inside each
other — non-conforming markup will often result in
non-conforming DOMs when parsed.</p>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. <a href="parsing.html#push-onto-the-list-of-active-formatting-elements">Push
onto the list of active formatting elements</a> that
element.</p>
</dd>
<dt>A start tag whose tag name is one of: "b", "big", "code", "em",
"font", "i", "s", "small", "strike", "strong", "tt", "u"</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. <a href="parsing.html#push-onto-the-list-of-active-formatting-elements">Push
onto the list of active formatting elements</a> that
element.</p>
</dd>
<dt>A start tag whose tag name is "nobr"</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-scope" title="has an
element in scope">has a <code>nobr</code> element in scope</a>,
then this is a <a href="parsing.html#parse-error">parse error</a>; act as if an end tag with
the tag name "nobr" had been seen, then once again
<a href="parsing.html#reconstruct-the-active-formatting-elements">reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. <a href="parsing.html#push-onto-the-list-of-active-formatting-elements">Push
onto the list of active formatting elements</a> that
element.</p>
</dd>
<dt id="adoptionAgency">An end tag whose tag name is one of: "a",
"b", "big", "code", "em", "font", "i", "nobr", "s", "small",
"strike", "strong", "tt", "u"</dt>
<dd>
<p>Run these steps:</p>
<ol><li><p>Let <var title="">outer loop counter</var> be
zero.</p></li>
<li><p><i>Outer loop</i>: If <var title="">outer loop
counter</var> is greater than or equal to eight, then abort these
steps.</p></li>
<li><p>Increment <var title="">outer loop counter</var> by
one.</p></li>
<li>
<p>Let the <var title="">formatting element</var> be the last
element in the <a href="parsing.html#list-of-active-formatting-elements">list of active formatting elements</a>
that:</p>
<ul><li>is between the end of the list and the last scope
marker in the list, if any, or the start of the list
otherwise, and</li>
<li>has the same tag name as the token.</li>
</ul><p>If there is no such node, then abort these steps and instead
act as described in the "any other end tag" entry below.</p>
<p>Otherwise, if there is such a node, but that node is not
in the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>, then this is a
<a href="parsing.html#parse-error">parse error</a>; remove the element from the list,
and abort these steps.</p>
<p>Otherwise, if there is such a node, and that node is also in
the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>, but the element is not
<a href="parsing.html#has-an-element-in-scope" title="has an element in scope">in scope</a>, then this
is a <a href="parsing.html#parse-error">parse error</a>; ignore the token, and abort these
steps.</p>
<p>Otherwise, there is a <var title="">formatting
element</var> and that element is in <a href="parsing.html#stack-of-open-elements" title="stack of
open elements">the stack</a> and is <a href="parsing.html#has-an-element-in-scope" title="has an
element in scope">in scope</a>. If the element is not the
<a href="parsing.html#current-node">current node</a>, this is a <a href="parsing.html#parse-error">parse
error</a>. In any case, proceed with the algorithm as
written in the following steps.</p>
</li>
<li><p>Let the <var title="">furthest block</var> be the topmost
node in the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> that is lower in
the stack than the <var title="">formatting element</var>, and is
an element in the <a href="parsing.html#special">special</a> category. There might not
be one.</p></li>
<li><p>If there is no <var title="">furthest block</var>,
then the UA must skip the subsequent steps and instead just
pop all the nodes from the bottom of the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>, from the <a href="parsing.html#current-node">current node</a> up to and
including the <var title="">formatting element</var>, and
remove the <var title="">formatting element</var> from the
<a href="parsing.html#list-of-active-formatting-elements">list of active formatting elements</a>.</p></li>
<li><p>Let the <var title="">common ancestor</var> be the element
immediately above the <var title="">formatting element</var> in the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>.</p></li>
<li><p>Let a bookmark note the position of the <var title="">formatting element</var> in the <a href="parsing.html#list-of-active-formatting-elements">list of active
formatting elements</a> relative to the elements on either
side of it in the list.</p></li>
<li>
<p>Let <var title="">node</var> and <var title="">last node</var> be the
<var title="">furthest block</var>. Follow these steps:</p>
<ol><li><p>Let <var title="">inner loop counter</var> be
zero.</p></li>
<li><p><i>Inner loop</i>: If <var title="">inner loop
counter</var> is greater than or equal to three, then abort these
steps.</p></li>
<li><p>Increment <var title="">inner loop counter</var> by
one.</p></li>
<li>Let <var title="">node</var> be the element immediately
above <var title="">node</var> in the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>, or if <var title="">node</var> is no longer in
the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> (e.g. because it got
removed by the next step), the element that was immediately
above <var title="">node</var> in the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> before <var title="">node</var> was
removed.</li>
<li>If <var title="">node</var> is not in the <a href="parsing.html#list-of-active-formatting-elements">list of
active formatting elements</a>, then remove <var title="">node</var> from the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> and then go back to the step labeled <i>inner
loop</i>.</li>
<li>Otherwise, if <var title="">node</var> is the <var title="">formatting element</var>, then go to the next step
in the overall algorithm.</li>
<li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
element <var title="">node</var> was created, replace the entry
for <var title="">node</var> in the <a href="parsing.html#list-of-active-formatting-elements">list of active
formatting elements</a> with an entry for the new element,
replace the entry for <var title="">node</var> in the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a> with an entry for the new
element, and let <var title="">node</var> be the new
element.</li>
<li>If <var title="">last node</var> is the <var title="">furthest block</var>, then move the aforementioned
bookmark to be immediately after the new <var title="">node</var> in the <a href="parsing.html#list-of-active-formatting-elements">list of active formatting
elements</a>.</li>
<li>Insert <var title="">last node</var> into <var title="">node</var>, first removing it from its previous
parent node if any.</li>
<li>Let <var title="">last node</var> be <var title="">node</var>.</li>
<li>Return to the step labeled <i>inner loop</i>.</li>
</ol></li>
<li>
<p>If the <var title="">common ancestor</var> node is a
<code><a href="tabular-data.html#the-table-element">table</a></code>, <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>, <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>,
<code><a href="tabular-data.html#the-thead-element">thead</a></code>, or <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then,
<a href="#foster-parent">foster parent</a> whatever <var title="">last
node</var> ended up being in the previous step, first removing
it from its previous parent node if any.</p>
<p>Otherwise, append whatever <var title="">last node</var>
ended up being in the previous step to the <var title="">common
ancestor</var> node, first removing it from its previous parent
node if any.</p>
</li>
<li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
<var title="">formatting element</var> was created.</p></li>
<li><p>Take all of the child nodes of the <var title="">furthest
block</var> and append them to the element created in the last
step.</p></li>
<li><p>Append that new element to the <var title="">furthest
block</var>.</p></li>
<li><p>Remove the <var title="">formatting element</var> from the
<a href="parsing.html#list-of-active-formatting-elements">list of active formatting elements</a>, and insert the
new element into the <a href="parsing.html#list-of-active-formatting-elements">list of active formatting
elements</a> at the position of the aforementioned
bookmark.</p></li>
<li><p>Remove the <var title="">formatting element</var> from the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>, and insert the new element
into the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> immediately below
the position of the <var title="">furthest block</var> in that
stack.</p></li>
<li><p>Jump back to the step labeled <i>outer loop</i>.</p></li>
</ol><p class="note">Because of the way this algorithm causes elements
to change parents, it has been dubbed the "adoption agency
algorithm" (in contrast with other possible algorithms for dealing
with misnested content, which included the "incest algorithm", the
"secret affair algorithm", and the "Heisenberg algorithm").</p>
</dd>
<dt>A start tag token whose tag name is one of: "applet",
"marquee", "object"</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>Insert a marker at the end of the <a href="parsing.html#list-of-active-formatting-elements">list of active
formatting elements</a>.</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
</dd>
<dt>An end tag token whose tag name is one of: "applet",
"marquee", "object"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-scope" title="has an element in scope">have an element in scope</a>
with the same tag name as that of the token, then this is a
<a href="parsing.html#parse-error">parse error</a>; ignore the token.</p>
<p>Otherwise, run these steps:</p>
<ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
<li><p>If the <a href="parsing.html#current-node">current node</a> is not an element with
the same tag name as that of the token, then this is a
<a href="parsing.html#parse-error">parse error</a>.</p></li>
<li><p>Pop elements from the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>
until an element with the same tag name as the token has been
popped from the stack.</p></li>
<li><a href="parsing.html#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to the
last marker</a>.</li>
</ol></dd>
<dt>A start tag whose tag name is "table"</dt>
<dd>
<p>If the <code><a href="infrastructure.html#document">Document</a></code> is <em>not</em> set to
<a href="dom.html#quirks-mode">quirks mode</a>, and the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> <a href="parsing.html#has-an-element-in-button-scope" title="has an element in button scope">has a
<code>p</code> element in button scope</a>, then act as if an
end tag with the tag name "p" had been seen.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
</dd>
<dt>A start tag whose tag name is one of: "area", "br", "embed",
"img", "keygen", "wbr"</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p><a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
token's <i>self-closing flag</i></a>, if it is set.</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
</dd>
<dt>A start tag whose tag name is "input"</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p><a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
token's <i>self-closing flag</i></a>, if it is set.</p>
<p>If the token does not have an attribute with the name "type",
or if it does, but that attribute's value is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
case-insensitive</a> match for the string "<code title="">hidden</code>", then: set the <a href="parsing.html#frameset-ok-flag">frameset-ok
flag</a> to "not ok".</p>
</dd>
<dt>A start tag whose tag name is one of: "param", "source", "track"</dt>
<dd>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p><a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
token's <i>self-closing flag</i></a>, if it is set.</p>
</dd>
<dt>A start tag whose tag name is "hr"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-button-scope" title="has
an element in button scope">has a <code>p</code> element in button
scope</a>, then act as if an end tag with the tag name
"p" had been seen.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p><a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
token's <i>self-closing flag</i></a>, if it is set.</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
</dd>
<dt>A start tag whose tag name is "image"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Change the token's tag name
to "img" and reprocess it. (Don't ask.)</p> </dd>
<dt id="isindex">A start tag whose tag name is "isindex"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>.</p>
<p>If the <a href="parsing.html#form-element-pointer"><code title="">form</code> element
pointer</a> is not null, then ignore the token.</p>
<p>Otherwise:</p>
<p><a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
token's <i>self-closing flag</i></a>, if it is set.</p>
<p>Act as if a start tag token with the tag name "form" had been seen.</p>
<p>If the token has an attribute called "action", set the
<code title="attr-fs-action"><a href="association-of-controls-and-forms.html#attr-fs-action">action</a></code> attribute on the
resulting <code><a href="forms.html#the-form-element">form</a></code> element to the value of the
"action" attribute of the token.</p>
<p>Act as if a start tag token with the tag name "hr" had been
seen.</p>
<p>Act as if a start tag token with the tag name "label" had been
seen.</p>
<p>Act as if a stream of character tokens had been seen (see below
for what they should say).</p>
<p>Act as if a start tag token with the tag name "input" had been
seen, with all the attributes from the "isindex" token except
"name", "action", and "prompt". Set the <code title="attr-fe-name"><a href="association-of-controls-and-forms.html#attr-fe-name">name</a></code> attribute of the resulting
<code><a href="the-input-element.html#the-input-element">input</a></code> element to the value "<code title="attr-fe-name-isindex"><a href="association-of-controls-and-forms.html#attr-fe-name-isindex">isindex</a></code>".</p>
<p>Act as if a stream of character tokens had been seen (see
below for what they should say).</p>
<p>Act as if an end tag token with the tag name "label" had been
seen.</p>
<p>Act as if a start tag token with the tag name "hr" had been
seen.</p>
<p>Act as if an end tag token with the tag name "form" had been
seen.</p>
<p>If the token has an attribute with the name "prompt", then the
first stream of characters must be the same string as given in
that attribute, and the second stream of characters must be
empty. Otherwise, the two streams of character tokens together
should, together with the <code><a href="the-input-element.html#the-input-element">input</a></code> element, express the
equivalent of "This is a searchable index. Enter search keywords:
(input field)" in the user's preferred language.</p>
</dd>
<dt>A start tag whose tag name is "textarea"</dt>
<dd>
<p>Run these steps:</p>
<ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
token.</p></li>
<li><p>If the next token is a U+000A LINE FEED (LF) character
token, then ignore that token and move on to the next
one. (Newlines at the start of <code><a href="the-button-element.html#the-textarea-element">textarea</a></code> elements are
ignored as an authoring convenience.)</p></li>
<li><p>Switch the tokenizer to the <a href="tokenization.html#rcdata-state">RCDATA
state</a>.</p></li>
<li><p>Let the <a href="parsing.html#original-insertion-mode">original insertion mode</a> be the
current <a href="parsing.html#insertion-mode">insertion mode</a>.</p>
</li><li><p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not
ok".</p></li>
<li><p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: text">text</a>".</p></li>
</ol></dd>
<dt>A start tag whose tag name is "xmp"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-button-scope" title="has
an element in button scope">has a <code>p</code> element in button
scope</a>, then act as if an end tag with the tag name
"p" had been seen.</p>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
<p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
</dd>
<dt>A start tag whose tag name is "iframe"</dt>
<dd>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
<p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
</dd>
<dt>A start tag whose tag name is "noembed"</dt>
<dt>A start tag whose tag name is "noscript", if the <a href="parsing.html#scripting-flag">scripting flag</a> is enabled</dt>
<dd>
<p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
</dd>
<dt>A start tag whose tag name is "select"</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
<p>If the <a href="parsing.html#insertion-mode">insertion mode</a> is one of "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>", "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>", "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table body</a>",
"<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>", or "<a href="#parsing-main-intd" title="insertion mode: in cell">in cell</a>", then switch the
<a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inselectintable" title="insertion mode: in
select in table">in select in table</a>". Otherwise, switch the
<a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inselect" title="insertion mode: in
select">in select</a>".</p>
</dd>
<dt>A start tag whose tag name is one of: "optgroup", "option"</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is an <code><a href="the-button-element.html#the-option-element">option</a></code>
element, then act as if an end tag with the tag name "option" had
been seen.</p>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
</dd>
<dt>A start tag whose tag name is one of: "rp", "rt"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-scope" title="has an
element in scope">has a <code>ruby</code> element in scope</a>,
then <a href="#generate-implied-end-tags">generate implied end tags</a>. If the <a href="parsing.html#current-node">current
node</a> is not then a <code><a href="text-level-semantics.html#the-ruby-element">ruby</a></code> element, this is a
<a href="parsing.html#parse-error">parse error</a>; pop all the nodes from the <a href="parsing.html#current-node">current
node</a> up to the node immediately before the bottommost
<code><a href="text-level-semantics.html#the-ruby-element">ruby</a></code> element on the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
</dd>
<dt>An end tag whose tag name is "br"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Act as if a start tag token with
the tag name "br" had been seen. Ignore the end tag token.</p>
</dd>
<dt>A start tag whose tag name is "math"</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#adjust-mathml-attributes">Adjust MathML attributes</a> for the token. (This
fixes the case of MathML attributes that are not all
lowercase.)</p>
<p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
fixes the use of namespaced attributes, in particular XLink.)</p>
<p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
<a href="namespaces.html#mathml-namespace">MathML namespace</a>.</p>
<p>If the token has its <i>self-closing flag</i> set, pop the
<a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> and <a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing
flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
</dd>
<dt>A start tag whose tag name is "svg"</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#adjust-svg-attributes">Adjust SVG attributes</a> for the token. (This fixes
the case of SVG attributes that are not all lowercase.)</p>
<p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
fixes the use of namespaced attributes, in particular XLink in
SVG.)</p>
<p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
<a href="namespaces.html#svg-namespace">SVG namespace</a>.</p>
<p>If the token has its <i>self-closing flag</i> set, pop the
<a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> and <a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing
flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
</dd>
<dt>A start tag whose tag name is one of: "caption",
"col", "colgroup", "frame", "head", "tbody", "td", "tfoot", "th",
"thead", "tr"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Any other start tag</dt>
<dd>
<p><a href="parsing.html#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
any.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p class="note">This element will be an <a href="parsing.html#ordinary">ordinary</a>
element.</p>
</dd>
<dt>Any other end tag</dt>
<dd>
<p>Run these steps:</p>
<ol><li><p>Initialize <var title="">node</var> to be the <a href="parsing.html#current-node">current
node</a> (the bottommost node of the stack).</p></li>
<li><p><i>Loop</i>: If <var title="">node</var> has the same tag
name as the token, then:</p>
<ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
for elements with the same tag name as the token.</p></li>
<li><p>If the tag name of the end tag token does not match
the tag name of the <a href="parsing.html#current-node">current node</a>, this is a
<a href="parsing.html#parse-error">parse error</a>.</p></li>
<li><p>Pop all the nodes from the <a href="parsing.html#current-node">current node</a> up
to <var title="">node</var>, including <var title="">node</var>, then stop these steps.</p></li>
</ol></li>
<li><p>Otherwise, if <var title="">node</var> is in the
<a href="parsing.html#special">special</a> category, then this is a <a href="parsing.html#parse-error">parse
error</a>; ignore the token, and abort these steps.</p></li>
<li><p>Set <var title="">node</var> to the previous entry in the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>.</p></li>
<li><p>Return to the step labeled <i>loop</i>.</p></li>
</ol></dd>
</dl><h6 id="parsing-main-incdata"><span class="secno">8.2.5.4.8 </span>The "<dfn title="insertion mode: text">text</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-incdata" title="insertion mode: text">text</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token</dt>
<dd>
<p><a href="#insert-a-character" title="insert a character">Insert the token's
character</a> into the <a href="parsing.html#current-node">current node</a>.</p>
<p class="note">This can never be a U+0000 NULL character; the
tokenizer converts those to U+FFFD REPLACEMENT CHARACTER
characters.</p>
</dd>
<dt>An end-of-file token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>.</p>
<p>If the <a href="parsing.html#current-node">current node</a> is a <code><a href="scripting-1.html#the-script-element">script</a></code>
element, mark the <code><a href="scripting-1.html#the-script-element">script</a></code> element as <a href="scripting-1.html#already-started">"already
started"</a>.</p>
<p>Pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to the <a href="parsing.html#original-insertion-mode">original
insertion mode</a> and reprocess the current token.</p>
</dd>
<dt id="scriptEndTag">An end tag whose tag name is "script"</dt>
<dd>
<p><a href="webappapis.html#provide-a-stable-state">Provide a stable state</a>.</p>
<p>Let <var title="">script</var> be the <a href="parsing.html#current-node">current node</a>
(which will be a <code><a href="scripting-1.html#the-script-element">script</a></code> element).</p>
<p>Pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to the <a href="parsing.html#original-insertion-mode">original
insertion mode</a>.</p>
<p>Let the <var title="">old insertion point</var> have the
same value as the current <a href="parsing.html#insertion-point">insertion point</a>. Let
the <a href="parsing.html#insertion-point">insertion point</a> be just before the <a href="parsing.html#next-input-character">next
input character</a>.</p>
<p>Increment the parser's <a href="parsing.html#script-nesting-level">script nesting level</a> by
one.</p>
<p><a href="scripting-1.html#prepare-a-script" title="prepare a script">Prepare</a> the <var title="">script</var>. This might cause some script to execute,
which might cause <a href="apis-in-html-documents.html#dom-document-write" title="dom-document-write">new characters
to be inserted into the tokenizer</a>, and might cause the
tokenizer to output more tokens, resulting in a <a href="parsing.html#nestedParsing">reentrant invocation of the parser</a>.</p>
<p>Decrement the parser's <a href="parsing.html#script-nesting-level">script nesting level</a> by
one. If the parser's <a href="parsing.html#script-nesting-level">script nesting level</a> is zero,
then set the <a href="parsing.html#parser-pause-flag">parser pause flag</a> to false.</p>
<p>Let the <a href="parsing.html#insertion-point">insertion point</a> have the value of the <var title="">old insertion point</var>. (In other words, restore the
<a href="parsing.html#insertion-point">insertion point</a> to its previous value. This value
might be the "undefined" value.)</p>
<p id="scriptTagParserResumes">At this stage, if there is a
<a href="scripting-1.html#pending-parsing-blocking-script">pending parsing-blocking script</a>, then:</p>
<dl class="switch"><dt>If the <a href="parsing.html#script-nesting-level">script nesting level</a> is not zero:</dt>
<dd>
<p>Set the <a href="parsing.html#parser-pause-flag">parser pause flag</a> to true, and abort the
processing of any nested invocations of the tokenizer, yielding
control back to the caller. (Tokenization will resume when the
caller returns to the "outer" tree construction stage.)</p>
<p class="note">The tree construction stage of this particular
parser is <a href="parsing.html#nestedParsing">being called reentrantly</a>,
say from a call to <code title="dom-document-write"><a href="apis-in-html-documents.html#dom-document-write">document.write()</a></code>.</p>
</dd>
<dt>Otherwise:</dt>
<dd>
<p>Run these steps:</p>
<ol><li><p>Let <var title="">the script</var> be the <a href="scripting-1.html#pending-parsing-blocking-script">pending
parsing-blocking script</a>. There is no longer a <a href="scripting-1.html#pending-parsing-blocking-script">pending
parsing-blocking script</a>.</p></li>
<li><p>Block the <a href="tokenization.html#tokenization" title="tokenization">tokenizer</a>
for this instance of the <a href="parsing.html#html-parser">HTML parser</a>, such that
the <a href="webappapis.html#event-loop">event loop</a> will not run <a href="webappapis.html#concept-task" title="concept-task">tasks</a> that invoke the <a href="tokenization.html#tokenization" title="tokenization">tokenizer</a>.</p></li>
<li><p>If the parser's <code><a href="infrastructure.html#document">Document</a></code> <a href="semantics.html#has-a-style-sheet-that-is-blocking-scripts">has a style
sheet that is blocking scripts</a> or <var title="">the
script</var>'s <a href="scripting-1.html#ready-to-be-parser-executed">"ready to be parser-executed"</a> flag
is not set: <a href="webappapis.html#spin-the-event-loop">spin the event loop</a> until the parser's
<code><a href="infrastructure.html#document">Document</a></code> <a href="semantics.html#has-no-style-sheet-that-is-blocking-scripts">has no style sheet that is blocking
scripts</a> and <var title="">the script</var>'s
<a href="scripting-1.html#ready-to-be-parser-executed">"ready to be parser-executed"</a> flag is
set.</p></li>
<li><p>Unblock the <a href="tokenization.html#tokenization" title="tokenization">tokenizer</a>
for this instance of the <a href="parsing.html#html-parser">HTML parser</a>, such that
<a href="webappapis.html#concept-task" title="concept-task">tasks</a> that invoke the <a href="tokenization.html#tokenization" title="tokenization">tokenizer</a> can again be
run.</p></li>
<li><p>Let the <a href="parsing.html#insertion-point">insertion point</a> be just before the
<a href="parsing.html#next-input-character">next input character</a>.</p></li>
<li><p>Increment the parser's <a href="parsing.html#script-nesting-level">script nesting level</a>
by one (it should be zero before this step, so this sets it to
one).</p></li>
<li><p><a href="scripting-1.html#execute-the-script-block" title="execute the script block">Execute</a>
<var title="">the script</var>.</p></li>
<li><p>Decrement the parser's <a href="parsing.html#script-nesting-level">script nesting level</a>
by one. If the parser's <a href="parsing.html#script-nesting-level">script nesting level</a> is
zero (which it always should be at this point), then set the
<a href="parsing.html#parser-pause-flag">parser pause flag</a> to false.</p>
</li><li><p>Let the <a href="parsing.html#insertion-point">insertion point</a> be undefined
again.</p></li>
<li><p>If there is once again a <a href="scripting-1.html#pending-parsing-blocking-script">pending parsing-blocking
script</a>, then repeat these steps from step 1.</p></li>
</ol></dd>
</dl></dd>
<dt>Any other end tag</dt>
<dd>
<p>Pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to the <a href="parsing.html#original-insertion-mode">original
insertion mode</a>.</p>
</dd>
</dl><h6 id="parsing-main-intable"><span class="secno">8.2.5.4.9 </span>The "<dfn title="insertion mode: in table">in table</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token</dt>
<dd>
<p>Let the <dfn id="pending-table-character-tokens"><var>pending table character tokens</var></dfn>
be an empty list of tokens.</p>
<p>Let the <a href="parsing.html#original-insertion-mode">original insertion mode</a> be the current
<a href="parsing.html#insertion-mode">insertion mode</a>.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table text</a>" and
reprocess the token.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <a href="parsing.html#current-node">current
node</a> with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "caption"</dt>
<dd>
<p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
below.)</p>
<p>Insert a marker at the end of the <a href="parsing.html#list-of-active-formatting-elements">list of active
formatting elements</a>.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>".</p>
</dd>
<dt>A start tag whose tag name is "colgroup"</dt>
<dd>
<p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
below.)</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column
group</a>".</p>
</dd>
<dt>A start tag whose tag name is "col"</dt>
<dd>
<p>Act as if a start tag token with the tag name "colgroup"
had been seen, then reprocess the current token.</p>
</dd>
<dt>A start tag whose tag name is one of: "tbody", "tfoot", "thead"</dt>
<dd>
<p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
below.)</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
body</a>".</p>
</dd>
<dt>A start tag whose tag name is one of: "td", "th", "tr"</dt>
<dd>
<p>Act as if a start tag token with the tag name "tbody" had
been seen, then reprocess the current token.</p>
</dd>
<dt>A start tag whose tag name is "table"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Act as if an end tag token with
the tag name "table" had been seen, then, if that token wasn't
ignored, reprocess the current token.</p>
<p class="note">The fake end tag token here can only be
ignored in the <a href="the-end.html#fragment-case">fragment case</a>.</p>
</dd>
<dt>An end tag whose tag name is "table"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
scope</a> with the same tag name as the token, this is a
<a href="parsing.html#parse-error">parse error</a>. Ignore the token. (<a href="the-end.html#fragment-case">fragment
case</a>)</p>
<p>Otherwise:</p>
<p>Pop elements from this stack until a <code><a href="tabular-data.html#the-table-element">table</a></code>
element has been popped from the stack.</p>
<p><a href="parsing.html#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
</dd>
<dt>An end tag whose tag name is one of: "body", "caption",
"col", "colgroup", "html", "tbody", "td", "tfoot", "th",
"thead", "tr"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is one of: "style", "script"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>A start tag whose tag name is "input"</dt>
<dd>
<p>If the token does not have an attribute with the name "type",
or if it does, but that attribute's value is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
case-insensitive</a> match for the string "<code title="">hidden</code>", then: act as described in the "anything
else" entry below.</p>
<p>Otherwise:</p>
<p><a href="parsing.html#parse-error">Parse error</a>.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
<p>Pop that <code><a href="the-input-element.html#the-input-element">input</a></code> element off the <a href="parsing.html#stack-of-open-elements">stack of
open elements</a>.</p>
</dd>
<dt>A start tag whose tag name is "form"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>.</p>
<p>If the <a href="parsing.html#form-element-pointer"><code title="form">form</code> element
pointer</a> is not null, ignore the token.</p>
<p>Otherwise:</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, and set the
<a href="parsing.html#form-element-pointer"><code title="form">form</code> element pointer</a> to
point to the element created.</p>
<p>Pop that <code><a href="forms.html#the-form-element">form</a></code> element off the <a href="parsing.html#stack-of-open-elements">stack of
open elements</a>.</p>
</dd>
<dt>An end-of-file token</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is not the root
<code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="parsing.html#parse-error">parse
error</a>.</p>
<p class="note">It can only be the <a href="parsing.html#current-node">current node</a> in
the <a href="the-end.html#fragment-case">fragment case</a>.</p>
<p><a href="the-end.html#stop-parsing">Stop parsing</a>.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Process the token <a href="parsing.html#using-the-rules-for">using the
rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
body</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, except that if the
<a href="parsing.html#current-node">current node</a> is a <code><a href="tabular-data.html#the-table-element">table</a></code>,
<code><a href="tabular-data.html#the-tbody-element">tbody</a></code>, <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>, <code><a href="tabular-data.html#the-thead-element">thead</a></code>, or
<code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then, whenever a node would be inserted
into the <a href="parsing.html#current-node">current node</a>, it must instead be <a href="#foster-parent" title="foster parent">foster parented</a>.</p>
</dd>
</dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-context">clear the stack
back to a table context</dfn>, it means that the UA must, while
the <a href="parsing.html#current-node">current node</a> is not a <code><a href="tabular-data.html#the-table-element">table</a></code>
element or an <code><a href="semantics.html#the-html-element">html</a></code> element, pop elements from the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>.</p>
<p class="note">The <a href="parsing.html#current-node">current node</a> being an
<code><a href="semantics.html#the-html-element">html</a></code> element after this process is a <a href="the-end.html#fragment-case">fragment
case</a>.</p>
<h6 id="parsing-main-intabletext"><span class="secno">8.2.5.4.10 </span>The "<dfn title="insertion mode: in table text">in table text</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table text</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is U+0000 NULL</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Any other character token</dt>
<dd>
<p>Append the character token to the <var><a href="#pending-table-character-tokens">pending table character
tokens</a></var> list.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>If any of the tokens in the <var><a href="#pending-table-character-tokens">pending table character
tokens</a></var> list are character tokens that are not one of U+0009
CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED
(FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE, then reprocess
those character tokens using the rules given in the "anything
else" entry in the <a href="#parsing-main-intable" title="insertion mode: in table">in
table</a>" insertion mode.</p>
<p>Otherwise, <a href="#insert-a-character" title="insert a character">insert the
characters</a> given by the <var><a href="#pending-table-character-tokens">pending table character
tokens</a></var> list into the <a href="parsing.html#current-node">current node</a>.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to the <a href="parsing.html#original-insertion-mode">original
insertion mode</a> and reprocess the token.</p>
</dd>
</dl><h6 id="parsing-main-incaption"><span class="secno">8.2.5.4.11 </span>The "<dfn title="insertion mode: in caption">in caption</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>An end tag whose tag name is "caption"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
scope</a> with the same tag name as the token, this is a
<a href="parsing.html#parse-error">parse error</a>. Ignore the token. (<a href="the-end.html#fragment-case">fragment
case</a>)</p>
<p>Otherwise:</p>
<p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
<p>Now, if the <a href="parsing.html#current-node">current node</a> is not a
<code><a href="tabular-data.html#the-caption-element">caption</a></code> element, then this is a <a href="parsing.html#parse-error">parse
error</a>.</p>
<p>Pop elements from this stack until a <code><a href="tabular-data.html#the-caption-element">caption</a></code>
element has been popped from the stack.</p>
<p><a href="parsing.html#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
the last marker</a>.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
</dd>
<dt>A start tag whose tag name is one of: "caption", "col",
"colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
<dt>An end tag whose tag name is "table"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Act as if an end tag with the tag
name "caption" had been seen, then, if that token wasn't
ignored, reprocess the current token.</p>
<p class="note">The fake end tag token here can only be
ignored in the <a href="the-end.html#fragment-case">fragment case</a>.</p>
</dd>
<dt>An end tag whose tag name is one of: "body", "col",
"colgroup", "html", "tbody", "td", "tfoot", "th", "thead",
"tr"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
</dl><h6 id="parsing-main-incolgroup"><span class="secno">8.2.5.4.12 </span>The "<dfn title="insertion mode: in column group">in column group</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column group</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
the <a href="parsing.html#current-node">current node</a>.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <a href="parsing.html#current-node">current
node</a> with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>A start tag whose tag name is "col"</dt>
<dd>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p><a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
token's <i>self-closing flag</i></a>, if it is set.</p>
</dd>
<dt>An end tag whose tag name is "colgroup"</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is the root
<code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="parsing.html#parse-error">parse
error</a>; ignore the token. (<a href="the-end.html#fragment-case">fragment
case</a>)</p>
<p>Otherwise, pop the <a href="parsing.html#current-node">current node</a> (which will be
a <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element) from the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>. Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to
"<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
</dd>
<dt>An end tag whose tag name is "col"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>An end-of-file token</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is the root <code><a href="semantics.html#the-html-element">html</a></code>
element, then <a href="the-end.html#stop-parsing">stop parsing</a>. (<a href="the-end.html#fragment-case">fragment
case</a>)</p>
<p>Otherwise, act as described in the "anything else" entry
below.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>Act as if an end tag with the tag name "colgroup" had been
seen, and then, if that token wasn't ignored, reprocess the
current token.</p>
<p class="note">The fake end tag token here can only be
ignored in the <a href="the-end.html#fragment-case">fragment case</a>.</p>
</dd>
</dl><h6 id="parsing-main-intbody"><span class="secno">8.2.5.4.13 </span>The "<dfn title="insertion mode: in table body">in table body</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table body</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A start tag whose tag name is "tr"</dt>
<dd>
<p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
context</a>. (See below.)</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion mode:
in row">in row</a>".</p>
</dd>
<dt>A start tag whose tag name is one of: "th", "td"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Act as if a start tag with
the tag name "tr" had been seen, then reprocess the current
token.</p>
</dd>
<dt>An end tag whose tag name is one of: "tbody", "tfoot",
"thead"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
scope</a> with the same tag name as the token, this is a
<a href="parsing.html#parse-error">parse error</a>. Ignore the token.</p>
<p>Otherwise:</p>
<p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
context</a>. (See below.)</p>
<p>Pop the <a href="parsing.html#current-node">current node</a> from the <a href="parsing.html#stack-of-open-elements">stack of
open elements</a>. Switch the <a href="parsing.html#insertion-mode">insertion mode</a>
to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
</dd>
<dt>A start tag whose tag name is one of: "caption", "col",
"colgroup", "tbody", "tfoot", "thead"</dt>
<dt>An end tag whose tag name is "table"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">have a
<code>tbody</code>, <code>thead</code>, or <code>tfoot</code>
element in table scope</a>, this is a <a href="parsing.html#parse-error">parse
error</a>. Ignore the token. (<a href="the-end.html#fragment-case">fragment
case</a>)</p>
<p>Otherwise:</p>
<p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
context</a>. (See below.)</p>
<p>Act as if an end tag with the same tag name as the
<a href="parsing.html#current-node">current node</a> ("tbody", "tfoot", or "thead") had
been seen, then reprocess the current token.</p>
</dd>
<dt>An end tag whose tag name is one of: "body", "caption",
"col", "colgroup", "html", "td", "th", "tr"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
</dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-body-context">clear the stack
back to a table body context</dfn>, it means that the UA must,
while the <a href="parsing.html#current-node">current node</a> is not a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
<code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>, <code><a href="tabular-data.html#the-thead-element">thead</a></code>, or <code><a href="semantics.html#the-html-element">html</a></code>
element, pop elements from the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p class="note">The <a href="parsing.html#current-node">current node</a> being an
<code><a href="semantics.html#the-html-element">html</a></code> element after this process is a <a href="the-end.html#fragment-case">fragment
case</a>.</p>
<h6 id="parsing-main-intr"><span class="secno">8.2.5.4.14 </span>The "<dfn title="insertion mode: in row">in row</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A start tag whose tag name is one of: "th", "td"</dt>
<dd>
<p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
context</a>. (See below.)</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion mode:
in cell">in cell</a>".</p>
<p>Insert a marker at the end of the <a href="parsing.html#list-of-active-formatting-elements">list of active
formatting elements</a>.</p>
</dd>
<dt>An end tag whose tag name is "tr"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
scope</a> with the same tag name as the token, this is a
<a href="parsing.html#parse-error">parse error</a>. Ignore the token. (<a href="the-end.html#fragment-case">fragment
case</a>)</p>
<p>Otherwise:</p>
<p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
context</a>. (See below.)</p>
<p>Pop the <a href="parsing.html#current-node">current node</a> (which will be a
<code><a href="tabular-data.html#the-tr-element">tr</a></code> element) from the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>. Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to
"<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
body</a>".</p>
</dd>
<dt>A start tag whose tag name is one of: "caption", "col",
"colgroup", "tbody", "tfoot", "thead", "tr"</dt>
<dt>An end tag whose tag name is "table"</dt>
<dd>
<p>Act as if an end tag with the tag name "tr" had been seen,
then, if that token wasn't ignored, reprocess the current
token.</p>
<p class="note">The fake end tag token here can only be
ignored in the <a href="the-end.html#fragment-case">fragment case</a>.</p>
</dd>
<dt>An end tag whose tag name is one of: "tbody", "tfoot",
"thead"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
scope</a> with the same tag name as the token, this is a
<a href="parsing.html#parse-error">parse error</a>. Ignore the token.</p>
<p>Otherwise, act as if an end tag with the tag name "tr" had
been seen, then reprocess the current token.</p>
</dd>
<dt>An end tag whose tag name is one of: "body", "caption",
"col", "colgroup", "html", "td", "th"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
</dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-row-context">clear the stack
back to a table row context</dfn>, it means that the UA must,
while the <a href="parsing.html#current-node">current node</a> is not a <code><a href="tabular-data.html#the-tr-element">tr</a></code>
element or an <code><a href="semantics.html#the-html-element">html</a></code> element, pop elements from the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>.</p>
<p class="note">The <a href="parsing.html#current-node">current node</a> being an
<code><a href="semantics.html#the-html-element">html</a></code> element after this process is a <a href="the-end.html#fragment-case">fragment
case</a>.</p>
<h6 id="parsing-main-intd"><span class="secno">8.2.5.4.15 </span>The "<dfn title="insertion mode: in cell">in cell</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-intd" title="insertion mode: in cell">in cell</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>An end tag whose tag name is one of: "td", "th"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
scope</a> with the same tag name as that of the token, then
this is a <a href="parsing.html#parse-error">parse error</a> and the token must be
ignored.</p>
<p>Otherwise:</p>
<p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
<p>Now, if the <a href="parsing.html#current-node">current node</a> is not an element
with the same tag name as the token, then this is a
<a href="parsing.html#parse-error">parse error</a>.</p>
<p>Pop elements from the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> stack
until an element with the same tag name as the token has been
popped from the stack.</p>
<p><a href="parsing.html#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
the last marker</a>.</p>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>".</p>
</dd>
<dt>A start tag whose tag name is one of: "caption", "col",
"colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does
<em>not</em> <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">have
a <code>td</code> or <code>th</code> element in table
scope</a>, then this is a <a href="parsing.html#parse-error">parse error</a>; ignore
the token. (<a href="the-end.html#fragment-case">fragment case</a>)</p>
<p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
reprocess the current token.</p>
</dd>
<dt>An end tag whose tag name is one of: "body", "caption",
"col", "colgroup", "html"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>An end tag whose tag name is one of: "table", "tbody",
"tfoot", "thead", "tr"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
scope</a> with the same tag name as that of the token (which
can only happen for "tbody", "tfoot" and "thead", or in the
<a href="the-end.html#fragment-case">fragment case</a>), then this is a <a href="parsing.html#parse-error">parse
error</a> and the token must be ignored.</p>
<p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
reprocess the current token.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
</dl><p>Where the steps above say to <dfn id="close-the-cell">close the cell</dfn>, they
mean to run the following algorithm:</p>
<ol><li><p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">has a <code>td</code>
element in table scope</a>, then act as if an end tag token
with the tag name "td" had been seen.</p></li>
<li><p>Otherwise, the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> will
<a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">have a
<code>th</code> element in table scope</a>; act as if an end
tag token with the tag name "th" had been seen.</p></li>
</ol><p class="note">The <a href="parsing.html#stack-of-open-elements">stack of open elements</a> cannot have
both a <code><a href="tabular-data.html#the-td-element">td</a></code> and a <code><a href="tabular-data.html#the-th-element">th</a></code> element <a href="parsing.html#has-an-element-in-table-scope" title="has an element in table scope">in table scope</a> at the
same time, nor can it have neither when the <a href="#close-the-cell">close the
cell</a> algorithm is invoked.</p>
<h6 id="parsing-main-inselect"><span class="secno">8.2.5.4.16 </span>The "<dfn title="insertion mode: in select">in select</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is U+0000 NULL</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>Any other character token</dt>
<dd>
<p><a href="#insert-a-character" title="insert a character">Insert the token's
character</a> into the <a href="parsing.html#current-node">current node</a>.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <a href="parsing.html#current-node">current
node</a> with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>A start tag whose tag name is "option"</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is an <code><a href="the-button-element.html#the-option-element">option</a></code>
element, act as if an end tag with the tag name "option" had
been seen.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
</dd>
<dt>A start tag whose tag name is "optgroup"</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is an <code><a href="the-button-element.html#the-option-element">option</a></code>
element, act as if an end tag with the tag name "option" had
been seen.</p>
<p>If the <a href="parsing.html#current-node">current node</a> is an
<code><a href="the-button-element.html#the-optgroup-element">optgroup</a></code> element, act as if an end tag with the
tag name "optgroup" had been seen.</p>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
</dd>
<dt>An end tag whose tag name is "optgroup"</dt>
<dd>
<p>First, if the <a href="parsing.html#current-node">current node</a> is an
<code><a href="the-button-element.html#the-option-element">option</a></code> element, and the node immediately before
it in the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> is an
<code><a href="the-button-element.html#the-optgroup-element">optgroup</a></code> element, then act as if an end tag with
the tag name "option" had been seen.</p>
<p>If the <a href="parsing.html#current-node">current node</a> is an
<code><a href="the-button-element.html#the-optgroup-element">optgroup</a></code> element, then pop that node from the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>. Otherwise, this is a
<a href="parsing.html#parse-error">parse error</a>; ignore the token.</p>
</dd>
<dt>An end tag whose tag name is "option"</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is an <code><a href="the-button-element.html#the-option-element">option</a></code>
element, then pop that node from the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>. Otherwise, this is a <a href="parsing.html#parse-error">parse
error</a>; ignore the token.</p>
</dd>
<dt>An end tag whose tag name is "select"</dt>
<dd>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-select-scope" title="has an element in select scope">have an element in select
scope</a> with the same tag name as the token, this is a
<a href="parsing.html#parse-error">parse error</a>. Ignore the token. (<a href="the-end.html#fragment-case">fragment
case</a>)</p>
<p>Otherwise:</p>
<p>Pop elements from the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>
until a <code><a href="the-button-element.html#the-select-element">select</a></code> element has been popped from the
stack.</p>
<p><a href="parsing.html#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
</dd>
<dt>A start tag whose tag name is "select"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Act as if the token had been
an end tag with the tag name "select" instead.</p>
</dd>
<dt>A start tag whose tag name is one of: "input", "keygen", "textarea"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>.</p>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> does not <a href="parsing.html#has-an-element-in-select-scope" title="has an element in select scope">have a <code>select</code>
element in select scope</a>, ignore the token. (<a href="the-end.html#fragment-case">fragment
case</a>)</p>
<p>Otherwise, act as if an end tag with the tag name "select" had
been seen, and reprocess the token.</p>
</dd>
<dt>A start tag token whose tag name is "script"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>An end-of-file token</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is not the root
<code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="parsing.html#parse-error">parse
error</a>.</p>
<p class="note">It can only be the <a href="parsing.html#current-node">current node</a> in
the <a href="the-end.html#fragment-case">fragment case</a>.</p>
<p><a href="the-end.html#stop-parsing">Stop parsing</a>.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
</dl><h6 id="parsing-main-inselectintable"><span class="secno">8.2.5.4.17 </span>The "<dfn title="insertion mode: in select in table">in select in table</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-inselectintable" title="insertion mode: in select in table">in select in table</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A start tag whose tag name is one of: "caption", "table",
"tbody", "tfoot", "thead", "tr", "td", "th"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Act as if an end tag with the tag
name "select" had been seen, and reprocess the token.</p>
</dd>
<dt>An end tag whose tag name is one of: "caption", "table",
"tbody", "tfoot", "thead", "tr", "td", "th"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>.</p>
<p>If the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> <a href="parsing.html#has-an-element-in-table-scope">has an
element in table scope</a> with the same tag name as that
of the token, then act as if an end tag with the tag name
"select" had been seen, and reprocess the token. Otherwise,
ignore the token.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
</dl><h6 id="parsing-main-afterbody"><span class="secno">8.2.5.4.18 </span>The "<dfn title="insertion mode: after body">after body</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-afterbody" title="insertion mode: after body">after body</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the first element in
the <a href="parsing.html#stack-of-open-elements">stack of open elements</a> (the <code><a href="semantics.html#the-html-element">html</a></code>
element), with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>An end tag whose tag name is "html"</dt>
<dd>
<p>If the parser was originally created as part of the <a href="the-end.html#html-fragment-parsing-algorithm">HTML
fragment parsing algorithm</a>, this is a <a href="parsing.html#parse-error">parse
error</a>; ignore the token. (<a href="the-end.html#fragment-case">fragment case</a>)</p>
<p>Otherwise, switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#the-after-after-body-insertion-mode" title="insertion mode: after after body">after after
body</a>".</p>
</dd>
<dt>An end-of-file token</dt>
<dd>
<p><a href="the-end.html#stop-parsing">Stop parsing</a>.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Switch the <a href="parsing.html#insertion-mode">insertion
mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in
body</a>" and reprocess the token.</p>
</dd>
</dl><h6 id="parsing-main-inframeset"><span class="secno">8.2.5.4.19 </span>The "<dfn title="insertion mode: in frameset">in frameset</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-inframeset" title="insertion mode: in frameset">in frameset</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
the <a href="parsing.html#current-node">current node</a>.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <a href="parsing.html#current-node">current
node</a> with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>A start tag whose tag name is "frameset"</dt>
<dd>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
</dd>
<dt>An end tag whose tag name is "frameset"</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is the root
<code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="parsing.html#parse-error">parse
error</a>; ignore the token. (<a href="the-end.html#fragment-case">fragment
case</a>)</p>
<p>Otherwise, pop the <a href="parsing.html#current-node">current node</a> from the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>.</p>
<p>If the parser was <em>not</em> originally created as part
of the <a href="the-end.html#html-fragment-parsing-algorithm">HTML fragment parsing algorithm</a>
(<a href="the-end.html#fragment-case">fragment case</a>), and the <a href="parsing.html#current-node">current
node</a> is no longer a <code><a href="obsolete.html#frameset">frameset</a></code> element, then
switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#parsing-main-afterframeset" title="insertion mode: after frameset">after
frameset</a>".</p>
</dd>
<dt>A start tag whose tag name is "frame"</dt>
<dd>
<p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.
Immediately pop the <a href="parsing.html#current-node">current node</a> off the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>.</p>
<p><a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
token's <i>self-closing flag</i></a>, if it is set.</p>
</dd>
<dt>A start tag whose tag name is "noframes"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>An end-of-file token</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is not the root
<code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="parsing.html#parse-error">parse
error</a>.</p>
<p class="note">It can only be the <a href="parsing.html#current-node">current node</a> in
the <a href="the-end.html#fragment-case">fragment case</a>.</p>
<p><a href="the-end.html#stop-parsing">Stop parsing</a>.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
</dl><h6 id="parsing-main-afterframeset"><span class="secno">8.2.5.4.20 </span>The "<dfn title="insertion mode: after frameset">after frameset</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#parsing-main-afterframeset" title="insertion mode: after frameset">after frameset</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
the <a href="parsing.html#current-node">current node</a>.</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <a href="parsing.html#current-node">current
node</a> with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>An end tag whose tag name is "html"</dt>
<dd>
<p>Switch the <a href="parsing.html#insertion-mode">insertion mode</a> to "<a href="#the-after-after-frameset-insertion-mode" title="insertion mode: after after frameset">after after
frameset</a>".</p>
</dd>
<dt>A start tag whose tag name is "noframes"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>An end-of-file token</dt>
<dd>
<p><a href="the-end.html#stop-parsing">Stop parsing</a>.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
</dl><h6 id="the-after-after-body-insertion-mode"><span class="secno">8.2.5.4.21 </span>The "<dfn title="insertion mode: after after body">after after body</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#the-after-after-body-insertion-mode" title="insertion mode: after after body">after after body</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <code><a href="infrastructure.html#document">Document</a></code>
object with the <code title="">data</code> attribute set to the
data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>An end-of-file token</dt>
<dd>
<p><a href="the-end.html#stop-parsing">Stop parsing</a>.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Switch the <a href="parsing.html#insertion-mode">insertion mode</a>
to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" and
reprocess the token.</p>
</dd>
</dl><h6 id="the-after-after-frameset-insertion-mode"><span class="secno">8.2.5.4.22 </span>The "<dfn title="insertion mode: after after frameset">after after frameset</dfn>" insertion mode</h6>
<p>When the user agent is to apply the rules for the "<a href="#the-after-after-frameset-insertion-mode" title="insertion mode: after after frameset">after after frameset</a>" <a href="parsing.html#insertion-mode">insertion mode</a>, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <code><a href="infrastructure.html#document">Document</a></code>
object with the <code title="">data</code> attribute set to the
data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dt>A character token that is one of U+0009 CHARACTER
TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
U+000D CARRIAGE RETURN (CR), or U+0020 SPACE</dt>
<dt>A start tag whose tag name is "html"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>An end-of-file token</dt>
<dd>
<p><a href="the-end.html#stop-parsing">Stop parsing</a>.</p>
</dd>
<dt>A start tag whose tag name is "noframes"</dt>
<dd>
<p>Process the token <a href="parsing.html#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="parsing.html#insertion-mode">insertion
mode</a>.</p>
</dd>
<dt>Anything else</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
</dl><h5 id="parsing-main-inforeign"><span class="secno">8.2.5.5 </span>The rules for parsing tokens <dfn title="insertion mode: in foreign content">in foreign content</dfn></h5>
<p>When the user agent is to apply the rules for parsing tokens in foreign content, the user agent must handle the token as follows:</p>
<dl class="switch"><dt>A character token that is U+0000 NULL</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. <a href="#insert-a-character" title="insert a
character">Insert a U+FFFD REPLACEMENT CHARACTER character</a>
into the <a href="parsing.html#current-node">current node</a>.</p>
</dd>
<dt>A character token that is one of U+0009 CHARACTER TABULATION,
U+000A LINE FEED (LF), U+000C FORM FEED (FF), U+000D CARRIAGE
RETURN (CR), or U+0020 SPACE</dt>
<dd>
<p><a href="#insert-a-character" title="insert a character">Insert the token's
character</a> into the <a href="parsing.html#current-node">current node</a>.</p>
</dd>
<dt>Any other character token</dt>
<dd>
<p><a href="#insert-a-character" title="insert a character">Insert the token's
character</a> into the <a href="parsing.html#current-node">current node</a>.</p>
<p>Set the <a href="parsing.html#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
</dd>
<dt>A comment token</dt>
<dd>
<p>Append a <code><a href="infrastructure.html#comment-0">Comment</a></code> node to the <a href="parsing.html#current-node">current
node</a> with the <code title="">data</code> attribute set to
the data given in the comment token.</p>
</dd>
<dt>A DOCTYPE token</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>. Ignore the token.</p>
</dd>
<dt>A start tag whose tag name is one of: "b", "big",
"blockquote", "body", "br", "center", "code",
"dd", "div", "dl", "dt", "em", "embed", "h1", "h2",
"h3", "h4", "h5", "h6", "head", "hr", "i", "img",
"li", "listing", "menu", "meta", "nobr",
"ol", "p", "pre", "ruby", "s", "small",
"span", "strong", "strike", "sub", "sup",
"table", "tt", "u", "ul", "var"</dt> <dt>A start tag whose tag name is "font", if the token has any
attributes named "color", "face", or "size"</dt>
<dd>
<p><a href="parsing.html#parse-error">Parse error</a>.</p>
<p>Pop an element from the <a href="parsing.html#stack-of-open-elements">stack of open elements</a>,
and then keep popping more elements from the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> until the <a href="parsing.html#current-node">current node</a> is a
<a href="#mathml-text-integration-point">MathML text integration point</a>, an <a href="#html-integration-point">HTML
integration point</a>, or an element in the <a href="namespaces.html#html-namespace-0">HTML
namespace</a>.</p>
<p>Then, reprocess the token.</p>
</dd>
<dt>Any other start tag</dt>
<dd>
<p>If the <a href="parsing.html#current-node">current node</a> is an element in the
<a href="namespaces.html#mathml-namespace">MathML namespace</a>, <a href="#adjust-mathml-attributes">adjust MathML
attributes</a> for the token. (This fixes the case of MathML
attributes that are not all lowercase.)</p>
<p>If the <a href="parsing.html#current-node">current node</a> is an element in the <a href="namespaces.html#svg-namespace">SVG
namespace</a>, and the token's tag name is one of the ones in
the first column of the following table, change the tag name to
the name given in the corresponding cell in the second
column. (This fixes the case of SVG elements that are not all
lowercase.)</p>
<table><thead><tr><th> Tag name </th><th> Element name
</th></tr></thead><tbody><tr><td> <code title="">altglyph</code> </td><td> <code title="">altGlyph</code>
</td></tr><tr><td> <code title="">altglyphdef</code> </td><td> <code title="">altGlyphDef</code>
</td></tr><tr><td> <code title="">altglyphitem</code> </td><td> <code title="">altGlyphItem</code>
</td></tr><tr><td> <code title="">animatecolor</code> </td><td> <code title="">animateColor</code>
</td></tr><tr><td> <code title="">animatemotion</code> </td><td> <code title="">animateMotion</code>
</td></tr><tr><td> <code title="">animatetransform</code> </td><td> <code title="">animateTransform</code>
</td></tr><tr><td> <code title="">clippath</code> </td><td> <code title="">clipPath</code>
</td></tr><tr><td> <code title="">feblend</code> </td><td> <code title="">feBlend</code>
</td></tr><tr><td> <code title="">fecolormatrix</code> </td><td> <code title="">feColorMatrix</code>
</td></tr><tr><td> <code title="">fecomponenttransfer</code> </td><td> <code title="">feComponentTransfer</code>
</td></tr><tr><td> <code title="">fecomposite</code> </td><td> <code title="">feComposite</code>
</td></tr><tr><td> <code title="">feconvolvematrix</code> </td><td> <code title="">feConvolveMatrix</code>
</td></tr><tr><td> <code title="">fediffuselighting</code> </td><td> <code title="">feDiffuseLighting</code>
</td></tr><tr><td> <code title="">fedisplacementmap</code> </td><td> <code title="">feDisplacementMap</code>
</td></tr><tr><td> <code title="">fedistantlight</code> </td><td> <code title="">feDistantLight</code>
</td></tr><tr><td> <code title="">feflood</code> </td><td> <code title="">feFlood</code>
</td></tr><tr><td> <code title="">fefunca</code> </td><td> <code title="">feFuncA</code>
</td></tr><tr><td> <code title="">fefuncb</code> </td><td> <code title="">feFuncB</code>
</td></tr><tr><td> <code title="">fefuncg</code> </td><td> <code title="">feFuncG</code>
</td></tr><tr><td> <code title="">fefuncr</code> </td><td> <code title="">feFuncR</code>
</td></tr><tr><td> <code title="">fegaussianblur</code> </td><td> <code title="">feGaussianBlur</code>
</td></tr><tr><td> <code title="">feimage</code> </td><td> <code title="">feImage</code>
</td></tr><tr><td> <code title="">femerge</code> </td><td> <code title="">feMerge</code>
</td></tr><tr><td> <code title="">femergenode</code> </td><td> <code title="">feMergeNode</code>
</td></tr><tr><td> <code title="">femorphology</code> </td><td> <code title="">feMorphology</code>
</td></tr><tr><td> <code title="">feoffset</code> </td><td> <code title="">feOffset</code>
</td></tr><tr><td> <code title="">fepointlight</code> </td><td> <code title="">fePointLight</code>
</td></tr><tr><td> <code title="">fespecularlighting</code> </td><td> <code title="">feSpecularLighting</code>
</td></tr><tr><td> <code title="">fespotlight</code> </td><td> <code title="">feSpotLight</code>
</td></tr><tr><td> <code title="">fetile</code> </td><td> <code title="">feTile</code>
</td></tr><tr><td> <code title="">feturbulence</code> </td><td> <code title="">feTurbulence</code>
</td></tr><tr><td> <code title="">foreignobject</code> </td><td> <code title="">foreignObject</code>
</td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
</td></tr><tr><td> <code title="">lineargradient</code> </td><td> <code title="">linearGradient</code>
</td></tr><tr><td> <code title="">radialgradient</code> </td><td> <code title="">radialGradient</code>
</td></tr><tr><td> <code title="">textpath</code> </td><td> <code title="">textPath</code>
</td></tr></tbody></table><p>If the <a href="parsing.html#current-node">current node</a> is an element in the <a href="namespaces.html#svg-namespace">SVG
namespace</a>, <a href="#adjust-svg-attributes">adjust SVG attributes</a> for the
token. (This fixes the case of SVG attributes that are not all
lowercase.)</p>
<p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
fixes the use of namespaced attributes, in particular XLink in
SVG.)</p>
<p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
same namespace as the <a href="parsing.html#current-node">current node</a>.</p>
<p>If the token has its <i>self-closing flag</i> set, pop the
<a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> and <a href="tokenization.html#acknowledge-self-closing-flag" title="acknowledge self-closing
flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
</dd>
<dt id="scriptForeignEndTag">An end tag whose tag name is "script", if the <a href="parsing.html#current-node">current node</a> is a <code title="">script</code> element in the <a href="namespaces.html#svg-namespace">SVG namespace</a></dt>
<dd>
<p>Pop the <a href="parsing.html#current-node">current node</a> off the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a>.</p>
<p>Let the <var title="">old insertion point</var> have the
same value as the current <a href="parsing.html#insertion-point">insertion point</a>. Let
the <a href="parsing.html#insertion-point">insertion point</a> be just before the <a href="parsing.html#next-input-character">next
input character</a>.</p>
<p>Increment the parser's <a href="parsing.html#script-nesting-level">script nesting level</a> by
one. Set the <a href="parsing.html#parser-pause-flag">parser pause flag</a> to true.</p>
<p><a href="http://www.w3.org/TR/SVGMobile12/script.html#ScriptContentProcessing">Process
the <code title="">script</code> element</a> according to the SVG
rules, if the user agent supports SVG. <a href="references.html#refsSVG">[SVG]</a></p>
<p class="note">Even if this causes <a href="apis-in-html-documents.html#dom-document-write" title="dom-document-write">new characters to be inserted into the
tokenizer</a>, the parser will not be executed reentrantly,
since the <a href="parsing.html#parser-pause-flag">parser pause flag</a> is true.</p>
<p>Decrement the parser's <a href="parsing.html#script-nesting-level">script nesting level</a> by
one. If the parser's <a href="parsing.html#script-nesting-level">script nesting level</a> is zero,
then set the <a href="parsing.html#parser-pause-flag">parser pause flag</a> to false.</p>
<p>Let the <a href="parsing.html#insertion-point">insertion point</a> have the value of the <var title="">old insertion point</var>. (In other words, restore the
<a href="parsing.html#insertion-point">insertion point</a> to its previous value. This value
might be the "undefined" value.)</p>
</dd>
<dt>Any other end tag</dt>
<dd>
<p>Run these steps:</p>
<ol><li><p>Initialize <var title="">node</var> to be the <a href="parsing.html#current-node">current
node</a> (the bottommost node of the stack).</p></li>
<li><p>If <var title="">node</var> is not an element with the
same tag name as the token, then this is a <a href="parsing.html#parse-error">parse
error</a>.</p></li>
<li><p><i>Loop</i>: If <var title="">node</var>'s tag name,
<a href="infrastructure.html#converted-to-ascii-lowercase">converted to ASCII lowercase</a>, is the same as the tag
name of the token, pop elements from the <a href="parsing.html#stack-of-open-elements">stack of open
elements</a> until <var title="">node</var> has been popped
from the stack, and then jump to the last step of this list of
steps.</p></li>
<li><p>Set <var title="">node</var> to the previous entry in the
<a href="parsing.html#stack-of-open-elements">stack of open elements</a>.</p></li>
<li><p>If <var title="">node</var> is not an element in the
<a href="namespaces.html#html-namespace-0">HTML namespace</a>, return to the step labeled
<i>loop</i>.</p></li>
<li><p>Otherwise, process the token according to the rules given
in the section corresponding to the current <a href="parsing.html#insertion-mode">insertion
mode</a> in HTML content.</p></li>
</ol></dd>
</dl></div></body></html>