fix: handle all autolinks manually

On ne peut pas appeler super() qui est en méthode en C, pas en ruby.
Donc on doit gérer manuellement les cas possibles.
This commit is contained in:
Colin Darie 2023-03-29 12:17:08 +02:00
parent 04b17e8299
commit 95315788f6
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
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
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