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 html_parser.render(self).html_safe
85 @@html_renderer ||= Renderer.new(:filter_html => true, :safe_links_only => true)
86 @@html_parser ||= Redcarpet::Markdown.new(@@html_renderer, :no_intra_emphasis => true, :autolink => true, :space_after_headers => true)
89 class Renderer < Redcarpet::Render::XHTML
90 def link(link, _title, alt_text)
91 "<a rel=\"nofollow\" href=\"#{link}\">#{alt_text}</a>"
94 def autolink(link, link_type)
95 if link_type == :email
96 "<a rel=\"nofollow\" href=\"mailto:#{link}\">#{link}</a>"
98 "<a rel=\"nofollow\" href=\"#{link}\">#{link}</a>"
106 linkify(simple_format(ERB::Util.html_escape(self)))