diff options
Diffstat (limited to '')
-rw-r--r-- | lib/feed2imap/textconverters.rb | 23 |
1 files changed, 23 insertions, 0 deletions
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 =~ /<p>/) || (self =~ /<br>/) || (self =~ /<br\s*(\/)?\s*>/) 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, '<p>\1</p>') text.gsub!(/\s*\n(\s*\n)+\s*/, "</p>\n<p>") |