This commit is contained in:
bootstraponline
2012-10-13 14:50:08 -06:00
parent e16ae7b511
commit 6a765c9791
2 changed files with 30 additions and 0 deletions
+16
View File
@@ -511,6 +511,22 @@ module Gollum
#
# Returns the placeholder'd String 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
lang = $2 ? $2.strip : nil
id = Digest::SHA1.hexdigest("#{lang}.#{$3}")
+14
View File
@@ -212,6 +212,20 @@ context "Markup" do
assert_equal expected, output
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
@wiki.write_page("Potato", :markdown, " sed -i '' 's/[[:space:]]*$//'", commit_details)
page = @wiki.page("Potato")