22# * Phases and insertion modes are one concept in parser.py.
33# * EOF handling is slightly different to make sure <html>, <head> and <body>
44# always exist.
5- # * Active formatting elements not reconstructed on whitespace tokens
6-
75
86
97try :
@@ -756,11 +754,12 @@ def processSpaceCharactersDropNewline(self, data):
756754 # Sometimes (start of <pre> and <textarea> blocks) we want to drop
757755 # leading newlines
758756 self .processSpaceCharacters = self .processSpaceCharactersNonPre
759- if (data .startswith ("\n " ) and ( self . tree . openElements [ - 1 ]. name == "pre"
760- or self .tree .openElements [- 1 ].name == " textarea" )
761- and not self .tree .openElements [- 1 ].hasContent ()):
757+ if (data .startswith ("\n " ) and
758+ self .tree .openElements [- 1 ].name in ( "pre" , " textarea" ) and
759+ not self .tree .openElements [- 1 ].hasContent ()):
762760 data = data [1 :]
763761 if data :
762+ self .tree .reconstructActiveFormattingElements ()
764763 self .tree .insertText (data )
765764
766765 def processCharacters (self , data ):
@@ -770,10 +769,10 @@ def processCharacters(self, data):
770769 self .tree .reconstructActiveFormattingElements ()
771770 self .tree .insertText (data )
772771
773- #Uncomment the following to match the current spec rather than the behaviour above
774- # def processSpaceCharacters(self, data):
775- # self.tree.reconstructActiveFormattingElements()
776- # self.tree.insertText(data)
772+ #This matches the current spec but may not match the real world
773+ def processSpaceCharacters (self , data ):
774+ self .tree .reconstructActiveFormattingElements ()
775+ self .tree .insertText (data )
777776
778777 def startTagProcessInHead (self , name , attributes ):
779778 self .parser .phases ["inHead" ].processStartTag (name , attributes )
0 commit comments