Fix #537
This commit is contained in:
@@ -511,6 +511,22 @@ module Gollum
|
|||||||
#
|
#
|
||||||
# Returns the placeholder'd String data.
|
# Returns the placeholder'd String data.
|
||||||
def extract_code(data)
|
def extract_code(data)
|
||||||
|
data.gsub!(/^([ \t]*)~~~ ?([^\r\n]+)?\r?\n(.+?)\r?\n\1~~~\r?$/m) do
|
||||||
|
m_indent = $1
|
||||||
|
m_lang = $2
|
||||||
|
m_code = $3
|
||||||
|
|
||||||
|
lang = m_lang ? m_lang.strip : nil
|
||||||
|
id = Digest::SHA1.hexdigest("#{lang}.#{m_code}")
|
||||||
|
cached = check_cache(:code, id)
|
||||||
|
|
||||||
|
@codemap[id] = cached ?
|
||||||
|
{ :output => cached } :
|
||||||
|
{ :lang => lang.gsub(/[{}\.]/, '').strip, :code => m_code, :indent => m_indent }
|
||||||
|
|
||||||
|
"#{m_indent}#{id}" # print the SHA1 ID with the proper indentation
|
||||||
|
end
|
||||||
|
|
||||||
data.gsub!(/^([ \t]*)``` ?([^\r\n]+)?\r?\n(.+?)\r?\n\1```\r?$/m) do
|
data.gsub!(/^([ \t]*)``` ?([^\r\n]+)?\r?\n(.+?)\r?\n\1```\r?$/m) do
|
||||||
lang = $2 ? $2.strip : nil
|
lang = $2 ? $2.strip : nil
|
||||||
id = Digest::SHA1.hexdigest("#{lang}.#{$3}")
|
id = Digest::SHA1.hexdigest("#{lang}.#{$3}")
|
||||||
|
|||||||
@@ -212,6 +212,20 @@ context "Markup" do
|
|||||||
assert_equal expected, output
|
assert_equal expected, output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "~~~ code blocks #537" do
|
||||||
|
# bug only triggers on "```" syntax
|
||||||
|
# not `code`
|
||||||
|
page = 'test_rgx'
|
||||||
|
@wiki.write_page(page, :markdown,
|
||||||
|
%Q(~~~ {.ruby}
|
||||||
|
'hi'
|
||||||
|
~~~
|
||||||
|
), commit_details)
|
||||||
|
output = @wiki.page(page).formatted_data
|
||||||
|
expected = %Q{<div class=\"highlight\"><pre><span class=\"s1\">'hi'</span>\n</pre></div>}
|
||||||
|
assert_equal expected, output
|
||||||
|
end
|
||||||
|
|
||||||
test "wiki link within code block" do
|
test "wiki link within code block" do
|
||||||
@wiki.write_page("Potato", :markdown, " sed -i '' 's/[[:space:]]*$//'", commit_details)
|
@wiki.write_page("Potato", :markdown, " sed -i '' 's/[[:space:]]*$//'", commit_details)
|
||||||
page = @wiki.page("Potato")
|
page = @wiki.page("Potato")
|
||||||
|
|||||||
Reference in New Issue
Block a user