Gollum::Markup uses Wiki#base_path when linking images/files
This commit is contained in:
@@ -94,12 +94,10 @@ module Gollum
|
||||
def process_image_tag(tag)
|
||||
parts = tag.split('|')
|
||||
name = parts[0].strip
|
||||
path = nil
|
||||
|
||||
if file = find_file(name)
|
||||
path = "/#{file.path}"
|
||||
path = if file = find_file(name)
|
||||
::File.join @wiki.base_path, file.path
|
||||
elsif name =~ /^https?:\/\/.+(jpg|png|gif|svg|bmp)$/
|
||||
path = name
|
||||
name
|
||||
end
|
||||
|
||||
if path
|
||||
@@ -186,7 +184,7 @@ module Gollum
|
||||
path = parts[1] && parts[1].strip
|
||||
|
||||
if name && path && file = find_file(path)
|
||||
%{<a href="/#{file.path}">#{name}</a>}
|
||||
%{<a href="#{::File.join @wiki.base_path, file.path}">#{name}</a>}
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
||||
+6
-4
@@ -60,25 +60,27 @@ context "Markup" do
|
||||
end
|
||||
|
||||
test "image with absolute path" do
|
||||
@wiki = Gollum::Wiki.new(@path, :base_path => '/wiki')
|
||||
index = @wiki.repo.index
|
||||
index.add("alpha.jpg", "hi")
|
||||
index.commit("Add alpha.jpg")
|
||||
@wiki.write_page("Bilbo Baggins", :markdown, "a [[/alpha.jpg]] b", @commit)
|
||||
@wiki.write_page("Bilbo Baggins", :markdown, "a [[/alpha.jpg]] [[a | /alpha.jpg]] b", @commit)
|
||||
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
output = Gollum::Markup.new(page).render
|
||||
assert_equal %{<p>a <img src="/alpha.jpg" /> b</p>}, output
|
||||
assert_equal %{<p>a <img src="/wiki/alpha.jpg" /> <a href="/wiki/alpha.jpg">a</a> b</p>}, output
|
||||
end
|
||||
|
||||
test "image with relative path" do
|
||||
@wiki = Gollum::Wiki.new(@path, :base_path => '/wiki')
|
||||
index = @wiki.repo.index
|
||||
index.add("greek/alpha.jpg", "hi")
|
||||
index.add("greek/Bilbo-Baggins.md", "a [[alpha.jpg]] b")
|
||||
index.add("greek/Bilbo-Baggins.md", "a [[alpha.jpg]] [[a | alpha.jpg]] b")
|
||||
index.commit("Add alpha.jpg")
|
||||
|
||||
page = @wiki.page("Bilbo Baggins")
|
||||
output = Gollum::Markup.new(page).render
|
||||
assert_equal %{<p>a <img src="/greek/alpha.jpg" /> b</p>}, output
|
||||
assert_equal %{<p>a <img src="/wiki/greek/alpha.jpg" /> <a href="/wiki/greek/alpha.jpg">a</a> b</p>}, output
|
||||
end
|
||||
|
||||
test "image with alt" do
|
||||
|
||||
Reference in New Issue
Block a user