2018-05-24 18:01:40 +02:00
|
|
|
module StringToHtmlHelper
|
2023-02-03 15:17:12 +01:00
|
|
|
def string_to_html(str, wrapper_tag = 'p', allow_a: false)
|
2022-02-02 18:03:24 +01:00
|
|
|
return nil if str.blank?
|
2019-11-06 16:30:20 +01:00
|
|
|
html_formatted = simple_format(str, {}, { wrapper_tag: wrapper_tag })
|
2020-06-22 14:42:10 +02:00
|
|
|
with_links = Anchored::Linker.auto_link(html_formatted, target: '_blank', rel: 'noopener')
|
2023-02-03 15:17:12 +01:00
|
|
|
|
|
|
|
tags = if allow_a
|
|
|
|
Rails.configuration.action_view.sanitized_allowed_tags + ['a']
|
|
|
|
else
|
|
|
|
Rails.configuration.action_view.sanitized_allowed_tags
|
|
|
|
end
|
|
|
|
|
|
|
|
sanitize(with_links, tags:, attributes: ['target', 'rel', 'href'])
|
2018-05-24 18:01:40 +02:00
|
|
|
end
|
|
|
|
end
|