Commit cd3c24a8 authored by Robert Speicher's avatar Robert Speicher

Autolink short URLs

parent f4fac3ac
...@@ -52,7 +52,10 @@ module Gitlab ...@@ -52,7 +52,10 @@ module Gitlab
# NOTE: We don't parse email links because it will erroneously match # NOTE: We don't parse email links because it will erroneously match
# external Commit and CommitRange references. # external Commit and CommitRange references.
rinku = Rinku.auto_link(html, :urls, options, IGNORE_PARENTS.to_a) #
# The final argument tells Rinku to link short URLs that don't include a
# period (e.g., http://localhost:3000/)
rinku = Rinku.auto_link(html, :urls, options, IGNORE_PARENTS.to_a, 1)
# Rinku returns a String, so parse it back to a Nokogiri::XML::Document # Rinku returns a String, so parse it back to a Nokogiri::XML::Document
# for further processing. # for further processing.
......
...@@ -207,11 +207,9 @@ describe 'GitLab Markdown' do ...@@ -207,11 +207,9 @@ describe 'GitLab Markdown' do
expect(item(5).children.first['href']).to eq 'irc://irc.freenode.net/git' expect(item(5).children.first['href']).to eq 'irc://irc.freenode.net/git'
end end
# TODO (rspeicher): Do we really want this?
it 'autolinks short, invalid URLs' do it 'autolinks short, invalid URLs' do
skip 'rspeicher: Pending decision'
expect(item(6).children.first.name).to eq 'a' expect(item(6).children.first.name).to eq 'a'
expect(item(6).children.first['href']).to eq 'http://foo' expect(item(6).children.first['href']).to eq 'http://localhost:3000'
end end
%w(code a kbd).each do |elem| %w(code a kbd).each do |elem|
......
...@@ -41,6 +41,14 @@ module Gitlab::Markdown ...@@ -41,6 +41,14 @@ module Gitlab::Markdown
expect(doc.at_css('a')['href']).to eq link expect(doc.at_css('a')['href']).to eq link
end end
it 'autolinks short URLs' do
link = 'http://localhost:3000/'
doc = filter("See #{link}")
expect(doc.at_css('a').text).to eq link
expect(doc.at_css('a')['href']).to eq link
end
it 'accepts link_attr options' do it 'accepts link_attr options' do
doc = filter("See #{link}", link_attr: {class: 'custom'}) doc = filter("See #{link}", link_attr: {class: 'custom'})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment