def ircify_html(opts={})
txt = self.dup
txt.gsub!(/<script(?:\s+[^>]*)?>.*?<\/script>/im, "")
txt.gsub!(/<style(?:\s+[^>]*)?>.*?<\/style>/im, "")
txt.gsub!(/<\/?(?:b|strong)(?:\s+[^>]*)?>/im, "#{Bold}")
txt.gsub!(/<\/?(?:i|em|u)(?:\s+[^>]*)?>/im, "#{Underline}")
case val = opts[:a_href]
when Reverse, Bold, Underline
txt.gsub!(/<(?:\/a\s*|a (?:[^>]*\s+)?href\s*=\s*(?:[^>]*\s*)?)>/, val)
when :link_out
txt.gsub!(/<a (?:[^>]*\s+)?href\s*=\s*(?:([^"'>][^\s>]*)\s+|"((?:[^"]|\\")*)"|'((?:[^']|\\')*)')(?:[^>]*\s+)?>(.*?)<\/a>/) { |match|
debug match
debug [$1, $2, $3, $4].inspect
link = $1 || $2 || $3
str = $4
str + ": " + link
}
else
warning "unknown :a_href option #{val} passed to ircify_html" if val
end
txt.gsub!(/<\/?(p|br)(?:\s+[^>]*)?\s*\/?\s*>/i, ' ')
txt.gsub!("\n", ' ')
txt.gsub!("\r", ' ')
txt.gsub!(/<sup>(.*?)<\/sup>/, '^{\1}')
txt.gsub!(/<sub>(.*?)<\/sub>/, '_{\1}')
txt.gsub!(/(^|_)\{(.)\}/, '\1\2')
txt.gsub!(/<li>/, ' *) ')
txt.gsub!(/<[^>]+>/, '')
txt = Utils.decode_html_entities(txt)
case val = opts[:nbsp]
when :space, ' '
txt.gsub!([160].pack('U'), ' ')
else
warning "unknown :nbsp option #{val} passed to ircify_html" if val
end
txt.gsub!(/#{Bold}(\s*)#{Bold}/, '\1')
txt.gsub!(/#{Underline}(\s*)#{Underline}/, '\1')
txt.gsub!(/\s+(#{Bold}|#{Underline})\s+/, ' \1')
txt.sub!(/\s+(#{Bold}|#{Underline})\z/, '\1')
txt.sub!(/\A(#{Bold}|#{Underline})\s+/, '\1')
txt.gsub!(/\s+/, ' ')
txt.strip!
if opts[:limit] && txt.size > opts[:limit]
txt = txt.slice(0, opts[:limit]) + "#{Reverse}...#{Reverse}"
end
return txt
end