Remove links in code, fixes #128.
This commit is contained in:
+13
-1
@@ -53,8 +53,11 @@ module Gollum
|
||||
end
|
||||
data = process_tags(data)
|
||||
data = process_code(data, encoding)
|
||||
if sanitize || block_given?
|
||||
|
||||
doc = Nokogiri::HTML::DocumentFragment.parse(data)
|
||||
doc = remove_links_in_code(doc)
|
||||
|
||||
if sanitize || block_given?
|
||||
doc = sanitize.clean_node!(doc) if sanitize
|
||||
yield doc if block_given?
|
||||
data = doc.to_html
|
||||
@@ -353,6 +356,15 @@ module Gollum
|
||||
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
|
||||
|
||||
+14
-1
@@ -173,7 +173,20 @@ context "Markup" do
|
||||
@wiki.write_page("Potato", :mediawiki, "a [[Potato|Potato Heaad]] ", commit_details)
|
||||
page = @wiki.page("Potato")
|
||||
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
|
||||
|
||||
#########################################################################
|
||||
|
||||
Reference in New Issue
Block a user