Remove links in code, fixes #128.
This commit is contained in:
+14
-2
@@ -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
|
||||||
|
|||||||
+16
-3
@@ -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
|
||||||
|
|
||||||
#########################################################################
|
#########################################################################
|
||||||
@@ -598,11 +611,11 @@ np.array([[2,2],[1,3]],np.float)
|
|||||||
# Asciidoc
|
# Asciidoc
|
||||||
#########################################################################
|
#########################################################################
|
||||||
|
|
||||||
test "asciidoc header" do
|
test "asciidoc header" do
|
||||||
compare("= Book Title\n\n== Heading", '<div class="sect1"><h2 id="wiki-_heading">Heading</h2><div class="sectionbody"></div></div>', 'asciidoc')
|
compare("= Book Title\n\n== Heading", '<div class="sect1"><h2 id="wiki-_heading">Heading</h2><div class="sectionbody"></div></div>', 'asciidoc')
|
||||||
end
|
end
|
||||||
|
|
||||||
test "internal links with asciidoc" do
|
test "internal links with asciidoc" do
|
||||||
compare("= Book Title\n\n[[anid]]\n== Heading", '<div class="sect1"><h2 id="wiki-anid">Heading</h2><div class="sectionbody"></div></div>', 'asciidoc')
|
compare("= Book Title\n\n[[anid]]\n== Heading", '<div class="sect1"><h2 id="wiki-anid">Heading</h2><div class="sectionbody"></div></div>', 'asciidoc')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user