2   def self.new(format, text)
 
   4     when "html" then HTML.new(text || "")
 
   5     when "markdown" then Markdown.new(text || "")
 
   6     when "text" then Text.new(text || "")
 
  11     include ActionView::Helpers::TextHelper
 
  12     include ActionView::Helpers::OutputSafetyHelper
 
  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       [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       Markdown.html_parser.render(self).html_safe
 
  82     def self.html_renderer
 
  83       @html_renderer ||= Renderer.new(:filter_html => true, :safe_links_only => true)
 
  87       @html_parser ||= Redcarpet::Markdown.new(html_renderer, :no_intra_emphasis => true, :autolink => true, :space_after_headers => true)
 
  90     class Renderer < Redcarpet::Render::XHTML
 
  91       def link(link, _title, alt_text)
 
  92         "<a rel=\"nofollow\" href=\"#{link}\">#{alt_text}</a>"
 
  95       def autolink(link, link_type)
 
  96         if link_type == :email
 
  97           "<a rel=\"nofollow\" href=\"mailto:#{link}\">#{link}</a>"
 
  99           "<a rel=\"nofollow\" href=\"#{link}\">#{link}</a>"
 
 107       linkify(simple_format(ERB::Util.html_escape(self)))