From b9d35dc1143395935c8da9b4de87cabde1935c37 Mon Sep 17 00:00:00 2001 From: lnu Date: Tue, 23 Aug 2005 15:11:24 +0000 Subject: better handling of feeds with HTML entities. git-svn-id: svn+ssh://svn.gna.org/svn/feed2imap/trunk/feed2imap@54 f70e237a-67f3-0310-a06c-d2b8a7116972 --- lib/feed2imap/textconverters.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lib/feed2imap') diff --git a/lib/feed2imap/textconverters.rb b/lib/feed2imap/textconverters.rb index ba3813a..418083f 100644 --- a/lib/feed2imap/textconverters.rb +++ b/lib/feed2imap/textconverters.rb @@ -27,10 +27,33 @@ class String return (self =~ /

/) || (self =~ /
/) || (self =~ //) end + # returns true if the text contains escaped HTML (with HTML entities) + def escaped_html? + return (self =~ /<img src=/) || (self =~ /<a href=/) || (self =~ /<br(\/| \/|)>/) + end + + # un-escape HTML in the text + def unescape_html + { + '<' => '<', + '>' => '>', + "'" => ''', + '"' => '"', + '&' => '&', + "\047" => ''' + }.each do |k, v| + gsub!(v, k) + end + self + end + # convert text to HTML def text2html text = self.clone return text if text.html? + if text.escaped_html? + return text.unescape_html + end # paragraphs text.gsub!(/\A\s*(.*)\Z/m, '

\1

') text.gsub!(/\s*\n(\s*\n)+\s*/, "

\n

") -- cgit v1.2.3-54-g00ecf