Skip to content

Commit ab9a28e

Browse files
committed
Some fixes for whitespace in <pre> handling
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40494
1 parent 9ad8355 commit ab9a28e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/html5parser.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# Differences from the current specification (23 December 2006) are as follows:
23
# * Phases and insertion modes are one concept in parser.py.
34
# * EOF handling is slightly different to make sure <html>, <head> and <body>
@@ -17,6 +18,7 @@
1718
# Import from the sets module for python 2.3
1819
from sets import Set as set
1920
from sets import ImmutableSet as frozenset
21+
import new
2022
import gettext
2123
_ = gettext.gettext
2224

@@ -624,8 +626,10 @@ def addFormattingElement(self, name, attributes):
624626
# the real deal
625627
def processSpaceCharactersPre(self, data):
626628
#Sometimes (start of <pre> blocks) we want to drop leading newlines
627-
self.processSpaceCharacters = Phase.processSpaceCharacters
628-
if data.startswith("\n"):
629+
self.processSpaceCharacters = new.instancemethod(
630+
Phase.processSpaceCharacters, self)
631+
if (data.startswith("\n") and not
632+
self.tree.openElements[-1].hasContent()):
629633
data = data[1:]
630634
if data:
631635
self.tree.insertText(data)
@@ -859,6 +863,10 @@ def endTagHtml(self, name):
859863
self.parser.phase.processEndTag(name)
860864

861865
def endTagBlock(self, name):
866+
#Put us back in the right whitespace handling mode
867+
if name == "pre":
868+
self.processSpaceCharacters = new.instancemethod(
869+
Phase.processSpaceCharacters, self)
862870
inScope = self.tree.elementInScope(name)
863871
if inScope:
864872
self.tree.generateImpliedEndTags()

0 commit comments

Comments
 (0)