# File lib/html5/filters/optionaltags.rb, line 31
      def is_optional_start(tagname, previous, nexttok)
        type = nexttok ? nexttok[:type] : nil
        if tagname == 'html'
          # An html element's start tag may be omitted if the first thing
          # inside the html element is not a space character or a comment.
          return ![:Comment, :SpaceCharacters].include?(type)
        elsif tagname == 'head'
          # A head element's start tag may be omitted if the first thing
          # inside the head element is an element.
          return type == :StartTag
        elsif tagname == 'body'
          # A body element's start tag may be omitted if the first thing
          # inside the body element is not a space character or a comment,
          # except if the first thing inside the body element is a script
          # or style element and the node immediately preceding the body
          # element is a head element whose end tag has been omitted.
          if [:Comment, :SpaceCharacters].include?(type)
            return false
          elsif type == :StartTag
            # XXX: we do not look at the preceding event, so we never omit
            # the body element's start tag if it's followed by a script or
            # a style element.
            return !%w[script style].include?(nexttok[:name])
          else
            return true
          end
        elsif tagname == 'colgroup'
          # A colgroup element's start tag may be omitted if the first thing
          # inside the colgroup element is a col element, and if the element
          # is not immediately preceeded by another colgroup element whose
          # end tag has been omitted.
          if type == :StartTag
            # XXX: we do not look at the preceding event, so instead we never
            # omit the colgroup element's end tag when it is immediately
            # followed by another colgroup element. See is_optional_end.
            return nexttok[:name] == "col"
          else
            return false
          end
        elsif tagname == 'tbody'
          # A tbody element's start tag may be omitted if the first thing
          # inside the tbody element is a tr element, and if the element is
          # not immediately preceeded by a tbody, thead, or tfoot element
          # whose end tag has been omitted.
          if type == :StartTag
            # omit the thead and tfoot elements' end tag when they are
            # immediately followed by a tbody element. See is_optional_end.
            if previous and previous[:type] == :EndTag && %w(tbody thead tfoot).include?(previous[:name])
              return false
            end

            return nexttok[:name] == 'tr'
          else
            return false
          end
        end
        return false
      end