Skip to content

Commit 62e3436

Browse files
author
James Graham
committed
Fix button scoping stuff
1 parent 81c4a5d commit 62e3436

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

html5lib/constants.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@
310310

311311
specialElements = frozenset((
312312
(namespaces["html"], "address"),
313+
(namespaces["html"], "applet"),
313314
(namespaces["html"], "area"),
314315
(namespaces["html"], "article"),
315316
(namespaces["html"], "aside"),
@@ -320,6 +321,7 @@
320321
(namespaces["html"], "body"),
321322
(namespaces["html"], "br"),
322323
(namespaces["html"], "button"),
324+
(namespaces["html"], "caption"),
323325
(namespaces["html"], "center"),
324326
(namespaces["html"], "col"),
325327
(namespaces["html"], "colgroup"),
@@ -346,6 +348,7 @@
346348
(namespaces["html"], "head"),
347349
(namespaces["html"], "header"),
348350
(namespaces["html"], "hr"),
351+
(namespaces["html"], "html"),
349352
(namespaces["html"], "iframe"),
350353
# Note that image is commented out in the spec as "this isn't an
351354
# element that can end up on the stack, so it doesn't matter,"
@@ -356,12 +359,14 @@
356359
(namespaces["html"], "li"),
357360
(namespaces["html"], "link"),
358361
(namespaces["html"], "listing"),
362+
(namespaces["html"], "marquee"),
359363
(namespaces["html"], "menu"),
360364
(namespaces["html"], "meta"),
361365
(namespaces["html"], "nav"),
362366
(namespaces["html"], "noembed"),
363367
(namespaces["html"], "noframes"),
364368
(namespaces["html"], "noscript"),
369+
(namespaces["html"], "object"),
365370
(namespaces["html"], "ol"),
366371
(namespaces["html"], "p"),
367372
(namespaces["html"], "param"),
@@ -371,15 +376,19 @@
371376
(namespaces["html"], "section"),
372377
(namespaces["html"], "select"),
373378
(namespaces["html"], "style"),
379+
(namespaces["html"], "table"),
374380
(namespaces["html"], "tbody"),
381+
(namespaces["html"], "td"),
375382
(namespaces["html"], "textarea"),
376383
(namespaces["html"], "tfoot"),
384+
(namespaces["html"], "th"),
377385
(namespaces["html"], "thead"),
378386
(namespaces["html"], "title"),
379387
(namespaces["html"], "tr"),
380388
(namespaces["html"], "ul"),
381389
(namespaces["html"], "wbr"),
382-
(namespaces["html"], "xmp")
390+
(namespaces["html"], "xmp"),
391+
(namespaces["svg"], "foreignObject")
383392
))
384393

