From 38b870065158477c4c2d4c3c4e497a8456a10225 Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Thu, 29 Jul 2010 21:57:30 -0400 Subject: [PATCH] Code hilighter needs to handle blanks lines. --- lib/gollum/markup.rb | 2 +- test/test_markup.rb | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) 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
\n
\n\n

b

" + 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
\n
\n\n

b

" 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
\n
\n\n

b

" + 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
\n
\n\n

b

" compare(content, output) end