2 def self.new(format, text)
4 when "html"; HTML.new(text || "")
5 when "markdown"; Markdown.new(text || "")
6 when "text"; Text.new(text || "")
16 doc = Nokogiri::HTML(to_html)
18 if doc.content.length > 0
19 doc.xpath("//a").each do |link|
21 link_size += link.content.length
24 link_proportion = link_size.to_f / doc.content.length.to_f
29 return [link_proportion - 0.2, 0.0].max * 200 + link_count * 20
36 Rinku.auto_link(text, :urls, tag_options(:rel => "nofollow")).html_safe
38 Rinku.auto_link(text, :urls, tag_options(:rel => "nofollow"))
44 include ActionView::Helpers::TextHelper
45 include ActionView::Helpers::TagHelper
48 linkify(sanitize(simple_format(self)))
58 Sanitize.clean(text, Sanitize::Config::OSM).html_safe
64 html_parser.render(self).html_safe
74 @@html_renderer ||= Renderer.new({
75 :filter_html => true, :safe_links_only => true
77 @@html_parser ||= Redcarpet::Markdown.new(@@html_renderer, {
78 :no_intra_emphasis => true, :autolink => true, :space_after_headers => true
82 class Renderer < Redcarpet::Render::XHTML
83 def link(link, title, alt_text)
84 "<a rel=\"nofollow\" href=\"#{link}\">#{alt_text}</a>"
87 def autolink(link, link_type)
88 if link_type == :email
89 "<a rel=\"nofollow\" href=\"mailto:#{link}\">#{link}</a>"
91 "<a rel=\"nofollow\" href=\"#{link}\">#{link}</a>"
98 include ActionView::Helpers::TextHelper
101 linkify(simple_format(ERB::Util.html_escape(self)))