Allow users to pass anchors to page links.
http://github.com/github/gollum/issues/\#issue/21
This commit is contained in:
+16
-6
@@ -267,14 +267,24 @@ module Gollum
|
|||||||
if name =~ %r{^https?://} && parts[1].nil?
|
if name =~ %r{^https?://} && parts[1].nil?
|
||||||
%{<a href="#{name}">#{name}</a>}
|
%{<a href="#{name}">#{name}</a>}
|
||||||
else
|
else
|
||||||
if page = @wiki.page(cname)
|
|
||||||
link = ::File.join(@wiki.base_path, CGI.escape(Page.cname(page.name)))
|
|
||||||
presence = "present"
|
|
||||||
else
|
|
||||||
link = ::File.join(@wiki.base_path, CGI.escape(cname))
|
|
||||||
presence = "absent"
|
presence = "absent"
|
||||||
|
link_name = cname
|
||||||
|
page, extra = find_page_from_name(cname)
|
||||||
|
if page
|
||||||
|
link_name = Page.cname(page.name)
|
||||||
|
presence = "present"
|
||||||
end
|
end
|
||||||
%{<a class="internal #{presence}" href="#{link}">#{name}</a>}
|
link = ::File.join(@wiki.base_path, CGI.escape(link_name))
|
||||||
|
%{<a class="internal #{presence}" href="#{link}#{extra}">#{name}</a>}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_page_from_name(cname)
|
||||||
|
if page = @wiki.page(cname)
|
||||||
|
return page
|
||||||
|
end
|
||||||
|
if pos = cname.index('#')
|
||||||
|
[@wiki.page(cname[0...pos]), cname[pos..-1]]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -95,6 +95,22 @@ context "Markup" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "page link with included #" do
|
||||||
|
@wiki.write_page("Precious #1", :markdown, "a [[Precious #1]] b", commit_details)
|
||||||
|
page = @wiki.page('Precious #1')
|
||||||
|
output = page.formatted_data
|
||||||
|
assert_match /class="internal present"/, output
|
||||||
|
assert_match /href="\/Precious-%231"/, output
|
||||||
|
end
|
||||||
|
|
||||||
|
test "page link with extra #" do
|
||||||
|
@wiki.write_page("Potato", :markdown, "a [[Potato#1]] b", commit_details)
|
||||||
|
page = @wiki.page('Potato')
|
||||||
|
output = page.formatted_data
|
||||||
|
assert_match /class="internal present"/, output
|
||||||
|
assert_match /href="\/Potato#1"/, output
|
||||||
|
end
|
||||||
|
|
||||||
test "external page link" do
|
test "external page link" do
|
||||||
@wiki.write_page("Bilbo Baggins", :markdown, "a [[http://example.com]] b", commit_details)
|
@wiki.write_page("Bilbo Baggins", :markdown, "a [[http://example.com]] b", commit_details)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user