diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index a02d8aa0..170d95c4 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -459,11 +459,12 @@ 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 - id = Digest::SHA1.hexdigest("#{$2}.#{$3}") + lang = $2 ? $2.strip : nil + id = Digest::SHA1.hexdigest("#{lang}.#{$3}") cached = check_cache(:code, id) @codemap[id] = cached ? { :output => cached } : - { :lang => $2, :code => $3, :indent => $1 } + { :lang => lang, :code => $3, :indent => $1 } "#{$1}#{id}" # print the SHA1 ID with the proper indentation end data diff --git a/test/test_markup.rb b/test/test_markup.rb index 6a406cd9..cfd78fd2 100644 --- a/test/test_markup.rb +++ b/test/test_markup.rb @@ -478,6 +478,20 @@ np.array([[2,2],[1,3]],np.float) assert_markup_highlights_code Gollum::Markup, rendered end + test "code with trailing whitespace" do + content = <<-END +shoop da woop + +``` python +np.array([[2,2],[1,3]],np.float) +``` + END + + # rendered with Gollum::Markup + page, rendered = render_page(content) + assert_markup_highlights_code Gollum::Markup, rendered + end + def assert_markup_highlights_code(markup_class, rendered) assert_match /div class="highlight"/, rendered, "#{markup_class} doesn't highlight code\n #{rendered}" assert_match /span class="n"/, rendered, "#{markup_class} doesn't highlight code\n #{rendered}"