33from six import text_type
44
55from . import _base
6- from ..constants import voidElements
6+ from ..constants import namespaces , voidElements
77
88from ..constants import spaceCharacters
99spaceCharacters = "" .join (spaceCharacters )
@@ -19,17 +19,22 @@ def __iter__(self):
1919 for token in _base .Filter .__iter__ (self ):
2020 type = token ["type" ]
2121 if type in ("StartTag" , "EmptyTag" ):
22+ namespace = token ["namespace" ]
2223 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" )
2328 if not isinstance (name , text_type ):
2429 raise LintError ("Tag name is not a string: %(tag)r" % {"tag" : name })
2530 if not name :
2631 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 :
2833 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 :
3035 raise LintError ("Non-void element reported as EmptyTag token: %(tag)s" % {"tag" : token ["name" ]})
3136 if type == "StartTag" :
32- open_elements .append (name )
37+ open_elements .append (( namespace , name ) )
3338 for (namespace , localname ), value in token ["data" ].items ():
3439 if namespace is not None and not isinstance (namespace , text_type ):
3540 raise LintError ("Attribute namespace is not a string or None: %(name)r" % {"name" : namespace })
@@ -43,15 +48,20 @@ def __iter__(self):
4348 raise LintError ("Attribute value is not a string: %(value)r" % {"value" : value })
4449
4550 elif type == "EndTag" :
51+ namespace = token ["namespace" ]
4652 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" )
4757 if not isinstance (name , text_type ):
4858 raise LintError ("Tag name is not a string: %(tag)r" % {"tag" : name })
4959 if not name :
5060 raise LintError ("Empty tag name" )
51- if name in voidElements :
61+ if ( not namespace or namespace == namespaces [ "html" ]) and name in voidElements :
5262 raise LintError ("Void element reported as EndTag token: %(tag)s" % {"tag" : name })
5363 start_name = open_elements .pop ()
54- if start_name != name :
64+ if start_name != ( namespace , name ) :
5565 raise LintError ("EndTag (%(end)s) does not match StartTag (%(start)s)" % {"end" : name , "start" : start_name })
5666
5767 elif type == "Comment" :
0 commit comments