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

Strip content of the {% highlight %} block. #1823

Merged
merged 2 commits into from
Apr 3, 2014
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/jekyll/tags/highlight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ def initialize(tag_name, markup, tokens)
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)
Expand Down Expand Up @@ -106,8 +107,9 @@ def render_codehighlighter(context, code)

def add_code_tags(code, lang)
# Add nested <code> tags to code blocks
code = code.sub(/<pre>/,'<pre><code class="' + lang.to_s.gsub("+", "-") + '">')
code = code.sub(/<\/pre>/,"</code></pre>")
code = code.sub(/<pre>\n*/,'<pre><code class="' + lang.to_s.gsub("+", "-") + '">')
code = code.sub(/\n*<\/pre>/,"</code></pre>")
code.strip
end

end
Expand Down
2 changes: 1 addition & 1 deletion test/test_generated_site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TestGeneratedSite < Test::Unit::TestCase
end

should "ensure post count is as expected" do
assert_equal 40, @site.posts.size
assert_equal 41, @site.posts.size
end

should "insert site.posts into the index" do
Expand Down
16 changes: 10 additions & 6 deletions test/test_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ def fill_post(code, override = {})

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
Expand Down Expand Up @@ -87,11 +91,11 @@ def fill_post(code, override = {})
end

should "render markdown with pygments" do
assert_match %{<pre><code class="text">test\n</code></pre>}, @result
assert_match %{<pre><code class="text">test</code></pre>}, @result
end

should "render markdown with pygments with line numbers" do
assert_match %{<pre><code class="text"><span class="lineno">1</span> test\n</code></pre>}, @result
assert_match %{<pre><code class="text"><span class="lineno">1</span> test</code></pre>}, @result
end
end

Expand All @@ -101,7 +105,7 @@ def fill_post(code, override = {})
end

should "not embed the file" do
assert_match %{<pre><code class="text">./jekyll.gemspec\n</code></pre>}, @result
assert_match %{<pre><code class="text">./jekyll.gemspec</code></pre>}, @result
end
end

Expand All @@ -111,7 +115,7 @@ def fill_post(code, override = {})
end

should "render markdown with pygments line handling" do
assert_match %{<pre><code class="text">Æ\n</code></pre>}, @result
assert_match %{<pre><code class="text">Æ</code></pre>}, @result
end
end

Expand Down