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:
parent
05abc34ea4
commit
49e016ba58
2 changed files with 23 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue