ircify_first_html_par_woh (::Utils)

    # File lib/rbot/core/utils/utils.rb, line 468
        def Utils.ircify_first_html_par_woh(xml_org, opts={})
          xml = xml_org.gsub(/<!--.*?-->/m, '').gsub(/<script(?:\s+[^>]*)?>.*?<\/script>/im, "").gsub(/<style(?:\s+[^>]*)?>.*?<\/style>/im, "")

          strip = opts[:strip]
          strip = Regexp.new(/^#{Regexp.escape(strip)}/) if strip.kind_of?(String)

          min_spaces = opts[:min_spaces] || 8
          min_spaces = 0 if min_spaces < 0

          txt = String.new

          while true
            debug "Minimum number of spaces: #{min_spaces}"
            header_found = xml.match(HX_REGEX)
            if header_found
              header_found = $'
              while txt.empty? or txt.count(" ") < min_spaces
                candidate = header_found[PAR_REGEX]
                break unless candidate
                txt = candidate.ircify_html
                header_found = $'
                txt.sub!(strip, '') if strip
                debug "(Hx attempt) #{txt.inspect} has #{txt.count(" ")} spaces"
              end
            end

            return txt unless txt.empty? or txt.count(" ") < min_spaces

            # If we haven't found a first par yet, try to get it from the whole
            # document
            header_found = xml
            while txt.empty? or txt.count(" ") < min_spaces
              candidate = header_found[PAR_REGEX]
              break unless candidate
              txt = candidate.ircify_html
              header_found = $'
              txt.sub!(strip, '') if strip
              debug "(par attempt) #{txt.inspect} has #{txt.count(" ")} spaces"
            end

            return txt unless txt.empty? or txt.count(" ") < min_spaces

            # Nothing yet ... let's get drastic: we look for non-par elements too,
            # but only for those that match something that we know is likely to
            # contain text

            # Attempt #1
            header_found = xml
            while txt.empty? or txt.count(" ") < min_spaces
              candidate = header_found[AFTER_PAR1_REGEX]
              break unless candidate
              txt = candidate.ircify_html
              header_found = $'
              txt.sub!(strip, '') if strip
              debug "(other attempt \#1) #{txt.inspect} has #{txt.count(" ")} spaces"
            end

            return txt unless txt.empty? or txt.count(" ") < min_spaces

            # Attempt #2
            header_found = xml
            while txt.empty? or txt.count(" ") < min_spaces
              candidate = header_found[AFTER_PAR2_REGEX]
              break unless candidate
              txt = candidate.ircify_html
              header_found = $'
              txt.sub!(strip, '') if strip
              debug "(other attempt \#2) #{txt.inspect} has #{txt.count(" ")} spaces"
            end

            debug "Last candidate #{txt.inspect} has #{txt.count(" ")} spaces"
            return txt unless txt.count(" ") < min_spaces
            break if min_spaces == 0
            min_spaces /= 2
          end
        end