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
 
  13     include ActionView::Helpers::OutputSafetyHelper
 
  16       Sanitize.clean(text, Sanitize::Config::OSM).html_safe
 
  21     include ActionView::Helpers::TagHelper
 
  27       doc = Nokogiri::HTML(to_html)
 
  29       if doc.content.length > 0
 
  30         doc.xpath("//a").each do |link|
 
  32           link_size += link.content.length
 
  35         link_proportion = link_size.to_f / doc.content.length.to_f
 
  40       return [link_proportion - 0.2, 0.0].max * 200 + link_count * 40
 
  45     def simple_format(text)
 
  46       SimpleFormat.new.simple_format(text)
 
  51         Rinku.auto_link(text, :urls, tag_options(:rel => "nofollow")).html_safe
 
  53         Rinku.auto_link(text, :urls, tag_options(:rel => "nofollow"))
 
  60       linkify(sanitize(simple_format(self)))
 
  70       Sanitize.clean(text, Sanitize::Config::OSM).html_safe
 
  76       html_parser.render(self).html_safe
 
  86       @@html_renderer ||= Renderer.new({
 
  87         :filter_html => true, :safe_links_only => true
 
  89       @@html_parser ||= Redcarpet::Markdown.new(@@html_renderer, {
 
  90         :no_intra_emphasis => true, :autolink => true, :space_after_headers => true
 
  94     class Renderer < Redcarpet::Render::XHTML
 
  95       def link(link, title, alt_text)
 
  96         "<a rel=\"nofollow\" href=\"#{link}\">#{alt_text}</a>"
 
  99       def autolink(link, link_type)
 
 100         if link_type == :email
 
 101           "<a rel=\"nofollow\" href=\"mailto:#{link}\">#{link}</a>"
 
 103           "<a rel=\"nofollow\" href=\"#{link}\">#{link}</a>"
 
 111       linkify(simple_format(ERB::Util.html_escape(self)))