diff --git a/lib/jekyll/tags/highlight.rb b/lib/jekyll/tags/highlight.rb index b51712b6..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.strip + 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 bc4b48cd..c910d12b 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -174,6 +174,46 @@ CONTENT end end + 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
+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 = <