@@ -388,7 +388,7 @@ def resetInsertionMode(self):
388388 nodeName = self .innerHTML
389389 # Check for conditions that should only happen in the innerHTML
390390 # case
391- if nodeName in ("select" , "colgroup" , "head" , "frameset" , " html" ):
391+ if nodeName in ("select" , "colgroup" , "head" , "html" ):
392392 assert self .innerHTML
393393
394394 if nodeName in newModes :
@@ -1385,7 +1385,11 @@ def endTagFormatting(self, token):
13851385 # http://www.whatwg.org/specs/web-apps/current-work/#adoptionAgency
13861386 # XXX Better parseError messages appreciated.
13871387 name = token ["name" ]
1388- while True :
1388+
1389+ outerLoopCounter = 0
1390+ while outerLoopCounter < 8 :
1391+ outerLoopCounter += 1
1392+
13891393 # Step 1 paragraph 1
13901394 formattingElement = self .tree .elementInActiveFormattingElements (
13911395 token ["name" ])
@@ -1435,16 +1439,17 @@ def endTagFormatting(self, token):
14351439
14361440 # Step 6
14371441 lastNode = node = furthestBlock
1438- while True :
1439- # AT replace this with a function and recursion?
1442+ innerLoopCounter = 0
1443+
1444+ index = self .tree .openElements .index (node )
1445+ while innerLoopCounter < 3 :
1446+ innerLoopCounter += 1
14401447 # Node is element before node in open elements
1441- node = self .tree .openElements [
1442- self .tree .openElements .index (node )- 1 ]
1443- while node not in self .tree .activeFormattingElements :
1444- tmpNode = node
1445- node = self .tree .openElements [
1446- self .tree .openElements .index (node )- 1 ]
1447- self .tree .openElements .remove (tmpNode )
1448+ index -= 1
1449+ node = self .tree .openElements [index ]
1450+ if node not in self .tree .activeFormattingElements :
1451+ self .tree .openElements .remove (node )
1452+ continue
14481453 # Step 6.3
14491454 if node == formattingElement :
14501455 break
@@ -1454,7 +1459,6 @@ def endTagFormatting(self, token):
14541459 + 1 )
14551460 # Step 6.5
14561461 #cite = node.parent
1457- #if node.hasContent():
14581462 clone = node .cloneNode ()
14591463 # Replace node with clone
14601464 self .tree .activeFormattingElements [
0 commit comments