Allow users to pass anchors to page links.
http://github.com/github/gollum/issues/\#issue/21
This commit is contained in:
+17
-7
@@ -267,14 +267,24 @@ module Gollum
|
||||
if name =~ %r{^https?://} && parts[1].nil?
|
||||
%{<a href="#{name}">#{name}</a>}
|
||||
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
|
||||
%{<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
|
||||
|
||||
|
||||
+17
-1
@@ -89,12 +89,28 @@ context "Markup" do
|
||||
|
||||
page = @wiki.page(name)
|
||||
output = page.formatted_data
|
||||
assert_match /class="internal present"/, output
|
||||
assert_match /class="internal present"/, output
|
||||
assert_match /href="\/wiki\/Bilbo-Baggins-\d"/, output
|
||||
assert_match /\>Bilbo Baggins \d\</, output
|
||||
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
|
||||
@wiki.write_page("Bilbo Baggins", :markdown, "a [[http://example.com]] b", commit_details)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user