helpers: prevent some texts to be incorrectly detected as links

Users were having issues with texts like:

> Pour info: penser à faire cette action.

where `info:` was detected as being an URI.
This commit is contained in:
Pierre de La Morinerie 2020-06-22 12:42:10 +00:00
parent 9cb2510b29
commit af5b36ea6a
2 changed files with 14 additions and 3 deletions

View file

@ -1,7 +1,7 @@
module StringToHtmlHelper
def string_to_html(str, wrapper_tag = 'p')
html_formatted = simple_format(str, {}, { wrapper_tag: wrapper_tag })
with_links = html_formatted.gsub(URI.regexp, '<a target="_blank" rel="noopener" href="\0">\0</a>')
with_links = Anchored::Linker.auto_link(html_formatted, target: '_blank', rel: 'noopener')
sanitize(with_links, attributes: ['target', 'rel', 'href'])
end
end