Add support for Windows line feeds too.

This commit is contained in:
Parker Moore 2015-01-09 23:55:47 -08:00
parent cae9d96cc4
commit 4cbd814546
2 changed files with 27 additions and 2 deletions

View File

@ -42,7 +42,7 @@ eos
def render(context) def render(context)
prefix = context["highlighter_prefix"] || "" prefix = context["highlighter_prefix"] || ""
suffix = context["highlighter_suffix"] || "" 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 is_safe = !!context.registers[:site].safe

View File

@ -174,10 +174,35 @@ CONTENT
end end
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 setup do
fill_post <<-EOS fill_post <<-EOS
[,1] [,2]
[1,] FALSE TRUE
[2,] FALSE TRUE
EOS
end
should "only strip the preceding newlines" do
assert_match %{<pre><code class=\"language-text\" data-lang=\"text\"> [,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 %{<pre><code class=\"language-text\" data-lang=\"text\"> [,1] [,2]}, @result
end
end
context "post content has highlight tag with only preceding spaces" do
setup do
fill_post <<-EOS
[,1] [,2] [,1] [,2]
[1,] FALSE TRUE [1,] FALSE TRUE
[2,] FALSE TRUE [2,] FALSE TRUE