@@ -1404,28 +1404,60 @@ def endTagFormatting(self, token):
1404
1404
# XXX Better parseError messages appreciated.
1405
1405
name = token ["name" ]
1406
1406
1407
+ # Step 1
1407
1408
outerLoopCounter = 0
1409
+
1410
+ # Step 2
1408
1411
while outerLoopCounter < 8 :
1412
+
1413
+ # Step 3
1409
1414
outerLoopCounter += 1
1410
1415
1411
- # Step 1 paragraph 1
1416
+ # Step 4:
1417
+
1418
+ # Let the formatting element be the last element in
1419
+ # the list of active formatting elements that:
1420
+ # - is between the end of the list and the last scope
1421
+ # marker in the list, if any, or the start of the list
1422
+ # otherwise, and
1423
+ # - has the same tag name as the token.
1412
1424
formattingElement = self .tree .elementInActiveFormattingElements (
1413
1425
token ["name" ])
1414
1426
if (not formattingElement or
1415
1427
(formattingElement in self .tree .openElements and
1416
1428
not self .tree .elementInScope (formattingElement .name ))):
1417
- self .parser .parseError ("adoption-agency-1.1" , {"name" : token ["name" ]})
1429
+ # If there is no such node, then abort these steps
1430
+ # and instead act as described in the "any other
1431
+ # end tag" entry below.
1432
+ self .endTagOther (token )
1418
1433
return
1419
1434
1420
- # Step 1 paragraph 2
1435
+ # Otherwise, if there is such a node, but that node is
1436
+ # not in the stack of open elements, then this is a
1437
+ # parse error; remove the element from the list, and
1438
+ # abort these steps.
1421
1439
elif formattingElement not in self .tree .openElements :
1422
1440
self .parser .parseError ("adoption-agency-1.2" , {"name" : token ["name" ]})
1423
1441
self .tree .activeFormattingElements .remove (formattingElement )
1424
1442
return
1443
+
1444
+
1445
+ # Otherwise, if there is such a node, and that node is
1446
+ # also in the stack of open elements, but the element
1447
+ # is not in scope, then this is a parse error; ignore
1448
+ # the token, and abort these steps.
1449
+ elif not self .tree .elementInScope (formattingElement .name ):
1450
+ self .parser .parseError ("adoption-agency-4.4" , {"name" : token ["name" ]})
1451
+ return
1425
1452
1426
- # Step 1 paragraph 3
1427
- if formattingElement != self .tree .openElements [- 1 ]:
1428
- self .parser .parseError ("adoption-agency-1.3" , {"name" : token ["name" ]})
1453
+ # Otherwise, there is a formatting element and that
1454
+ # element is in the stack and is in scope. If the
1455
+ # element is not the current node, this is a parse
1456
+ # error. In any case, proceed with the algorithm as
1457
+ # written in the following steps.
1458
+ else :
1459
+ if formattingElement != self .tree .openElements [- 1 ]:
1460
+ self .parser .parseError ("adoption-agency-1.3" , {"name" : token ["name" ]})
1429
1461
1430
1462
# Step 2
1431
1463
# Start of the adoption agency algorithm proper
0 commit comments