@@ -1348,17 +1348,17 @@ def endTagFormatting(self, token):
1348
1348
commonAncestor = self .tree .openElements [afeIndex - 1 ]
1349
1349
1350
1350
# Step 5
1351
- if furthestBlock .parent :
1352
- furthestBlock .parent .removeChild (furthestBlock )
1351
+ # if furthestBlock.parent:
1352
+ # furthestBlock.parent.removeChild(furthestBlock)
1353
1353
1354
- # Step 6
1354
+ # Step 5
1355
1355
# The bookmark is supposed to help us identify where to reinsert
1356
1356
# nodes in step 12. We have to ensure that we reinsert nodes after
1357
1357
# the node before the active formatting element. Note the bookmark
1358
1358
# can move in step 7.4
1359
1359
bookmark = self .tree .activeFormattingElements .index (afeElement )
1360
1360
1361
- # Step 7
1361
+ # Step 6
1362
1362
lastNode = node = furthestBlock
1363
1363
while True :
1364
1364
# AT replace this with a function and recursion?
@@ -1370,51 +1370,55 @@ def endTagFormatting(self, token):
1370
1370
node = self .tree .openElements [
1371
1371
self .tree .openElements .index (node )- 1 ]
1372
1372
self .tree .openElements .remove (tmpNode )
1373
- # Step 7 .3
1373
+ # Step 6 .3
1374
1374
if node == afeElement :
1375
1375
break
1376
- # Step 7 .4
1376
+ # Step 6 .4
1377
1377
if lastNode == furthestBlock :
1378
- bookmark = self .tree .activeFormattingElements .\
1379
- index (node ) + 1
1380
- # Step 7.5
1381
- cite = node .parent
1382
- if node .hasContent ():
1383
- clone = node .cloneNode ()
1384
- # Replace node with clone
1385
- self .tree .activeFormattingElements [
1386
- self .tree .activeFormattingElements .index (node )] = clone
1387
- self .tree .openElements [
1388
- self .tree .openElements .index (node )] = clone
1389
- node = clone
1378
+ bookmark = (self .tree .activeFormattingElements .index (node )
1379
+ + 1 )
1380
+ # Step 6.5
1381
+ #cite = node.parent
1382
+ #if node.hasContent():
1383
+ clone = node .cloneNode ()
1384
+ # Replace node with clone
1385
+ self .tree .activeFormattingElements [
1386
+ self .tree .activeFormattingElements .index (node )] = clone
1387
+ self .tree .openElements [
1388
+ self .tree .openElements .index (node )] = clone
1389
+ node = clone
1390
+
1390
1391
# Step 7.6
1391
1392
# Remove lastNode from its parents, if any
1392
1393
if lastNode .parent :
1393
1394
lastNode .parent .removeChild (lastNode )
1394
1395
node .appendChild (lastNode )
1395
1396
# Step 7.7
1396
1397
lastNode = node
1397
- # End of inner loop
1398
+ # End of inner loop
1398
1399
1399
- # Step 8
1400
+ # Step 7
1401
+ # Foster parent lastNode if commonAncestor is a
1402
+ # table, tbody, tfoot, thead, or tr we need to foster parent the
1403
+ # lastNode
1400
1404
if lastNode .parent :
1401
1405
lastNode .parent .removeChild (lastNode )
1402
1406
commonAncestor .appendChild (lastNode )
1403
1407
1404
- # Step 9
1408
+ # Step 8
1405
1409
clone = afeElement .cloneNode ()
1406
1410
1407
- # Step 10
1411
+ # Step 9
1408
1412
furthestBlock .reparentChildren (clone )
1409
1413
1410
- # Step 11
1414
+ # Step 10
1411
1415
furthestBlock .appendChild (clone )
1412
1416
1413
- # Step 12
1417
+ # Step 11
1414
1418
self .tree .activeFormattingElements .remove (afeElement )
1415
1419
self .tree .activeFormattingElements .insert (bookmark , clone )
1416
1420
1417
- # Step 13
1421
+ # Step 12
1418
1422
self .tree .openElements .remove (afeElement )
1419
1423
self .tree .openElements .insert (
1420
1424
self .tree .openElements .index (furthestBlock ) + 1 , clone )
0 commit comments