|
18 | 18 | # Import from the sets module for python 2.3 |
19 | 19 | from sets import Set as set |
20 | 20 | from sets import ImmutableSet as frozenset |
21 | | -import new |
22 | 21 | import gettext |
23 | 22 | _ = gettext.gettext |
24 | 23 |
|
@@ -555,6 +554,10 @@ class InBodyPhase(Phase): |
555 | 554 | # the crazy mode |
556 | 555 | def __init__(self, parser, tree): |
557 | 556 | 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 | + |
558 | 561 | self.startTagHandler = utils.MethodDispatcher([ |
559 | 562 | ("html", self.startTagHtml), |
560 | 563 | (("script", "style"), self.startTagScriptStyle), |
@@ -626,10 +629,9 @@ def addFormattingElement(self, name, attributes): |
626 | 629 | # the real deal |
627 | 630 | def processSpaceCharactersPre(self, data): |
628 | 631 | #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()): |
633 | 635 | data = data[1:] |
634 | 636 | if data: |
635 | 637 | self.tree.insertText(data) |
@@ -865,8 +867,7 @@ def endTagHtml(self, name): |
865 | 867 | def endTagBlock(self, name): |
866 | 868 | #Put us back in the right whitespace handling mode |
867 | 869 | if name == "pre": |
868 | | - self.processSpaceCharacters = new.instancemethod( |
869 | | - Phase.processSpaceCharacters, self) |
| 870 | + self.processSpaceCharacters = self.processSpaceCharactersNonPre |
870 | 871 | inScope = self.tree.elementInScope(name) |
871 | 872 | if inScope: |
872 | 873 | self.tree.generateImpliedEndTags() |
|
0 commit comments