Merge pull request #1823 from jekyll/highlight-without-newline
This commit is contained in:
		
						commit
						122b2233b1
					
				| 
						 | 
					@ -41,14 +41,15 @@ eos
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      def render(context)
 | 
					      def render(context)
 | 
				
			||||||
 | 
					        code = super.to_s.strip
 | 
				
			||||||
        case context.registers[:site].highlighter
 | 
					        case context.registers[:site].highlighter
 | 
				
			||||||
        when 'pygments'
 | 
					        when 'pygments'
 | 
				
			||||||
          render_pygments(context, super)
 | 
					          render_pygments(context, code)
 | 
				
			||||||
        when 'rouge'
 | 
					        when 'rouge'
 | 
				
			||||||
          render_rouge(context, super)
 | 
					          render_rouge(context, code)
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
          render_codehighlighter(context, super)
 | 
					          render_codehighlighter(context, code)
 | 
				
			||||||
        end
 | 
					        end.strip
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      def render_pygments(context, code)
 | 
					      def render_pygments(context, code)
 | 
				
			||||||
| 
						 | 
					@ -106,8 +107,9 @@ eos
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      def add_code_tags(code, lang)
 | 
					      def add_code_tags(code, lang)
 | 
				
			||||||
        # Add nested <code> tags to code blocks
 | 
					        # Add nested <code> tags to code blocks
 | 
				
			||||||
        code = code.sub(/<pre>/,'<pre><code class="' + lang.to_s.gsub("+", "-") + '">')
 | 
					        code = code.sub(/<pre>\n*/,'<pre><code class="' + lang.to_s.gsub("+", "-") + '">')
 | 
				
			||||||
        code = code.sub(/<\/pre>/,"</code></pre>")
 | 
					        code = code.sub(/\n*<\/pre>/,"</code></pre>")
 | 
				
			||||||
 | 
					        code.strip
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,8 +33,12 @@ title: This is a test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
This document results in a markdown error with maruku
 | 
					This document results in a markdown error with maruku
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{% highlight text %}#{code}{% endhighlight %}
 | 
					{% highlight text %}
 | 
				
			||||||
{% highlight text linenos %}#{code}{% endhighlight %}
 | 
					#{code}
 | 
				
			||||||
 | 
					{% endhighlight %}
 | 
				
			||||||
 | 
					{% highlight text linenos %}
 | 
				
			||||||
 | 
					#{code}
 | 
				
			||||||
 | 
					{% endhighlight %}
 | 
				
			||||||
CONTENT
 | 
					CONTENT
 | 
				
			||||||
    create_post(content, override)
 | 
					    create_post(content, override)
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
| 
						 | 
					@ -87,11 +91,11 @@ CONTENT
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    should "render markdown with pygments" do
 | 
					    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
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    should "render markdown with pygments with line numbers" do
 | 
					    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
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -101,7 +105,7 @@ CONTENT
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    should "not embed the file" do
 | 
					    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
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -111,7 +115,7 @@ CONTENT
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    should "render markdown with pygments line handling" do
 | 
					    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
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue