fixed mediawiki link handling

This commit is contained in:
Douglas Campos
2011-01-11 23:57:22 -02:00
parent e4103e6181
commit 2dbb4e9fa7
2 changed files with 28 additions and 16 deletions
+21 -16
View File
@@ -13,6 +13,7 @@ module Gollum
@name = page.filename @name = page.filename
@data = page.text_data @data = page.text_data
@version = page.version.id @version = page.version.id
@format = page.format
@dir = ::File.dirname(page.path) @dir = ::File.dirname(page.path)
@tagmap = {} @tagmap = {}
@codemap = {} @codemap = {}
@@ -294,22 +295,26 @@ module Gollum
# Returns the String HTML if the tag is a valid page link tag or nil # Returns the String HTML if the tag is a valid page link tag or nil
# if it is not. # if it is not.
def process_page_link_tag(tag, no_follow = false) def process_page_link_tag(tag, no_follow = false)
parts = tag.split('|') parts = if @format == :mediawiki
name = parts[0].strip tag.split('|').reverse
cname = @wiki.page_class.cname((parts[1] || parts[0]).strip) else
tag = if name =~ %r{^https?://} && parts[1].nil? tag.split('|')
%{<a href="#{name}">#{name}</a>} end
else name, page_name = *parts.compact.map(&:strip)
presence = "absent" cname = @wiki.page_class.cname(page_name || name)
link_name = cname tag = if name =~ %r{^https?://} && page_name.nil?
page, extra = find_page_from_name(cname) %{<a href="#{name}">#{name}</a>}
if page else
link_name = @wiki.page_class.cname(page.name) presence = "absent"
presence = "present" link_name = cname
end page, extra = find_page_from_name(cname)
link = ::File.join(@wiki.base_path, CGI.escape(link_name)) if page
%{<a class="internal #{presence}" href="#{link}#{extra}">#{name}</a>} link_name = @wiki.page_class.cname(page.name)
end presence = "present"
end
link = ::File.join(@wiki.base_path, CGI.escape(link_name))
%{<a class="internal #{presence}" href="#{link}#{extra}">#{name}</a>}
end
if tag && no_follow if tag && no_follow
tag.sub! /^<a/, '<a ref="nofollow"' tag.sub! /^<a/, '<a ref="nofollow"'
end end
+7
View File
@@ -169,6 +169,13 @@ context "Markup" do
assert_equal "<p>a <a class=\"internal present\" href=\"/Potato\">Potato Heaad</a></p>", output assert_equal "<p>a <a class=\"internal present\" href=\"/Potato\">Potato Heaad</a></p>", output
end end
test "page link with different text on mediawiki" do
@wiki.write_page("Potato", :mediawiki, "a [[Potato|Potato Heaad]] ", commit_details)
page = @wiki.page("Potato")
output = page.formatted_data
assert_equal "<p>\na <a class=\"internal present\" href=\"/Potato\">Potato Heaad</a> \n</p>", output
end
######################################################################### #########################################################################
# #
# Images # Images