From b92274b101abe67ade60bf78f5ce439334f105e8 Mon Sep 17 00:00:00 2001 From: Kevin Ushey Date: Fri, 9 Jan 2015 00:07:11 -0800 Subject: [PATCH 1/3] only strip newlines when rendering highlight blocks (#3265) --- lib/jekyll/tags/highlight.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/tags/highlight.rb b/lib/jekyll/tags/highlight.rb index b51712b6..e1ed4e54 100644 --- a/lib/jekyll/tags/highlight.rb +++ b/lib/jekyll/tags/highlight.rb @@ -42,7 +42,7 @@ eos def render(context) prefix = context["highlighter_prefix"] || "" suffix = context["highlighter_suffix"] || "" - code = super.to_s.strip + code = super.to_s.gsub(/^\n+|\n+$/, '') is_safe = !!context.registers[:site].safe From cae9d96cc4ba43ae188a033f247e3dc58fcbf499 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Fri, 9 Jan 2015 23:51:34 -0800 Subject: [PATCH 2/3] Add test for stripping just newlines from code blocks. Ref #3275. --- test/test_tags.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/test_tags.rb b/test/test_tags.rb index bc4b48cd..eb547750 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -174,6 +174,21 @@ CONTENT end end + context "post content has highlight tag with preceding spaces" do + setup do + fill_post <<-EOS + + [,1] [,2] +[1,] FALSE TRUE +[2,] FALSE TRUE +EOS + end + + should "only strip the preceding newlines" do + assert_match %{
     [,1] [,2]}, @result
+    end
+  end
+
   context "simple post with markdown and pre tags" do
     setup do
       @content = <
Date: Fri, 9 Jan 2015 23:55:47 -0800
Subject: [PATCH 3/3] Add support for Windows line feeds too.

---
 lib/jekyll/tags/highlight.rb |  2 +-
 test/test_tags.rb            | 27 ++++++++++++++++++++++++++-
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/lib/jekyll/tags/highlight.rb b/lib/jekyll/tags/highlight.rb
index e1ed4e54..0305f1cf 100644
--- a/lib/jekyll/tags/highlight.rb
+++ b/lib/jekyll/tags/highlight.rb
@@ -42,7 +42,7 @@ eos
       def render(context)
         prefix = context["highlighter_prefix"] || ""
         suffix = context["highlighter_suffix"] || ""
-        code = super.to_s.gsub(/^\n+|\n+$/, '')
+        code = super.to_s.gsub(/^(\n|\r)+|(\n|\r)+$/, '')
 
         is_safe = !!context.registers[:site].safe
 
diff --git a/test/test_tags.rb b/test/test_tags.rb
index eb547750..c910d12b 100644
--- a/test/test_tags.rb
+++ b/test/test_tags.rb
@@ -174,10 +174,35 @@ CONTENT
     end
   end
 
-  context "post content has highlight tag with preceding spaces" do
+  context "post content has highlight tag with preceding spaces & lines" do
     setup do
       fill_post <<-EOS
 
+
+     [,1] [,2]
+[1,] FALSE TRUE
+[2,] FALSE TRUE
+EOS
+    end
+
+    should "only strip the preceding newlines" do
+      assert_match %{
     [,1] [,2]}, @result
+    end
+  end
+
+  context "post content has highlight tag with preceding spaces & Windows-style newlines" do
+    setup do
+      fill_post "\r\n\r\n\r\n     [,1] [,2]"
+    end
+
+    should "only strip the preceding newlines" do
+      assert_match %{
     [,1] [,2]}, @result
+    end
+  end
+
+  context "post content has highlight tag with only preceding spaces" do
+    setup do
+      fill_post <<-EOS
      [,1] [,2]
 [1,] FALSE TRUE
 [2,] FALSE TRUE