Skip to content

Commit 8873786

Browse files
author
James Graham
committed
Update to the latest spec
1 parent 4482710 commit 8873786

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

html5lib/html5parser.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ def endTagBlock(self, token):
13321332
def endTagForm(self, token):
13331333
node = self.tree.formPointer
13341334
self.tree.formPointer = None
1335-
if node is None or not self.tree.elementInScope(node.name):
1335+
if node is None or not self.tree.elementInScope(node):
13361336
self.parser.parseError("unexpected-end-tag",
13371337
{"name":"form"})
13381338
else:
@@ -1670,8 +1670,10 @@ def startTagInput(self, token):
16701670

16711671
def startTagForm(self, token):
16721672
self.parser.parseError("unexpected-form-in-table")
1673-
self.tree.insertElement(token)
1674-
self.tree.openElements.pop()
1673+
if self.tree.formPointer is None:
1674+
self.tree.insertElement(token)
1675+
self.tree.formPointer = self.tree.openElements[-1]
1676+
self.tree.openElements.pop()
16751677

16761678
def startTagOther(self, token):
16771679
self.parser.parseError("unexpected-start-tag-implies-table-voodoo", {"name": token["name"]})
@@ -2367,9 +2369,23 @@ def processCharacters(self, token):
23672369

23682370
def processEOF(self):
23692371
self.parser.parseError("eof-in-foreign-lands")
2370-
#while self.tree.openElements.pop().name not in ("svg", "math"):
2371-
# pass
2372-
self.parser.phase = self.parser.secondaryPhase
2372+
2373+
stopNodes = frozenset([(namespaces["mathml"], "mi"),
2374+
(namespaces["mathml"], "mo"),
2375+
(namespaces["mathml"], "mn"),
2376+
(namespaces["mathml"], "ms"),
2377+
(namespaces["mathml"], "mtext"),
2378+
(namespaces["svg"], "foreignObject"),
2379+
(namespaces["svg"], "desc"),
2380+
(namespaces["svg"], "title")])
2381+
while True:
2382+
node = self.tree.openElements.pop()
2383+
if (node.nameTuple in stopNodes or
2384+
node.nameTuple[0] == namespaces["html"]):
2385+
break
2386+
2387+
if self.parser.phase == self and not self.nonHTMLElementInScope():
2388+
self.parser.phase = self.parser.secondaryPhase
23732389
self.parser.phase.processEOF()
23742390

23752391
def processStartTag(self, token):
@@ -2431,10 +2447,11 @@ def processEndTag(self, token):
24312447
if node.namespace == self.tree.defaultNamespace:
24322448
assert self.parser.secondaryPhase != self
24332449
self.parser.secondaryPhase.processEndTag(token)
2434-
if self.parser.phase == self and not self.nonHTMLElementInScope():
2435-
self.parser.phase = self.parser.secondaryPhase
24362450
break
24372451

2452+
if self.parser.phase == self and not self.nonHTMLElementInScope():
2453+
self.parser.phase = self.parser.secondaryPhase
2454+
24382455
else:
24392456
assert self.parser.secondaryPhase != self
24402457
self.parser.secondaryPhase.processEndTag(token)

html5lib/treebuilders/_base.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ def reset(self):
129129
self.document = self.documentClass()
130130

131131
def elementInScope(self, target, variant=None):
132-
# Exit early when possible.
132+
133+
#If we pass a node in we match that. if we pass a string
134+
#match any node with that name
135+
exactNode = hasattr(target, "nameTuple")
136+
133137
listElementsMap = {
134138
None:scopingElements,
135139
"button":scopingElements | set([(namespaces["html"], "button")]),
@@ -141,7 +145,8 @@ def elementInScope(self, target, variant=None):
141145
listElements = listElementsMap[variant]
142146

143147
for node in reversed(self.openElements):
144-
if node.name == target:
148+
if (node.name == target and not exactNode or
149+
node == target and exactNode):
145150
return True
146151
elif node.nameTuple in listElements:
147152
return False

0 commit comments

Comments
 (0)