Skip to content

Commit 913244b

Browse files
committed
More <pre> newline edge case fixes
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40495
1 parent ab9a28e commit 913244b

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/html5parser.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
# Import from the sets module for python 2.3
1919
from sets import Set as set
2020
from sets import ImmutableSet as frozenset
21-
import new
2221
import gettext
2322
_ = gettext.gettext
2423

@@ -555,6 +554,10 @@ class InBodyPhase(Phase):
555554
# the crazy mode
556555
def __init__(self, parser, tree):
557556
Phase.__init__(self, parser, tree)
557+
558+
#Keep a ref to this for special handling of whitespace in <pre>
559+
self.processSpaceCharactersNonPre = self.processSpaceCharacters
560+
558561
self.startTagHandler = utils.MethodDispatcher([
559562
("html", self.startTagHtml),
560563
(("script", "style"), self.startTagScriptStyle),
@@ -626,10 +629,9 @@ def addFormattingElement(self, name, attributes):
626629
# the real deal
627630
def processSpaceCharactersPre(self, data):
628631
#Sometimes (start of <pre> blocks) we want to drop leading newlines
629-
self.processSpaceCharacters = new.instancemethod(
630-
Phase.processSpaceCharacters, self)
631-
if (data.startswith("\n") and not
632-
self.tree.openElements[-1].hasContent()):
632+
self.processSpaceCharacters = self.processSpaceCharactersNonPre
633+
if (data.startswith("\n") and self.tree.openElements[-1].name == "pre"
634+
and not self.tree.openElements[-1].hasContent()):
633635
data = data[1:]
634636
if data:
635637
self.tree.insertText(data)
@@ -865,8 +867,7 @@ def endTagHtml(self, name):
865867
def endTagBlock(self, name):
866868
#Put us back in the right whitespace handling mode
867869
if name == "pre":
868-
self.processSpaceCharacters = new.instancemethod(
869-
Phase.processSpaceCharacters, self)
870+
self.processSpaceCharacters = self.processSpaceCharactersNonPre
870871
inScope = self.tree.elementInScope(name)
871872
if inScope:
872873
self.tree.generateImpliedEndTags()

0 commit comments

Comments
 (0)