Merge pull request #8820 from colinux/fix-autolink-renderer

Fix: autolink manuellement les liens qui ne sont pas des urls
This commit is contained in:
Colin Darie 2023-03-29 12:23:31 +00:00 committed by Paul Chavard
commit f274748acd
2 changed files with 23 additions and 3 deletions

View file

@ -23,9 +23,14 @@ module Redcarpet
end
def autolink(link, link_type)
return super unless link_type == :url
link(link, nil, link)
case link_type
when :url
link(link, nil, link)
when :email
content_tag(:a, link, { href: "mailto:#{link}" })
else
link
end
end
# rubocop:enable Rails/ContentTag

View file

@ -58,6 +58,8 @@ TEXT
let(:text) do
<<~TEXT
bonjour https://www.demarches-simplifiees.fr
nohttp www.ds.io
ecrivez à ds@rspec.io
TEXT
end
@ -69,6 +71,19 @@ TEXT
expect(link[:rel]).to eq("noopener noreferrer")
expect(link[:title]).to eq("Nouvel onglet")
end
it "convert email autolinks" do
link = page.find_link("ds@rspec.io").native
expect(link[:href]).to eq("mailto:ds@rspec.io")
expect(link[:rel]).to be_nil
end
it "convert www only" do
link = page.find_link("www.ds.io").native
expect(link[:href]).to eq("http://www.ds.io")
expect(link[:rel]).to eq("noopener noreferrer")
expect(link[:title]).to eq("Nouvel onglet")
end
end
context 'disabled' do