diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-09-24 22:47:07 +0200 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-09-24 22:47:07 +0200 |
commit | 31463e4ed415856350b186349435fbd80f1d813a (patch) | |
tree | 72f466a5fdc608ea961ec408a80f653c0acc2d28 | |
parent | e544dadd545d4cd7f145d802109957fd8f866b41 (diff) |
ircify_html: options to handle img tags
-rw-r--r-- | lib/rbot/core/utils/extends.rb | 23 |
1 files changed, 23 insertions, 0 deletions
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!(/<img\s+(.*?)\s*\/?>/) 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", ' ') |