@@ -555,8 +555,7 @@ def startTagHead(self, name, attributes):
555555 self .parser .parseError ("two-heads-are-not-better-than-one" )
556556
557557 def startTagTitle (self , name , attributes ):
558- if self .tree .headPointer is not None and \
559- self .parser .phase == self .parser .phases ["inHead" ]:
558+ if self .tree .headPointer is not None and self .parser .phase == self .parser .phases ["inHead" ]:
560559 element = self .tree .createElement (name , attributes )
561560 self .appendToHead (element )
562561 self .tree .openElements .append (element )
@@ -565,8 +564,7 @@ def startTagTitle(self, name, attributes):
565564 self .parser .tokenizer .contentModelFlag = contentModelFlags ["RCDATA" ]
566565
567566 def startTagStyle (self , name , attributes ):
568- if self .tree .headPointer is not None and \
569- self .parser .phase == self .parser .phases ["inHead" ]:
567+ if self .tree .headPointer is not None and self .parser .phase == self .parser .phases ["inHead" ]:
570568 element = self .tree .createElement (name , attributes )
571569 self .appendToHead (element )
572570 self .tree .openElements .append (element )
@@ -576,8 +574,7 @@ def startTagStyle(self, name, attributes):
576574
577575 def startTagNoScript (self , name , attributes ):
578576 # XXX Need to decide whether to implement the scripting disabled case.
579- if self .tree .headPointer is not None and \
580- self .parser .phase == self .parser .phases ["inHead" ]:
577+ if self .tree .headPointer is not None and self .parser .phase == self .parser .phases ["inHead" ]:
581578 element = self .tree .createElement (name , attributes )
582579 self .appendToHead (element )
583580 self .tree .openElements .append (element )
@@ -587,23 +584,23 @@ def startTagNoScript(self, name, attributes):
587584
588585 def startTagScript (self , name , attributes ):
589586 #XXX Inner HTML case may be wrong
590- element = self .tree .createElement (name , attributes )
591- element ._flags .append ("parser-inserted" )
592- if (self .tree .headPointer is not None and
593- self .parser .phase == self .parser .phases ["inHead" ]):
587+ element = None
588+ if (self .tree .headPointer is not None and self .parser .phase == self .parser .phases ["inHead" ]):
589+ element = self .tree .createElement (name , attributes )
594590 self .appendToHead (element )
591+ self .tree .openElements .append (element )
595592 else :
596- self .tree .openElements [ - 1 ]. appendChild ( element )
597- self . tree . openElements . append (element )
593+ element = self .tree .insertElement ( name , attributes )
594+ element . _flags . append ("parser-inserted" )
598595 self .parser .tokenizer .contentModelFlag = contentModelFlags ["CDATA" ]
599596
600597 def startTagBaseLinkMeta (self , name , attributes ):
601- element = self .tree .createElement (name , attributes )
602- if (self .tree .headPointer is not None and
603- self .parser .phase == self .parser .phases ["inHead" ]):
598+ if (self .tree .headPointer is not None and self .parser .phase == self .parser .phases ["inHead" ]):
599+ element = self .tree .createElement (name , attributes )
604600 self .appendToHead (element )
605601 else :
606- self .tree .openElements [- 1 ].appendChild (element )
602+ self .tree .insertElement (name , attributes )
603+ self .tree .openElements .pop ()
607604
608605 def startTagOther (self , name , attributes ):
609606 self .anythingElse ()
0 commit comments