8000 Reconstruct active formatting elements on whitespace (matches browser… · awesome-python/html5lib-python@7f2784d · GitHub
[go: up one dir, main page]

Skip to content

Commit 7f2784d

Browse files
committed
Reconstruct active formatting elements on whitespace (matches browser behavior and spec
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40906
1 parent 49cbb22 commit 7f2784d

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/html5lib/html5parser.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# * Phases and insertion modes are one concept in parser.py.
33
# * EOF handling is slightly different to make sure <html>, <head> and <body>
44
# always exist.
5-
# * Active formatting elements not reconstructed on whitespace tokens
6-
75

86

97
try:
@@ -756,11 +754,12 @@ def processSpaceCharactersDropNewline(self, data):
756754
# Sometimes (start of <pre> and <textarea> blocks) we want to drop
757755
# leading newlines
758756
self.processSpaceCharacters = self.processSpaceCharactersNonPre
759-
if (data.startswith("\n") and (self.tree.openElements[-1].name == "pre"
760-
or self.tree.openElements[-1].name == "textarea")
761-
and not self.tree.openElements[-1].hasContent()):
757+
if (data.startswith("\n") and
758+
self.tree.openElements[-1].name in ("pre", "textarea") and
759+
not self.tree.openElements[-1].hasContent()):
762760
data = data[1:]
763761
if data:
762+
self.tree.reconstructActiveFormattingElements()
764763
self.tree.insertText(data)
765764

766765
def processCharacters(self, data):
@@ -770,10 +769,10 @@ def processCharacters(self, data):
770769
self.tree.reconstructActiveFormattingElements()
771770
self.tree.insertText(data)
772771

773-
#Uncomment the following to match the current spec rather than the behaviour above
774-
#def processSpaceCharacters(self, data):
775-
# self.tree.reconstructActiveFormattingElements()
776-
# self.tree.insertText(data)
772+
#This matches the current spec but may not match the real world
773+
def processSpaceCharacters(self, data):
774+
self.tree.reconstructActiveFormattingElements()
775+
self.tree.insertText(data)
777776

778777
def startTagProcessInHead(self, name, attributes):
779778
self.parser.phases["inHead"].processStartTag(name, attributes)

0 commit comments

Comments
 (0)
0