Skip to content

Commit 9ad8355

Browse files
committed
Drop newline at the start of <pre> blocks
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40493
1 parent 4162ce8 commit 9ad8355

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/html5parser.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,14 @@ def addFormattingElement(self, name, attributes):
622622
self.tree.openElements[-1])
623623

624624
# the real deal
625+
def processSpaceCharactersPre(self, data):
626+
#Sometimes (start of <pre> blocks) we want to drop leading newlines
627+
self.processSpaceCharacters = Phase.processSpaceCharacters
628+
if data.startswith("\n"):
629+
data = data[1:]
630+
if data:
631+
self.tree.insertText(data)
632+
625633
def processCharacters(self, data):
626634
# XXX The specification says to do this for every character at the
627635
# moment, but apparently that doesn't match the real world so we don't
@@ -651,6 +659,8 @@ def startTagCloseP(self, name, attributes):
651659
if self.tree.elementInScope("p"):
652660
self.endTagP("p")
653661
self.tree.insertElement(name, attributes)
662+
if name == "pre":
663+
self.processSpaceCharacters = self.processSpaceCharactersPre
654664

655665
def startTagForm(self, name, attributes):
656666
if self.tree.formPointer:

0 commit comments

Comments
 (0)