def close_tags(text)
      # Don't bother closing tags if html is stripped since there are no tags.
      if @settings[:strip_html] && @settings[:allowed_tags].empty?
        tagstoclose = nil
      else
        tagstoclose = ""
        tags = []
        opentags = text.scan(OPENING_TAG).transpose[0] || []
        opentags.reverse!
        closedtags = text.scan(CLOSING_TAG).transpose[0] || []

        opentags.each do |ot|
          if closedtags.include?(ot)
            closedtags.delete_at(closedtags.index(ot))
          else
            tags << ot
          end
        end

        tags.each do |tag|
          tagstoclose << "</#{tag.strip.downcase}>" unless NO_CLOSE.include?(tag)
        end      
      end

      @excerpt = [text, @settings[:ending], tagstoclose].join
    end
def close_tags(text)
      # Don't bother closing tags if html is stripped since there are no tags.
      if @settings[:strip_html] && @settings[:allowed_tags].empty?
        tagstoclose = nil
      else
        tagstoclose = ""
        tags = []
        opentags = text.scan(OPENING_TAG).transpose[0] || []
        opentags.reverse!
        closedtags = text.scan(CLOSING_TAG).transpose[0] || []

        opentags.each do |ot|
          if closedtags.include?(ot)
            closedtags.delete_at(closedtags.index(ot))
          else
            tags << ot
          end
        end

        tags.each do |tag|
          tagstoclose << "</#{tag.strip.downcase}>" unless NO_CLOSE.include?(tag)
        end      
      end

      @excerpt = [text, @settings[:ending], tagstoclose].join
    end
close html tags