@@ -1399,7 +1399,7 @@ def endTagHeading(self, token):
1399
1399
1400
1400
def endTagFormatting (self , token ):
1401
1401
"""The much-feared adoption agency algorithm"""
1402
- # http://www .whatwg.org/specs/web-apps/current-work/ #adoptionAgency
1402
+ # http://svn .whatwg.org/webapps/complete.html #adoptionAgency revision 7867
1403
1403
# XXX Better parseError messages appreciated.
1404
1404
1405
1405
# Step 1
@@ -1456,35 +1456,45 @@ def endTagFormatting(self, token):
1456
1456
if formattingElement != self .tree .openElements [- 1 ]:
1457
1457
self .parser .parseError ("adoption-agency-1.3" , {"name" : token ["name" ]})
1458
1458
1459
- # Step 2
1460
- # Start of the adoption agency algorithm proper
1459
+ # Step 5:
1460
+
1461
+ # Let the furthest block be the topmost node in the
1462
+ # stack of open elements that is lower in the stack
1463
+ # than the formatting element, and is an element in
1464
+ # the special category. There might not be one.
1461
1465
afeIndex = self .tree .openElements .index (formattingElement )
1462
1466
furthestBlock = None
1463
1467
for element in self .tree .openElements [afeIndex :]:
1464
1468
if element .nameTuple in specialElements :
1465
1469
furthestBlock = element
1466
1470
break
1467
- # Step 3
1471
+
1472
+ # Step 6:
1473
+
1474
+ # If there is no furthest block, then the UA must
1475
+ # first pop all the nodes from the bottom of the stack
1476
+ # of open elements, from the current node up to and
1477
+ # including the formatting element, then remove the
1478
+ # formatting element from the list of active
1479
+ # formatting elements, and finally abort these steps.
1468
1480
if furthestBlock is None :
1469
1481
element = self .tree .openElements .pop ()
1470
1482
while element != formattingElement :
1471
1483
element = self .tree .openElements .pop ()
1472
1484
self .tree .activeFormattingElements .remove (element )
1473
1485
return
1474
- commonAncestor = self .tree .openElements [afeIndex - 1 ]
1475
1486
1476
- # Step 5
1477
- # if furthestBlock.parent:
1478
- # furthestBlock.parent.removeChild(furthestBlock)
1487
+ # Step 7
1488
+ commonAncestor = self .tree .openElements [afeIndex - 1 ]
1479
1489
1480
- # Step 5
1490
+ # Step 8:
1481
1491
# The bookmark is supposed to help us identify where to reinsert
1482
- # nodes in step 12 . We have to ensure that we reinsert nodes after
1492
+ # nodes in step 15 . We have to ensure that we reinsert nodes after
1483
1493
# the node before the active formatting element. Note the bookmark
1484
- # can move in step 7.4
1494
+ # can move in step 9.7
1485
1495
bookmark = self .tree .activeFormattingElements .index (formattingElement )
1486
1496
1487
- # Step 6
1497
+ # Step 9
1488
1498
lastNode = node = furthestBlock
1489
1499
innerLoopCounter = 0
1490
1500
@@ -1497,36 +1507,32 @@ def endTagFormatting(self, token):
1497
1507
if node not in self .tree .activeFormattingElements :
1498
1508
self .tree .openElements .remove (node )
1499
1509
continue
1500
- # Step 6.3
1510
+ # Step 9.6
1501
1511
if node == formattingElement :
1502
1512
break
1503
- # Step 6.4
1513
+ # Step 9.7
1504
1514
if lastNode == furthestBlock :
1505
- bookmark = (self .tree .activeFormattingElements .index (node )
1506
- + 1 )
1507
- # Step 6.5
1508
- # cite = node.parent
1515
+ bookmark = self .tree .activeFormattingElements .index (node ) + 1
1516
+ # Step 9.8
1509
1517
clone = node .cloneNode ()
1510
1518
# Replace node with clone
1511
1519
self .tree .activeFormattingElements [
1512
1520
self .tree .activeFormattingElements .index (node )] = clone
1513
1521
self .tree .openElements [
1514
1522
self .tree .openElements .index (node )] = clone
1515
1523
node = clone
1516
-
1517
- # Step 6.6
1524
+ # Step 9.9
1518
1525
# Remove lastNode from its parents, if any
1519
1526
if lastNode .parent :
1520
1527
lastNode .parent .removeChild (lastNode )
1521
1528
node .appendChild (lastNode )
1522
- # Step 7.7
1529
+ # Step 9.10
1523
1530
lastNode = node
1524
- # End of inner loop
1525
1531
1526
- # Step 7
1532
+ # Step 10
1527
1533
# Foster parent lastNode if commonAncestor is a
1528
- # table, tbody, tfoot, thead, or tr we need to foster parent the
1529
- # lastNode
1534
+ # table, tbody, tfoot, thead, or tr we need to foster
1535
+ # parent the lastNode
1530
1536
if lastNode .parent :
1531
1537
lastNode .parent .removeChild (lastNode )
1532
1538
@@ -1536,20 +1542,20 @@ def endTagFormatting(self, token):
1536
1542
else :
1537
1543
commonAncestor .appendChild (lastNode )
1538
1544
1539
- # Step 8
1545
+ # Step 11
1540
1546
clone = formattingElement .cloneNode ()
1541
1547
1542
- # Step 9
1548
+ # Step 12
1543
1549
furthestBlock .reparentChildren (clone )
1544
1550
1545
- # Step 10
1551
+ # Step 13
1546
1552
furthestBlock .appendChild (clone )
1547
1553
1548
- # Step 11
1554
+ # Step 14
1549
1555
self .tree .activeFormattingElements .remove (formattingElement )
1550
1556
self .tree .activeFormattingElements .insert (bookmark , clone )
1551
1557
1552
- # Step 12
1558
+ # Step 15
1553
1559
self .tree .openElements .remove (formattingElement )
1554
1560
self .tree .openElements .insert (
1555
1561
self .tree .openElements .index (furthestBlock ) + 1 , clone )
0 commit comments