385394
spaceCharacters = frozenset((

html5lib/html5parser.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def startswithany(str, prefixes):
4040
import utils
4141
import constants
4242
from constants import spaceCharacters, asciiUpper2Lower
43-
from constants import scopingElements, formattingElements, specialElements
43+
from constants import formattingElements, specialElements
4444
from constants import headingElements, tableInsertModeElements
4545
from constants import cdataElements, rcdataElements, voidElements
4646
from constants import tokenTypes, ReparseException, namespaces, spaceCharacters
@@ -1015,12 +1015,12 @@ def startTagFrameset(self, token):
10151015
self.parser.phase = self.parser.phases["inFrameset"]
10161016

10171017
def startTagCloseP(self, token):
1018-
if self.tree.elementInScope("p"):
1018+
if self.tree.elementInScope("p", variant="button"):
10191019
self.endTagP(impliedTagToken("p"))
10201020
self.tree.insertElement(token)
10211021

10221022
def startTagPreListing(self, token):
1023-
if self.tree.elementInScope("p"):
1023+
if self.tree.elementInScope("p", variant="button"):
10241024
self.endTagP(impliedTagToken("p"))
10251025
self.tree.insertElement(token)
10261026
self.parser.framesetOK = False
@@ -1030,7 +1030,7 @@ def startTagForm(self, token):
10301030
if self.tree.formPointer:
10311031
self.parser.parseError(u"unexpected-start-tag", {"name": "form"})
10321032
else:
1033-
if self.tree.elementInScope("p"):
1033+
if self.tree.elementInScope("p", variant="button"):
10341034
self.endTagP(impliedTagToken("p"))
10351035
self.tree.insertElement(token)
10361036
self.tree.formPointer = self.tree.openElements[-1]
@@ -1047,24 +1047,24 @@ def startTagListItem(self, token):
10471047
self.parser.phase.processEndTag(
10481048
impliedTagToken(node.name, "EndTag"))
10491049
break
1050-
if (node.nameTuple in (scopingElements | specialElements) and
1050+
if (node.nameTuple in specialElements and
10511051
node.name not in ("address", "div", "p")):
10521052
break
10531053

1054-
if self.tree.elementInScope("p"):
1054+
if self.tree.elementInScope("p", variant="button"):
10551055
self.parser.phase.processEndTag(
10561056
impliedTagToken("p", "EndTag"))
10571057

10581058
self.tree.insertElement(token)
10591059

10601060
def startTagPlaintext(self, token):
1061-
if self.tree.elementInScope("p"):
1061+
if self.tree.elementInScope("p", variant="button"):
10621062
self.endTagP(impliedTagToken("p"))
10631063
self.tree.insertElement(token)
10641064
self.parser.tokenizer.state = self.parser.tokenizer.plaintextState
10651065

10661066
def startTagHeading(self, token):
1067-
if self.tree.elementInScope("p"):
1067+
if self.tree.elementInScope("p", variant="button"):
10681068
self.endTagP(impliedTagToken("p"))
10691069
if self.tree.openElements[-1].name in headingElements:
10701070
self.parser.parseError("unexpected-start-tag", {"name": token["name"]})
@@ -1116,15 +1116,15 @@ def startTagAppletMarqueeObject(self, token):
11161116
self.parser.framesetOK = False
11171117

11181118
def startTagXmp(self, token):
1119-
if self.tree.elementInScope("p"):
1119+
if self.tree.elementInScope("p", variant="button"):
11201120
self.endTagP(impliedTagToken("p"))
11211121
self.tree.reconstructActiveFormattingElements()
11221122
self.parser.framesetOK = False
11231123
self.parser.parseRCDataRawtext(token, "RAWTEXT")
11241124

11251125
def startTagTable(self, token):
11261126
if self.parser.compatMode != "quirks":
1127-
if self.tree.elementInScope("p"):
1127+
if self.tree.elementInScope("p", variant="button"):
11281128
self.processEndTag(impliedTagToken("p"))
11291129
self.tree.insertElement(token)
11301130
self.parser.framesetOK = False
@@ -1143,7 +1143,7 @@ def startTagParamSource(self, token):
11431143
token["selfClosingAcknowledged"] = True
11441144

11451145
def startTagHr(self, token):
1146-
if self.tree.elementInScope("p"):
1146+
if self.tree.elementInScope("p", variant="button"):
11471147
self.endTagP(impliedTagToken("p"))
11481148
self.tree.insertElement(token)
11491149
self.tree.openElements.pop()
@@ -1402,8 +1402,7 @@ def endTagFormatting(self, token):
14021402
afeIndex = self.tree.openElements.index(formattingElement)
14031403
furthestBlock = None
14041404
for element in self.tree.openElements[afeIndex:]:
1405-
if (element.nameTuple in
1406-
specialElements | scopingElements):
1405+
if element.nameTuple in specialElements:
14071406
furthestBlock = element
14081407
break
14091408
# Step 3
@@ -1525,8 +1524,7 @@ def endTagOther(self, token):
15251524
pass
15261525
break
15271526
else:
1528-
if (node.nameTuple in
1529-
specialElements | scopingElements):
1527+
if node.nameTuple in specialElements:
15301528
self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
15311529
break
15321530

html5lib/treebuilders/_base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def elementInScope(self, target, variant=None):
132132
# Exit early when possible.
133133
listElementsMap = {
134134
None:scopingElements,
135+
"button":scopingElements | set([(namespaces["html"], "button")]),
135136
"list":scopingElements | set([(namespaces["html"], "ol"),
136137
(namespaces["html"], "ul")]),
137138
"table":set([(namespaces["html"], "html"),

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