demarches-normaliennes/app/helpers/string_to_html_helper.rb
Christophe Robillard 447612abdf fix a11y-8.9.1
no p tag when Champ text with no value
2022-02-02 19:03:40 +01:00

8 lines
343 B
Ruby

module StringToHtmlHelper
def string_to_html(str, wrapper_tag = 'p')
return nil if str.blank?
html_formatted = simple_format(str, {}, { wrapper_tag: wrapper_tag })
with_links = Anchored::Linker.auto_link(html_formatted, target: '_blank', rel: 'noopener')
sanitize(with_links, attributes: ['target', 'rel', 'href'])
end
end