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) +
66 def simple_format(text)
67 SimpleFormat.new.simple_format(text)
71 Sanitize.clean(text, Sanitize::Config::OSM).html_safe
74 def linkify(text, mode = :urls)
76 Rinku.auto_link(text, mode, tag_builder.tag_options(:rel => "nofollow noopener noreferrer")).html_safe
78 Rinku.auto_link(text, mode, tag_builder.tag_options(:rel => "nofollow noopener noreferrer"))
85 linkify(sanitize(simple_format(self)))
95 linkify(sanitize(document.to_html), :all)
103 @image_element = first_image_element(document.root) unless defined? @image_element
104 @image_element.attr["src"] if @image_element
108 @image_element = first_image_element(document.root) unless defined? @image_element
109 @image_element.attr["alt"] if @image_element
113 @paragraph_element = first_paragraph_element(document.root) unless defined? @paragraph_element
114 text_content(@paragraph_element) if @paragraph_element
120 @document ||= Kramdown::Document.new(self)
123 def first_image_element(element)
124 return element if image?(element) && element.attr["src"].present?
126 element.children.find do |child|
127 nested_image = first_image_element(child)
128 break nested_image if nested_image
132 def first_paragraph_element(element)
133 return element if paragraph?(element)
135 element.children.find do |child|
136 nested_paragraph = first_paragraph_element(child)
137 break nested_paragraph if nested_paragraph
141 def text_content(element)
144 append_text = lambda do |child|
145 if child.type == :text
148 child.children.each { |c| append_text.call(c) }
151 append_text.call(element)
157 element.type == :img || (element.type == :html_element && element.value == "img")
160 def paragraph?(element)
167 linkify(simple_format(ERB::Util.html_escape(self)))