Remove links in code, fixes #128.

This commit is contained in:
Jonathan Roes
2012-05-11 22:49:26 -04:00
parent c428cad286
commit eb37b17486
2 changed files with 30 additions and 5 deletions
+14 -2
View File
@@ -53,9 +53,12 @@ module Gollum
end end
data = process_tags(data) data = process_tags(data)
data = process_code(data, encoding) data = process_code(data, encoding)
doc = Nokogiri::HTML::DocumentFragment.parse(data)
doc = remove_links_in_code(doc)
if sanitize || block_given? if sanitize || block_given?
doc = Nokogiri::HTML::DocumentFragment.parse(data) doc = sanitize.clean_node!(doc) if sanitize
doc = sanitize.clean_node!(doc) if sanitize
yield doc if block_given? yield doc if block_given?
data = doc.to_html data = doc.to_html
end end
@@ -353,6 +356,15 @@ module Gollum
end end
end end
def remove_links_in_code(doc)
doc.css('code > a').each do |link|
link.before("[[#{link.content}]]")
link.remove
end
doc
end
######################################################################### #########################################################################
# #
# Code # Code
+14 -1
View File
@@ -173,7 +173,20 @@ context "Markup" do
@wiki.write_page("Potato", :mediawiki, "a [[Potato|Potato Heaad]] ", commit_details) @wiki.write_page("Potato", :mediawiki, "a [[Potato|Potato Heaad]] ", commit_details)
page = @wiki.page("Potato") page = @wiki.page("Potato")
output = page.formatted_data output = page.formatted_data
assert_equal normal("<p>\na <a class=\"internal present\" href=\"/Potato\">Potato Heaad</a> </p>"), normal(output) assert_equal normal("<p>\na <a class=\"internal present\" href=\"/Potato\">Potato Heaad</a> </p>
"), normal(output)
end
test "wiki link within inline code block" do
@wiki.write_page("Potato", :markdown, "`sed -i '' 's/[[:space:]]*$//'`", commit_details)
page = @wiki.page("Potato")
assert_equal "<p><code>sed -i '' 's/[[:space:]]*$//'</code></p>", page.formatted_data
end
test "wiki link within code block" do
@wiki.write_page("Potato", :markdown, " sed -i '' 's/[[:space:]]*$//'", commit_details)
page = @wiki.page("Potato")
assert_equal "<pre><code>sed -i '' 's/[[:space:]]*$//'\n</code></pre>", page.formatted_data
end end
######################################################################### #########################################################################