Strip code indents (two spaces or one tab) if present.

This commit is contained in:
Tom Preston-Werner
2010-07-29 21:45:17 -04:00
parent 076194a34d
commit f23d093d6f
2 changed files with 20 additions and 1 deletions
+4 -1
View File
@@ -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
+16
View File
@@ -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 = "<p>a</p>\n\n<div class=\"highlight\"><pre>" +
"<span class=\"n\">x</span> <span class=\"o\">=</span> " +
"<span class=\"mi\">1</span>\n</pre>\n</div>\n\n<p>b</p>"
compare(content, output)
end
test "code blocks with one-tab indent" do
content = "a\n\n```ruby\n\tx = 1\n```\n\nb"
output = "<p>a</p>\n\n<div class=\"highlight\"><pre>" +
"<span class=\"n\">x</span> <span class=\"o\">=</span> " +
"<span class=\"mi\">1</span>\n</pre>\n</div>\n\n<p>b</p>"
compare(content, output)
end
test "escaped wiki link" do
content = "a '[[Foo]], b"
output = "<p>a [[Foo]], b</p>"