Support external links.
This commit is contained in:
@@ -184,7 +184,7 @@ module Gollum
|
||||
path = parts[1] && parts[1].strip
|
||||
path = if path && file = find_file(path)
|
||||
::File.join @wiki.base_path, file.path
|
||||
elsif path =~ /^https?:\/\/.+(jpg|png|gif|svg|bmp)$/
|
||||
elsif path =~ %r{^https?://}
|
||||
path
|
||||
else
|
||||
nil
|
||||
@@ -209,9 +209,13 @@ module Gollum
|
||||
parts = tag.split('|')
|
||||
name = parts[0].strip
|
||||
cname = Page.cname((parts[1] || parts[0]).strip)
|
||||
link = ::File.join(@wiki.base_path, cname)
|
||||
presence = @wiki.page(cname) ? "present" : "absent"
|
||||
%{<a class="internal #{presence}" href="#{link}">#{name}</a>}
|
||||
if name =~ %r{^https?://} && parts[1].nil?
|
||||
%{<a href="#{name}">#{name}</a>}
|
||||
else
|
||||
link = ::File.join(@wiki.base_path, cname)
|
||||
presence = @wiki.page(cname) ? "present" : "absent"
|
||||
%{<a class="internal #{presence}" href="#{link}">#{name}</a>}
|
||||
end
|
||||
end
|
||||
|
||||
# Find the given file in the repo.
|
||||
|
||||
@@ -63,6 +63,13 @@ context "Markup" do
|
||||
end
|
||||
end
|
||||
|
||||
test "external page link" do
|
||||
@wiki.write_page("Bilbo Baggins", :markdown, "a [[http://example.com]] b", @commit)
|
||||
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
assert_equal "<p>a <a href=\"http://example.com\">http://example.com</a> b</p>", page.formatted_data
|
||||
end
|
||||
|
||||
test "image with http url" do
|
||||
['http', 'https'].each do |scheme|
|
||||
@wiki.write_page("Bilbo Baggins", :markdown, "a [[#{scheme}://example.com/bilbo.jpg]] b", @commit)
|
||||
|
||||
Reference in New Issue
Block a user