3 "Business Description:", "Additional Keywords:"
6 def self.new(format, text)
8 when "html" then HTML.new(text || "")
9 when "markdown" then Markdown.new(text || "")
10 when "text" then Text.new(text || "")
15 include ActionView::Helpers::TextHelper
16 include ActionView::Helpers::OutputSafetyHelper
18 def sanitize(text, _options = {})
19 Sanitize.clean(text, Sanitize::Config::OSM).html_safe
24 include ActionView::Helpers::TagHelper
30 doc = Nokogiri::HTML(to_html)
35 doc.xpath("//a").each do |link|
37 link_size += link.content.length
40 link_proportion = link_size.to_f / doc.content.length
43 spammy_phrases = SPAMMY_PHRASES.count do |phrase|
44 doc.content.include?(phrase)
47 ([link_proportion - 0.2, 0.0].max * 200) +
58 def simple_format(text)
59 SimpleFormat.new.simple_format(text)
63 Sanitize.clean(text, Sanitize::Config::OSM).html_safe
66 def linkify(text, mode = :urls)
68 Rinku.auto_link(text, mode, tag_builder.tag_options(:rel => "nofollow noopener noreferrer")).html_safe
70 Rinku.auto_link(text, mode, tag_builder.tag_options(:rel => "nofollow noopener noreferrer"))
77 linkify(sanitize(simple_format(self)))
87 linkify(sanitize(document.to_html), :all)
95 return @image if defined? @image
97 @image = first_image_element(document.root)&.attr&.[]("src")
103 @document ||= Kramdown::Document.new(self)
106 def first_image_element(element)
107 return element if image?(element) && element.attr["src"].present?
109 element.children.find do |child|
110 nested_image = first_image_element(child)
111 break nested_image if nested_image
116 element.type == :img || (element.type == :html_element && element.value == "img")
122 linkify(simple_format(ERB::Util.html_escape(self)))