Merge branch 'mediawiki_fixups' of https://github.com/qmx/gollum into qmx-mediawiki_fixups
This commit is contained in:
+22
-17
@@ -13,6 +13,7 @@ module Gollum
|
||||
@name = page.filename
|
||||
@data = page.text_data
|
||||
@version = page.version.id
|
||||
@format = page.format
|
||||
@dir = ::File.dirname(page.path)
|
||||
@tagmap = {}
|
||||
@codemap = {}
|
||||
@@ -294,24 +295,28 @@ module Gollum
|
||||
# Returns the String HTML if the tag is a valid page link tag or nil
|
||||
# if it is not.
|
||||
def process_page_link_tag(tag, no_follow = false)
|
||||
parts = tag.split('|')
|
||||
name = parts[0].strip
|
||||
cname = @wiki.page_class.cname((parts[1] || parts[0]).strip)
|
||||
tag = if name =~ %r{^https?://} && parts[1].nil?
|
||||
%{<a href="#{name}">#{name}</a>}
|
||||
else
|
||||
presence = "absent"
|
||||
link_name = cname
|
||||
page, extra = find_page_from_name(cname)
|
||||
if page
|
||||
link_name = @wiki.page_class.cname(page.name)
|
||||
presence = "present"
|
||||
end
|
||||
link = ::File.join(@wiki.base_path, CGI.escape(link_name))
|
||||
%{<a class="internal #{presence}" href="#{link}#{extra}">#{name}</a>}
|
||||
end
|
||||
parts = if @format == :mediawiki
|
||||
tag.split('|').reverse
|
||||
else
|
||||
tag.split('|')
|
||||
end
|
||||
name, page_name = *parts.compact.map(&:strip)
|
||||
cname = @wiki.page_class.cname(page_name || name)
|
||||
tag = if name =~ %r{^https?://} && page_name.nil?
|
||||
%{<a href="#{name}">#{name}</a>}
|
||||
else
|
||||
presence = "absent"
|
||||
link_name = cname
|
||||
page, extra = find_page_from_name(cname)
|
||||
if page
|
||||
link_name = @wiki.page_class.cname(page.name)
|
||||
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
|
||||
tag.sub! /^<a/, '<a ref="nofollow"'
|
||||
tag.sub! /^<a/, '<a rel="nofollow"'
|
||||
end
|
||||
tag
|
||||
end
|
||||
|
||||
@@ -162,6 +162,20 @@ context "Markup" do
|
||||
assert_equal "<p>a <a href=\"http://example.com\">http://example.com</a> b</p>", page.formatted_data
|
||||
end
|
||||
|
||||
test "page link with different text" do
|
||||
@wiki.write_page("Potato", :markdown, "a [[Potato Heaad|Potato]] ", commit_details)
|
||||
page = @wiki.page("Potato")
|
||||
output = page.formatted_data
|
||||
assert_equal "<p>a <a class=\"internal present\" href=\"/Potato\">Potato Heaad</a></p>", output
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user