@@ -81,16 +81,13 @@ def is_optional_end(self, tagname, next):
8181# An html element's end tag may be omitted if the html element
8282# is not immediately followed by a space character or a comment.
8383return type not in ("Comment" ,"SpaceCharacters" )
84- elif tagname in ('li' ,'optgroup' ,'option' , ' tr' ):
84+ elif tagname in ('li' ,'optgroup' ,'tr' ):
8585# A li element's end tag may be omitted if the li element is
8686# immediately followed by another li element or if there is
8787# no more content in the parent element.
8888# An optgroup element's end tag may be omitted if the optgroup
8989# element is immediately followed by another optgroup element,
9090# or if there is no more content in the parent element.
91- # An option element's end tag may be omitted if the option
92- # element is immediately followed by another option element,
93- # or if there is no more content in the parent element.
9491# A tr element's end tag may be omitted if the tr element is
9592# immediately followed by another tr element, or if there is
9693# no more content in the parent element.
@@ -125,6 +122,16 @@ def is_optional_end(self, tagname, next):
125122'p' ,'pre' ,'section' ,'table' ,'ul' )
126123else :
127124return type == "EndTag" or type is None
125+ elif tagname == 'option' :
126+ # An option element's end tag may be omitted if the option
127+ # element is immediately followed by another option element,
128+ # or if it is immediately followed by an <code>optgroup</code>
129+ # element, or if there is no more content in the parent
130+ # element.
131+ if type == "StartTag" :
132+ return next ["name" ]in ('option' ,'optgroup' )
133+ else :
134+ return type == "EndTag" or type is None
128135elif tagname in ('rt' ,'rp' ):
129136# An rt element's end tag may be omitted if the rt element is
130137# immediately followed by an rt or rp element, or if there is