Module: Helios::Press::ApplicationHelper
- Defined in:
- app/helpers/helios/press/application_helper.rb
Instance Method Summary collapse
-
#helios_press_process_rich_text_links(rich_text_content) ⇒ Object
Processes ActionText content to add target=“_blank” to external links.
Instance Method Details
#helios_press_process_rich_text_links(rich_text_content) ⇒ Object
Processes ActionText content to add target=“_blank” to external links
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/helpers/helios/press/application_helper.rb', line 5 def helios_press_process_rich_text_links(rich_text_content) return "" if rich_text_content.blank? html = rich_text_content.to_s doc = Nokogiri::HTML.fragment(html) doc.css("a").each do |link| href = link["href"] next if href.blank? if helios_press_external_link?(href) link["target"] = "_blank" link["rel"] = "noopener noreferrer" end end doc.to_html.html_safe end |