diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb
index b05b13a5..b1010138 100644
--- a/lib/gollum/markup.rb
+++ b/lib/gollum/markup.rb
@@ -267,14 +267,24 @@ module Gollum
if name =~ %r{^https?://} && parts[1].nil?
%{#{name}}
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
- %{#{name}}
+ link = ::File.join(@wiki.base_path, CGI.escape(link_name))
+ %{#{name}}
+ 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
diff --git a/test/test_markup.rb b/test/test_markup.rb
index c8c7a3d3..54d12684 100644
--- a/test/test_markup.rb
+++ b/test/test_markup.rb
@@ -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)