2 def self.new(format, text)
4 when "html"; HTML.new(text || "")
5 when "markdown"; Markdown.new(text || "")
6 when "text"; Text.new(text || "")
12 include ActionView::Helpers::TextHelper
15 Sanitize.clean(text, Sanitize::Config::OSM).html_safe
20 include ActionView::Helpers::TagHelper
26 doc = Nokogiri::HTML(to_html)
28 if doc.content.length > 0
29 doc.xpath("//a").each do |link|
31 link_size += link.content.length
34 link_proportion = link_size.to_f / doc.content.length.to_f
39 return [link_proportion - 0.2, 0.0].max * 200 + link_count * 40
44 def simple_format(text)
45 SimpleFormat.new.simple_format(text)
50 Rinku.auto_link(text, :urls, tag_options(:rel => "nofollow")).html_safe
52 Rinku.auto_link(text, :urls, tag_options(:rel => "nofollow"))
59 linkify(sanitize(simple_format(self)))
69 Sanitize.clean(text, Sanitize::Config::OSM).html_safe
75 html_parser.render(self).html_safe
85 @@html_renderer ||= Renderer.new({
86 :filter_html => true, :safe_links_only => true
88 @@html_parser ||= Redcarpet::Markdown.new(@@html_renderer, {
89 :no_intra_emphasis => true, :autolink => true, :space_after_headers => true
93 class Renderer < Redcarpet::Render::XHTML
94 def link(link, title, alt_text)
95 "<a rel=\"nofollow\" href=\"#{link}\">#{alt_text}</a>"
98 def autolink(link, link_type)
99 if link_type == :email
100 "<a rel=\"nofollow\" href=\"mailto:#{link}\">#{link}</a>"
102 "<a rel=\"nofollow\" href=\"#{link}\">#{link}</a>"
110 linkify(simple_format(ERB::Util.html_escape(self)))