diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index f8e2cd62..64fe6b43 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -321,7 +321,7 @@ module Gollum @codemap.each do |id, spec| lang = spec[:lang] code = spec[:code] - if code.all? { |line| line =~ /^( |\t)/ } + if code.all? { |line| line =~ /\A\r?\n\Z/ || line =~ /^( |\t)/ } code.gsub!(/^( |\t)/m, '') end data.gsub!(id, Gollum::Albino.new(code, lang).colorize) diff --git a/test/test_markup.rb b/test/test_markup.rb index eaa4f4c8..e56d6851 100644 --- a/test/test_markup.rb +++ b/test/test_markup.rb @@ -271,18 +271,20 @@ context "Markup" do end test "code blocks with two-space indent" do - content = "a\n\n```ruby\n x = 1\n```\n\nb" - output = "
a
\n\n" +
- "x = " +
- "1\n\nb
" + content = "a\n\n```ruby\n x = 1\n\n y = 2\n```\n\nb" + output = "a
\n\n" +
+ "x = 1" +
+ "\n\ny =" +
+ " 2\n\nb
" compare(content, output) end test "code blocks with one-tab indent" do - content = "a\n\n```ruby\n\tx = 1\n```\n\nb" - output = "a
\n\n" +
- "x = " +
- "1\n\nb
" + content = "a\n\n```ruby\n\tx = 1\n\n\ty = 2\n```\n\nb" + output = "a
\n\n" +
+ "x = 1" +
+ "\n\ny =" +
+ " 2\n\nb
" compare(content, output) end