Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight: Only Strip Newlines/Carriage Returns, not Spaces #3278

Merged
merged 3 commits into from Jan 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/jekyll/tags/highlight.rb
Expand Up @@ -42,7 +42,7 @@ def initialize(tag_name, markup, tokens)
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

Expand Down
40 changes: 40 additions & 0 deletions test/test_tags.rb
Expand Up @@ -174,6 +174,46 @@ def highlight_block_with_opts(options_string)
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 %{<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,] 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 "simple post with markdown and pre tags" do
setup do
@content = <<CONTENT
Expand Down