diff --git a/lib/jekyll/tags/highlight.rb b/lib/jekyll/tags/highlight.rb index eb128d32..36c2211a 100644 --- a/lib/jekyll/tags/highlight.rb +++ b/lib/jekyll/tags/highlight.rb @@ -41,14 +41,15 @@ eos end def render(context) + code = super.to_s.strip case context.registers[:site].highlighter when 'pygments' - render_pygments(context, super) + render_pygments(context, code) when 'rouge' - render_rouge(context, super) + render_rouge(context, code) else - render_codehighlighter(context, super) - end + render_codehighlighter(context, code) + end.strip end def render_pygments(context, code) @@ -106,8 +107,9 @@ eos def add_code_tags(code, lang) # Add nested tags to code blocks - code = code.sub(/
/,'
')
-        code = code.sub(/<\/pre>/,"
") + code = code.sub(/
\n*/,'
')
+        code = code.sub(/\n*<\/pre>/,"
") + code.strip end end diff --git a/test/test_tags.rb b/test/test_tags.rb index a0a5c579..b71b6d98 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -33,8 +33,12 @@ title: This is a test This document results in a markdown error with maruku -{% highlight text %}#{code}{% endhighlight %} -{% highlight text linenos %}#{code}{% endhighlight %} +{% highlight text %} +#{code} +{% endhighlight %} +{% highlight text linenos %} +#{code} +{% endhighlight %} CONTENT create_post(content, override) end @@ -87,11 +91,11 @@ CONTENT end should "render markdown with pygments" do - assert_match %{
test\n
}, @result + assert_match %{
test
}, @result end should "render markdown with pygments with line numbers" do - assert_match %{
1 test\n
}, @result + assert_match %{
1 test
}, @result end end @@ -101,7 +105,7 @@ CONTENT end should "not embed the file" do - assert_match %{
./jekyll.gemspec\n
}, @result + assert_match %{
./jekyll.gemspec
}, @result end end @@ -111,7 +115,7 @@ CONTENT end should "render markdown with pygments line handling" do - assert_match %{
Æ\n
}, @result + assert_match %{
Æ
}, @result end end