Merge pull request #336 from jroes/remove-links-in-code
Remove links in code, fixes #128.
This commit is contained in:
+22
-3
@@ -53,9 +53,10 @@ module Gollum
|
||||
end
|
||||
data = process_tags(data)
|
||||
data = process_code(data, encoding)
|
||||
|
||||
if sanitize || block_given?
|
||||
doc = Nokogiri::HTML::DocumentFragment.parse(data)
|
||||
doc = sanitize.clean_node!(doc) if sanitize
|
||||
doc = Nokogiri::HTML::DocumentFragment.parse(data)
|
||||
doc = sanitize.clean_node!(doc) if sanitize
|
||||
yield doc if block_given?
|
||||
data = doc.to_html
|
||||
end
|
||||
@@ -153,11 +154,29 @@ module Gollum
|
||||
# Returns the marked up String data.
|
||||
def process_tags(data)
|
||||
@tagmap.each do |id, tag|
|
||||
data.gsub!(id, process_tag(tag))
|
||||
# If it's preformatted, just put the tag back
|
||||
if is_preformatted?(data, id)
|
||||
data.gsub!(id, "[[#{tag}]]")
|
||||
else
|
||||
data.gsub!(id, process_tag(tag))
|
||||
end
|
||||
end
|
||||
data
|
||||
end
|
||||
|
||||
# Find `id` within `data` and determine if it's within
|
||||
# preformatted tags.
|
||||
#
|
||||
# data - The String data (with placeholders).
|
||||
# id - The String SHA1 hash.
|
||||
PREFORMATTED_TAGS = %w(code tt)
|
||||
def is_preformatted?(data, id)
|
||||
doc = Nokogiri::HTML::DocumentFragment.parse(data)
|
||||
node = doc.search("[text()*='#{id}']").first
|
||||
node && (PREFORMATTED_TAGS.include?(node.name) ||
|
||||
node.ancestors.any? { |a| PREFORMATTED_TAGS.include?(a.name) })
|
||||
end
|
||||
|
||||
# Process a single tag into its final HTML form.
|
||||
#
|
||||
# tag - The String tag contents (the stuff inside the double
|
||||
|
||||
+22
-3
@@ -173,7 +173,26 @@ 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
|
||||
|
||||
test "piped wiki link within code block" do
|
||||
@wiki.write_page("Potato", :markdown, "`make a link [[home|sweet home]]`", commit_details)
|
||||
page = @wiki.page("Potato")
|
||||
assert_equal "<p><code>make a link [[home|sweet home]]</code></p>", page.formatted_data
|
||||
end
|
||||
|
||||
#########################################################################
|
||||
@@ -598,11 +617,11 @@ np.array([[2,2],[1,3]],np.float)
|
||||
# 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')
|
||||
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')
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user