]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
extends: String#ircify_html now has an option to obey non-breakable spaces or turn...
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 18 Sep 2007 13:24:55 +0000 (13:24 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 18 Sep 2007 13:24:55 +0000 (13:24 +0000)
This option is used e.g. by the dict plugin to reduce the excessive whitespace in oxford entries.

data/rbot/plugins/dict.rb
lib/rbot/core/utils/extends.rb

index 6d35bd651b496dd2bbe1029925fa70f8b76878fb..ca5f25882147c94cb7c268cb5d27e31dda216fa6 100644 (file)
@@ -115,7 +115,7 @@ class DictPlugin < Plugin
       if h and h.match(%r!<h2>#{word}(?:<sup>1</sup>)?</h2>!)\r
         m.reply("#{word} : #{url}") unless justcheck\r
         defn = $'\r
-        m.reply("#{Bold}%s#{Bold}: %s" % [word, defn.ircify_html], :overlong => :truncate)\r
+        m.reply("#{Bold}%s#{Bold}: %s" % [word, defn.ircify_html(:nbsp => :space)], :overlong => :truncate)\r
         return true\r
       end\r
     }\r
index dcc257a2df85330f073377ca95e38f21bf64250c..4e5459d850b2493e8435b6b4f545ce836b1c9f4d 100644 (file)
@@ -144,6 +144,14 @@ class ::String
     # such as &nbsp;
     txt = Utils.decode_html_entities(txt)
 
+    # Keep unbreakable spaces or conver them to plain spaces?
+    case val = opts[:nbsp]
+    when :space, ' '
+      txt.gsub!([160].pack('U'), ' ')
+    else
+      warning "unknown :nbsp option #{val} passed to ircify_html" if val
+    end
+
     # Remove double formatting options, since they only waste bytes
     txt.gsub!(/#{Bold}(\s*)#{Bold}/, '\1')
     txt.gsub!(/#{Underline}(\s*)#{Underline}/, '\1')