From b9d35dc1143395935c8da9b4de87cabde1935c37 Mon Sep 17 00:00:00 2001
From: lnu /) || (self =~ / \1
/) || (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, '
") -- cgit v1.2.3-70-g09d2