Skip to content

Commit

Permalink
use Rouge::Formatters::HTMLLegacy and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Crunch09 committed Jun 18, 2017
1 parent 3bc8e49 commit 4f19427
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
10 changes: 5 additions & 5 deletions lib/jekyll/utils/rouge.rb
Expand Up @@ -4,16 +4,16 @@ module Rouge

def self.html_formatter(*args)
Jekyll::External.require_with_graceful_fail("rouge")
html_formatter = ::Rouge::Formatters::HTML.new(*args)
return html_formatter if old_api?

::Rouge::Formatters::HTMLPygments.new(html_formatter)
if old_api?
::Rouge::Formatters::HTML.new(*args)
else
::Rouge::Formatters::HTMLLegacy.new(*args)
end
end

def self.old_api?
::Rouge.version.to_s < "2"
end

end
end
end
5 changes: 3 additions & 2 deletions test/test_kramdown.rb
Expand Up @@ -62,8 +62,9 @@ class TestKramdown < JekyllUnitTest
puts "Hello World"
~~~
MARKDOWN

selector = "div.highlighter-rouge>pre.highlight>code"
div_highlight = ""
div_highlight = ">div.highlight" unless Utils::Rouge.old_api?
selector = "div.highlighter-rouge#{div_highlight}>pre.highlight>code"
refute result.css(selector).empty?
end

Expand Down
12 changes: 6 additions & 6 deletions test/test_tags.rb
Expand Up @@ -429,22 +429,22 @@ def highlight_block_with_opts(options_string)
EOS
end

should "should stop highlighting at boundary with rouge 1" do
should "should stop highlighting at boundary with rouge 2" do
skip "Skipped because using an older version of Rouge" if Utils::Rouge.old_api?
expected = <<-EOS
<p>This is not yet highlighted</p>
<figure class="highlight"><pre><code class="language-php" data-lang="php"><table style="border-spacing: 0"><tbody><tr><td class="gutter gl" style="text-align: right"><pre class="lineno">1</pre></td><td class="code"><pre>test<span class="w">
</span></pre></td></tr></tbody></table></code></pre></figure>
<p>This is not yet highlighted</p>\n
<figure class="highlight"><pre><code class="language-php" data-lang="php"><table class="rouge-table"><tbody><tr><td class="gutter gl"><pre class="lineno">1
</pre></td><td class="code"><pre><span class="nx">test</span></pre></td></tr></tbody></table></code></pre></figure>\n
<p>This should not be highlighted, right?</p>
EOS
assert_match(expected, @result)
end

should "should stop highlighting at boundary with rouge 2" do
should "should stop highlighting at boundary with rouge 1" do
skip "Skipped because using a newer version of Rouge" unless Utils::Rouge.old_api?
expected = <<-EOS
<p>This is not yet highlighted</p>\n
<figure class="highlight"><pre><code class="language-php" data-lang="php"><table style="border-spacing: 0"><tbody><tr><td class="gutter gl" style="text-align: right"><pre class="lineno">1</pre></td><td class="code"><pre>test<span class="w">
<figure class="highlight"><pre><code class="language-php" data-lang="php"><table style="border-spacing: 0"><tbody><tr><td class="gutter gl" style="text-align: right"><pre class="lineno">1</pre></td><td class="code"><pre>test<span class="w">\n
</span></pre></td></tr></tbody></table></code></pre></figure>\n
<p>This should not be highlighted, right?</p>
EOS
Expand Down

0 comments on commit 4f19427

Please sign in to comment.