Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit66ef026

Browse files
committed
Teach lint & treewalkers that elements are only void in HTML ns
1 parent270a2ca commit66ef026

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

‎html5lib/filters/lint.py‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
fromsiximporttext_type
44

55
from .import_base
6-
from ..constantsimportvoidElements
6+
from ..constantsimportnamespaces,voidElements
77

88
from ..constantsimportspaceCharacters
99
spaceCharacters="".join(spaceCharacters)
@@ -19,17 +19,22 @@ def __iter__(self):
1919
fortokenin_base.Filter.__iter__(self):
2020
type=token["type"]
2121
iftypein ("StartTag","EmptyTag"):
22+
namespace=token["namespace"]
2223
name=token["name"]
24+
ifnamespaceisnotNoneandnotisinstance(namespace,text_type):
25+
raiseLintError("Tag namespace is not a string or None: %(name)r"% {"name":namespace})
26+
ifnamespace=="":
27+
raiseLintError("Empty tag namespace")
2328
ifnotisinstance(name,text_type):
2429
raiseLintError("Tag name is not a string: %(tag)r"% {"tag":name})
2530
ifnotname:
2631
raiseLintError("Empty tag name")
27-
iftype=="StartTag"andnameinvoidElements:
32+
iftype=="StartTag"and(notnamespaceornamespace==namespaces["html"])andnameinvoidElements:
2833
raiseLintError("Void element reported as StartTag token: %(tag)s"% {"tag":name})
29-
eliftype=="EmptyTag"andnamenotinvoidElements:
34+
eliftype=="EmptyTag"and(notnamespaceornamespace==namespaces["html"])andnamenotinvoidElements:
3035
raiseLintError("Non-void element reported as EmptyTag token: %(tag)s"% {"tag":token["name"]})
3136
iftype=="StartTag":
32-
open_elements.append(name)
37+
open_elements.append((namespace,name))
3338
for (namespace,localname),valueintoken["data"].items():
3439
ifnamespaceisnotNoneandnotisinstance(namespace,text_type):
3540
raiseLintError("Attribute namespace is not a string or None: %(name)r"% {"name":namespace})
@@ -43,15 +48,20 @@ def __iter__(self):
4348
raiseLintError("Attribute value is not a string: %(value)r"% {"value":value})
4449

4550
eliftype=="EndTag":
51+
namespace=token["namespace"]
4652
name=token["name"]
53+
ifnamespaceisnotNoneandnotisinstance(namespace,text_type):
54+
raiseLintError("Tag namespace is not a string or None: %(name)r"% {"name":namespace})
55+
ifnamespace=="":
56+
raiseLintError("Empty tag namespace")
4757
ifnotisinstance(name,text_type):
4858
raiseLintError("Tag name is not a string: %(tag)r"% {"tag":name})
4959
ifnotname:
5060
raiseLintError("Empty tag name")
51-
ifnameinvoidElements:
61+
if(notnamespaceornamespace==namespaces["html"])andnameinvoidElements:
5262
raiseLintError("Void element reported as EndTag token: %(tag)s"% {"tag":name})
5363
start_name=open_elements.pop()
54-
ifstart_name!=name:
64+
ifstart_name!=(namespace,name):
5565
raiseLintError("EndTag (%(end)s) does not match StartTag (%(start)s)"% {"end":name,"start":start_name})
5666

5767
eliftype=="Comment":

‎html5lib/treewalkers/_base.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
fromsiximporttext_type,string_types
33

44
fromxml.domimportNode
5-
from ..constantsimportvoidElements,spaceCharacters
5+
from ..constantsimportnamespaces,voidElements,spaceCharacters
66

77
__all__= ["DOCUMENT","DOCTYPE","TEXT","ELEMENT","COMMENT","ENTITY","UNKNOWN",
88
"TreeWalker","NonRecursiveTreeWalker"]
@@ -154,7 +154,7 @@ def __iter__(self):
154154

155155
eliftype==ELEMENT:
156156
namespace,name,attributes,hasChildren=details
157-
ifnameinvoidElements:
157+
if(notnamespaceornamespace==namespaces["html"])andnameinvoidElements:
158158
fortokeninself.emptyTag(namespace,name,attributes,
159159
hasChildren):
160160
yieldtoken
@@ -187,7 +187,7 @@ def __iter__(self):
187187
type,details=details[0],details[1:]
188188
iftype==ELEMENT:
189189
namespace,name,attributes,hasChildren=details
190-
ifnamenotinvoidElements:
190+
if(namespaceandnamespace!=namespaces["html"])ornamenotinvoidElements:
191191
yieldself.endTag(namespace,name)
192192
ifself.treeiscurrentNode:
193193
currentNode=None

‎html5lib/treewalkers/genshistream.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def tokens(self, event, next):
4848
elifkind==END:
4949
name=data.localname
5050
namespace=data.namespace
51-
ifnamenotinvoidElements:
51+
ifnamespace!=namespaces["html"]ornamenotinvoidElements:
5252
yieldself.endTag(namespace,name)
5353

5454
elifkind==COMMENT:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp