8000 Pass all foreign content tests using simpletree · awesome-python/html5lib-python@f1adba6 · GitHub
[go: up one dir, main page]

Skip to content

Commit f1adba6

Browse files
committed
Pass all foreign content tests using simpletree
--HG-- branch : svgmathml extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/branches/svgmathml%401297
1 parent e2e5533 commit f1adba6

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/html5lib/html5parser.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ def resetInsertionMode(self):
334334
elif node.namespace in (namespaces["mathml"], namespaces["svg"]):
335335
self.phase = self.phases["inForeignContent"]
336336
self.secondaryPhase = self.phases["inBody"]
337+
break
337338
elif nodeName == "html":
338339
if self.tree.headPointer is None:
339340
self.phase = self.phases["beforeHead"]
@@ -1146,7 +1147,8 @@ def startTagMath(self, token):
11461147
self.tree.insertElement(token)
11471148
#Need to get the parse error right for the case where the token
11481149
#has a namespace not equal to the xmlns attribute
1149-
self.parser.secondaryPhase = self.parser.phase
1150+
if self.parser.phase != self.parser.phases["inForeignContent"]:
1151+
self.parser.secondaryPhase = self.parser.phase
11501152
self.parser.phase = self.parser.phases["inForeignContent"]
11511153
if token["selfClosing"]:
11521154
self.tree.openElements.pop()
@@ -1160,7 +1162,8 @@ def startTagSvg(self, token):
11601162
self.tree.insertElement(token)
11611163
#Need to get the parse error right for the case where the token
11621164
#has a namespace not equal to the xmlns attribute
1163-
self.parser.secondaryPhase = self.parser.phase
1165+
if self.parser.phase != self.parser.phases["inForeignContent"]:
1166+
self.parser.secondaryPhase = self.parser.phase
11641167
self.parser.phase = self.parser.phases["inForeignContent"]
11651168
if token["selfClosing"]:
11661169
self.tree.openElements.pop()
@@ -2175,6 +2178,10 @@ def __init__(self, parser, tree):
21752178
Phase.__init__(self, parser, tree)
21762179

21772180
def nonHTMLElementInScope(self):
2181+
for element in self.tree.openElements[::-1]:
2182+
if< E4FC /span> element.namespace == self.tree.defaultNamespace:
2183+
return self.tree.elementInScope(element)
2184+
assert False
21782185
for item in self.tree.openElements[::-1]:
21792186
if item.namespace == self.tree.defaultNamespace:
21802187
return True
@@ -2240,11 +2247,9 @@ def processStartTag(self, token):
22402247
currentNode.name in frozenset(["foreignObject",
22412248
"desc", "title"])
22422249
)):
2243-
print currentNode, token, self.nonHTMLElementInScope()
2244-
print self.tree.openElements
22452250
assert self.parser.secondaryPhase != self
22462251
self.parser.secondaryPhase.processStartTag(token)
2247-
if self.parser.phase == self and not self.nonHTMLElementInScope():
2252+
if self.parser.phase == self and self.nonHTMLElementInScope():
22482253
self.parser.phase = self.parser.secondaryPhase
22492254
elif token["name"] in self.breakoutElements:
22502255
self.parser.parseError("unexpected-html-element-in-foreign-content",
@@ -2268,8 +2273,9 @@ def processStartTag(self, token):
22682273
token["selfClosingAcknowledged"] = True
22692274

22702275
def processEndTag(self, token):
2276+
self.adjustSVGTagNames(token)
22712277
self.parser.secondaryPhase.processEndTag(token)
2272-
if self.parser.phase == self and not self.nonHTMLElementInScope():
2278+
if self.parser.phase == self and self.nonHTMLElementInScope():
22732279
self.parser.phase = self.parser.secondaryPhase
22742280

22752281
class AfterBodyPhase(Phase):

0 commit comments

Comments
 (0)
0