Skip to content

Commit f6c2703

Browse files
author
James Graham
committed
Make reset insertion mode work right + fix InSelect to match
1 parent 542dc08 commit f6c2703

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

html5lib/html5parser.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ def resetInsertionMode(self):
375375
# The name of this method is mostly historical. (It's also used in the
376376
# specification.)
377377
last = False
378+
foreign = False
378379
newModes = {
379380
"select":"inSelect",
380381
"td":"inCell",
@@ -388,38 +389,36 @@ def resetInsertionMode(self):
388389
"table":"inTable",
389390
"head":"inBody",
390391
"body":"inBody",
391-
"frameset":"inFrameset"
392+
"frameset":"inFrameset",
393+
"html":"beforeHead"
392394
}
393395
for node in self.tree.openElements[::-1]:
394396
nodeName = node.name
397+
new_phase = None
395398
if node == self.tree.openElements[0]:
399+
assert self.innerHTML
396400
last = True
397-
if nodeName not in ['td', 'th']:
398-
# XXX
399-
assert self.innerHTML
400-
nodeName = self.innerHTML
401+
nodeName = self.innerHTML
401402
# Check for conditions that should only happen in the innerHTML
402403
# case
403-
if nodeName in ("select", "colgroup", "head", "frameset"):
404-
# XXX
404+
if nodeName in ("select", "colgroup", "head", "frameset", "html"):
405405
assert self.innerHTML
406+
406407
if nodeName in newModes:
407-
self.phase = self.phases[newModes[nodeName]]
408+
new_phase = self.phases[newModes[nodeName]]
408409
break
409410
elif node.namespace in (namespaces["mathml"], namespaces["svg"]):
410-
self.phase = self.phases["inForeignContent"]
411-
self.secondaryPhase = self.phases["inBody"]
412-
break
413-
elif nodeName == "html":
414-
if self.tree.headPointer is None:
415-
self.phase = self.phases["beforeHead"]
416-
else:
417-
self.phase = self.phases["afterHead"]
418-
break
411+
foreign = True
419412
elif last:
420-
self.phase = self.phases["inBody"]
413+
new_phase = self.phases["inBody"]
421414
break
422415

416+
if foreign:
417+
self.phase = self.phases["inForeignContent"]
418+
self.secondaryPhase = new_phase
419+
else:
420+
self.phase = new_phase
421+
423422
def parseRCDataRawtext(self, token, contentType):
424423
"""Generic RCDATA/RAWTEXT Parsing algorithm
425424
contentType - RCDATA or RAWTEXT
@@ -2195,7 +2194,8 @@ def __init__(self, parser, tree):
21952194
("option", self.startTagOption),
21962195
("optgroup", self.startTagOptgroup),
21972196
("select", self.startTagSelect),
2198-
(("input", "keygen", "textarea"), self.startTagInput)
2197+
(("input", "keygen", "textarea"), self.startTagInput),
2198+
("script", self.startTagScript)
21992199
])
22002200
self.startTagHandler.default = self.startTagOther
22012201

@@ -2241,6 +2241,9 @@ def startTagInput(self, token):
22412241
self.endTagSelect(impliedTagToken("select"))
22422242
self.parser.phase.processStartTag(token)
22432243

2244+
def startTagScript(self, token):
2245+
self.parser.phases["inHead"].processStartTag(token)
2246+
22442247
def startTagOther(self, token):
22452248
self.parser.parseError("unexpected-start-tag-in-select",
22462249
{"name": token["name"]})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy