From f23d093d6f7d9f1a697f586f752459872f41a8dc Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Thu, 29 Jul 2010 21:45:17 -0400 Subject: [PATCH] Strip code indents (two spaces or one tab) if present. --- lib/gollum/markup.rb | 5 ++++- test/test_markup.rb | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index a1dc714e..f8e2cd62 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -321,7 +321,10 @@ module Gollum @codemap.each do |id, spec| lang = spec[:lang] code = spec[:code] - data.sub!(id, Gollum::Albino.new(code, lang).colorize) + if code.all? { |line| line =~ /^( |\t)/ } + code.gsub!(/^( |\t)/m, '') + end + data.gsub!(id, Gollum::Albino.new(code, lang).colorize) end data end diff --git a/test/test_markup.rb b/test/test_markup.rb index c6c5d50c..eaa4f4c8 100644 --- a/test/test_markup.rb +++ b/test/test_markup.rb @@ -270,6 +270,22 @@ context "Markup" do assert_equal output, rendered 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

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

" + compare(content, output) + end + test "escaped wiki link" do content = "a '[[Foo]], b" output = "

a [[Foo]], b

"