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:
commit
f274748acd
2 changed files with 23 additions and 3 deletions
|
@ -23,9 +23,14 @@ module Redcarpet
|
||||||
end
|
end
|
||||||
|
|
||||||
def autolink(link, link_type)
|
def autolink(link, link_type)
|
||||||
return super unless link_type == :url
|
case link_type
|
||||||
|
when :url
|
||||||
link(link, nil, link)
|
link(link, nil, link)
|
||||||
|
when :email
|
||||||
|
content_tag(:a, link, { href: "mailto:#{link}" })
|
||||||
|
else
|
||||||
|
link
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# rubocop:enable Rails/ContentTag
|
# rubocop:enable Rails/ContentTag
|
||||||
|
|
|
@ -58,6 +58,8 @@ TEXT
|
||||||
let(:text) do
|
let(:text) do
|
||||||
<<~TEXT
|
<<~TEXT
|
||||||
bonjour https://www.demarches-simplifiees.fr
|
bonjour https://www.demarches-simplifiees.fr
|
||||||
|
nohttp www.ds.io
|
||||||
|
ecrivez à ds@rspec.io
|
||||||
TEXT
|
TEXT
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -69,6 +71,19 @@ TEXT
|
||||||
expect(link[:rel]).to eq("noopener noreferrer")
|
expect(link[:rel]).to eq("noopener noreferrer")
|
||||||
expect(link[:title]).to eq("Nouvel onglet")
|
expect(link[:title]).to eq("Nouvel onglet")
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context 'disabled' do
|
context 'disabled' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue