From 6a765c9791e75c622c85a94d156d82241682266a Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Sat, 13 Oct 2012 14:50:08 -0600 Subject: [PATCH] Fix #537 --- lib/gollum/markup.rb | 16 ++++++++++++++++ test/test_markup.rb | 14 ++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index 300ec037..00bca913 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -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}") diff --git a/test/test_markup.rb b/test/test_markup.rb index 5250fd23..41e65394 100644 --- a/test/test_markup.rb +++ b/test/test_markup.rb @@ -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{
'hi'\n
} + 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")