X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fcore%2Futils%2Fextends.rb;h=7b733994b74d323b010db0bc2ee6d66dad1f598d;hb=a209adb0e00e2a335333c1cb696d5807a47072c6;hp=e0c781b194cba78910028f156c2ea735b80f1fe0;hpb=abdbe1adcd085a131c301bb5f40c053b96b47638;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/core/utils/extends.rb b/lib/rbot/core/utils/extends.rb index e0c781b1..7b733994 100644 --- a/lib/rbot/core/utils/extends.rb +++ b/lib/rbot/core/utils/extends.rb @@ -137,6 +137,10 @@ class ::String txt.gsub!(/(.*?)<\/sub>/, '_{\1}') txt.gsub!(/(^|_)\{(.)\}/, '\1\2') + # List items are converted to *). We don't have special support for + # nested or ordered lists. + txt.gsub!(/
  • /, ' *) ') + # All other tags are just removed txt.gsub!(/<[^>]+>/, '') @@ -144,6 +148,14 @@ class ::String # such as   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') @@ -178,6 +190,23 @@ class ::String def riphtml self.gsub(/<[^>]+>/, '').gsub(/&/,'&').gsub(/"/,'"').gsub(/</,'<').gsub(/>/,'>').gsub(/&ellip;/,'...').gsub(/'/, "'").gsub("\n",'') end + + # This method tries to find an HTML title in the string, + # and returns it if found + def get_html_title + if defined? ::Hpricot + Hpricot(self).at("title").inner_html + else + return unless Irc::Utils::TITLE_REGEX.match(self) + $1 + end + end + + # This method returns the IRC-formatted version of an + # HTML title found in the string + def ircify_html_title + self.get_html_title.ircify_html rescue nil + end end