Support external links.

This commit is contained in:
Tom Preston-Werner
2010-07-20 22:44:39 -05:00
parent 8221bd6321
commit 9e917e235a
2 changed files with 15 additions and 4 deletions
+8 -4
View File
@@ -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.
+7
View File
@@ -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)