3
3
from six import text_type
4
4
5
5
from . import _base
6
- from ..constants import voidElements
6
+ from ..constants import namespaces , voidElements
7
7
8
8
from ..constants import spaceCharacters
9
9
spaceCharacters = "" .join (spaceCharacters )
@@ -19,17 +19,22 @@ def __iter__(self):
19
19
for token in _base .Filter .__iter__ (self ):
20
20
type = token ["type" ]
21
21
if type in ("StartTag" , "EmptyTag" ):
22
+ namespace = token ["namespace" ]
22
23
name = token ["name" ]
24
+ if namespace is not None and not isinstance (namespace , text_type ):
25
+ raise LintError ("Tag namespace is not a string or None: %(name)r" % {"name" : namespace })
26
+ if namespace == "" :
27
+ raise LintError ("Empty tag namespace" )
23
28
if not isinstance (name , text_type ):
24
29
raise LintError ("Tag name is not a string: %(tag)r" % {"tag" : name })
25
30
if not name :
26
31
raise LintError ("Empty tag name" )
27
- if type == "StartTag" and name in voidElements :
32
+ if type == "StartTag" and ( not namespace or namespace == namespaces [ "html" ]) and name in voidElements :
28
33
raise LintError ("Void element reported as StartTag token: %(tag)s" % {"tag" : name })
29
- elif type == "EmptyTag" and name not in voidElements :
34
+ elif type == "EmptyTag" and ( not namespace or namespace == namespaces [ "html" ]) and name not in voidElements :
30
35
raise LintError ("Non-void element reported as EmptyTag token: %(tag)s" % {"tag" : token ["name" ]})
31
36
if type == "StartTag" :
32
- open_elements .append (name )
37
+ open_elements .append (( namespace , name ) )
33
38
for (namespace , localname ), value in token ["data" ].items ():
34
39
if namespace is not None and not isinstance (namespace , text_type ):
35
40
raise LintError ("Attribute namespace is not a string or None: %(name)r" % {"name" : namespace })
@@ -43,15 +48,20 @@ def __iter__(self):
43
48
raise LintError ("Attribute value is not a string: %(value)r" % {"value" : value })
44
49
45
50
elif type == "EndTag" :
51
+ namespace = token ["namespace" ]
46
52
name = token ["name" ]
53
+ if namespace is not None and not isinstance (namespace , text_type ):
54
+ raise LintError ("Tag namespace is not a string or None: %(name)r" % {"name" : namespace })
55
+ if namespace == "" :
56
+ raise LintError ("Empty tag namespace" )
47
57
if not isinstance (name , text_type ):
48
58
raise LintError ("Tag name is not a string: %(tag)r" % {"tag" : name })
49
59
if not name :
50
60
raise LintError ("Empty tag name" )
51
- if name in voidElements :
61
+ if ( not namespace or namespace == namespaces [ "html" ]) and name in voidElements :
52
62
raise LintError ("Void element reported as EndTag token: %(tag)s" % {"tag" : name })
53
63
start_name = open_elements .pop ()
54
- if start_name != name :
64
+ if start_name != ( namespace , name ) :
55
65
raise LintError ("EndTag (%(end)s) does not match StartTag (%(start)s)" % {"end" : name , "start" : start_name })
56
66
57
67
elif type == "Comment" :
0 commit comments