From 31463e4ed415856350b186349435fbd80f1d813a Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Thu, 24 Sep 2009 22:47:07 +0200 Subject: ircify_html: options to handle img tags --- lib/rbot/core/utils/extends.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lib') diff --git a/lib/rbot/core/utils/extends.rb b/lib/rbot/core/utils/extends.rb index fc7119fa..b1964617 100644 --- a/lib/rbot/core/utils/extends.rb +++ b/lib/rbot/core/utils/extends.rb @@ -245,6 +245,29 @@ class ::String warning "unknown :a_href option #{val} passed to ircify_html" if val end + # If opts[:img] is defined, it should be a String. Each image + # will be replaced by the string itself, replacing occurrences of + # %{alt} %{dimensions} and %{src} with the alt text, image dimensions + # and URL + if val = opts[:img] + if val.kind_of? String + txt.gsub!(//) do |imgtag| + attrs = Hash.new + imgtag.scan(/([[:alpha:]]+)\s*=\s*(['"])?(.*?)\2/) do |key, quote, value| + k = key.downcase.intern rescue 'junk' + attrs[k] = value + end + attrs[:alt] ||= attrs[:title] + attrs[:width] ||= '...' + attrs[:height] ||= '...' + attrs[:dimensions] ||= "#{attrs[:width]}x#{attrs[:height]}" + val % attrs + end + else + warning ":img option is not a string" + end + end + # Paragraph and br tags are converted to whitespace txt.gsub!(/<\/?(p|br)(?:\s+[^>]*)?\s*\/?\s*>/i, ' ') txt.gsub!("\n", ' ') -- cgit v1.2.3