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