Files
nairobi/app/helpers/text_with_links_helper.rb
Javi Martín 2aabf79fb4 Rename methods to add auto links to HTML
The name `safe_html_with_links` was confusing and could make you think
it takes care of making the HTML safe. So I've renamed it in a way that
makes it a bit more intuitive that it expects its input to be already
sanitized.

I've changed `text_with_links` as well so now the two method names
complement each other.
2019-10-08 18:46:20 +02:00

21 lines
603 B
Ruby

module TextWithLinksHelper
def sanitize_and_auto_link(text)
return unless text
sanitized = sanitize(text, tags: [], attributes: [])
Rinku.auto_link(sanitized, :all, 'target="_blank" rel="nofollow"').html_safe
end
def auto_link_already_sanitized_html(html)
return if html.nil?
html = ActiveSupport::SafeBuffer.new(html) if html.is_a?(String)
return html.html_safe unless html.html_safe?
Rinku.auto_link(html, :all, 'target="_blank" rel="nofollow"').html_safe
end
def simple_format_no_tags_no_sanitize(html)
simple_format(html, {}, sanitize: false)
end
end