@@ -25,14 +25,14 @@ class HTMLSerializer(object):
2525 quote_char = '"'
2626 minimize_boolean_attributes = True
2727
28+ use_trailing_solidus = False
2829 trailing_solidus = " /"
2930
3031 omit_optional_tags = True
3132
3233 def __init__ (self , ** kwargs ):
33- for attr in ("quote_attr_values" , "quote_char" ,
34- "minimize_boolean_attributes" , "trailing_solidus" ,
35- "omit_optional_tags" ):
34+ for attr in ("quote_attr_values" , "quote_char" , "minimize_boolean_attributes" ,
35+ "trailing_solidus" , "use_trailing_solidus" , "omit_optional_tags" ):
3636 if attr in kwargs :
3737 setattr (self , attr , kwargs [attr ])
3838 self .errors = []
@@ -77,7 +77,7 @@ def serialize(self, treewalker):
7777 and k not in booleanAttributes .get ("" , tuple ())):
7878 attributes .append ("=" )
7979 v = v .replace ("&" , "&" )
80- if self .quote_attr_values :
80+ if self .quote_attr_values or not v :
8181 quote_attr = True
8282 else :
8383 quote_attr = reduce (lambda x ,y : x or y in v ,
@@ -92,8 +92,8 @@ def serialize(self, treewalker):
9292 attributes .append (self .quote_char )
9393 else :
9494 attributes .append (v )
95- if name in voidElements and self .include_trailing_slashes :
96- attributes .append (" /" )
95+ if name in voidElements and self .use_trailing_solidus :
96+ attributes .append (self . trailing_solidus )
9797 yield u"<%s%s>" % (name , u"" .join (attributes ))
9898
9999 elif type == "EndTag" :
@@ -186,8 +186,8 @@ def is_optional_start(self, tagname, next):
186186 # TODO
187187 return False
188188
189- def _is_optional_end (self , tagname , next_event ):
190- type , data = next_event
189+ def is_optional_end (self , tagname , next ):
190+ type = next and next [ "type" ] or None
191191 if tagname in ('html' , 'head' , 'body' ):
192192 # An html element's end tag may be omitted if the html element
193193 # is not immediately followed by a space character or a comment.
0 commit comments