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 ||= Redcarpet::Render::XHTML.new({
86 :filter_html => true, :safe_links_only => true, :link_attributes => { :rel => "nofollow" }
88 @@html_parser ||= Redcarpet::Markdown.new(@@html_renderer, {
89 :no_intra_emphasis => true, :autolink => true, :space_after_headers => true
96 linkify(simple_format(ERB::Util.html_escape(self)))