@@ -661,11 +661,13 @@ def addFormattingElement(self, name, attributes):
661661 self .tree .openElements [- 1 ])
662662
663663 # the real deal
664- def processSpaceCharactersPre (self , data ):
665- #Sometimes (start of <pre> blocks) we want to drop leading newlines
664+ def processSpaceCharactersDropNewline (self , data ):
665+ # Sometimes (start of <pre> and <textarea> blocks) we want to drop
666+ # leading newlines
666667 self .processSpaceCharacters = self .processSpaceCharactersNonPre
667- if (data .startswith ("\n " ) and self .tree .openElements [- 1 ].name == "pre"
668- and not self .tree .openElements [- 1 ].hasContent ()):
668+ if (data .startswith ("\n " ) and (self .tree .openElements [- 1 ].name == "pre"
669+ or self .tree .openElements [- 1 ].name == "textarea" )
670+ and not self .tree .openElements [- 1 ].hasContent ()):
669671 data = data [1 :]
670672 if data :
671673 self .tree .insertText (data )
@@ -700,7 +702,7 @@ def startTagCloseP(self, name, attributes):
700702 self .endTagP ("p" )
701703 self .tree .insertElement (name , attributes )
702704 if name == "pre" :
703- self .processSpaceCharacters = self .processSpaceCharactersPre
705+ self .processSpaceCharacters = self .processSpaceCharactersDropNewline
704706
705707 def startTagForm (self , name , attributes ):
706708 if self .tree .formPointer :
@@ -842,6 +844,7 @@ def startTagTextarea(self, name, attributes):
842844 # XXX Form element pointer checking here as well...
843845 self .tree .insertElement (name , attributes )
844846 self .parser .tokenizer .contentModelFlag = contentModelFlags ["RCDATA" ]
847+ self .processSpaceCharacters = self .processSpaceCharactersDropNewline
845848
846849 def startTagCdata (self , name , attributes ):
847850 """iframe, noembed noframes, noscript(if scripting enabled)"""
0 commit comments