From d24ea6693399b2d9b446dedb7cf1a452a0ea3c58 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 1 Feb 2015 22:37:10 -0800 Subject: [PATCH 1/2] The highlight tip should only clip the newlines before and after the *entire* block, not in between. Ref: https://github.com/jneen/rouge/issues/230 --- 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 adf6bcd7..5af5f2bd 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|\r)+|(\n|\r)+$/, '') + code = super.to_s.gsub(/\A(\n|\r)+|(\n|\r)+\z/, '') is_safe = !!context.registers[:site].safe From 32c48bb78d11087b04db3ce8404f094a2d06162b Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 1 Feb 2015 23:03:10 -0800 Subject: [PATCH 2/2] Highlight tag: add test for not removing interstitial newlines. --- test/test_tags.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/test_tags.rb b/test/test_tags.rb index 7b6b60f4..9fbd9e39 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -190,6 +190,26 @@ EOS end end + context "post content has highlight tag with preceding spaces & lines in several places" do + setup do + fill_post <<-EOS + + + [,1] [,2] + + +[1,] FALSE TRUE +[2,] FALSE TRUE + + +EOS + end + + should "only strip the newlines which precede and succeed the entire block" do + assert_match "
     [,1] [,2]\n\n\n[1,] FALSE TRUE\n[2,] FALSE TRUE
", @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]"