Drop support for older versions of Rouge (#6978)

Merge pull request 6978
This commit is contained in:
Ashwin Maroli 2018-05-03 19:33:55 +05:30 committed by jekyllbot
parent acdbf81476
commit f8dfbd2f7b
9 changed files with 10 additions and 73 deletions

View File

@ -16,8 +16,6 @@ matrix:
env: TEST_SUITE=fmt env: TEST_SUITE=fmt
- rvm: *ruby1 - rvm: *ruby1
env: TEST_SUITE=default-site env: TEST_SUITE=default-site
- rvm: *ruby1
env: ROUGE_VERSION=1.11.1 # runs everything with this version
exclude: exclude:
- rvm: *jruby - rvm: *jruby
env: TEST_SUITE=cucumber env: TEST_SUITE=cucumber

View File

@ -5,8 +5,6 @@ gemspec :name => "jekyll"
gem "rake", "~> 12.0" gem "rake", "~> 12.0"
gem "rouge", ENV["ROUGE"] if ENV["ROUGE"]
group :development do group :development do
gem "launchy", "~> 2.3" gem "launchy", "~> 2.3"
gem "pry" gem "pry"

View File

@ -40,7 +40,6 @@ Gem::Specification.new do |s|
s.add_runtime_dependency("liquid", "~> 4.0") s.add_runtime_dependency("liquid", "~> 4.0")
s.add_runtime_dependency("mercenary", "~> 0.3.3") s.add_runtime_dependency("mercenary", "~> 0.3.3")
s.add_runtime_dependency("pathutil", "~> 0.9") s.add_runtime_dependency("pathutil", "~> 0.9")
rouge_versions = ENV["ROUGE_VERSION"] ? ["~> #{ENV["ROUGE_VERSION"]}"] : [">= 1.7", "< 4"] s.add_runtime_dependency("rouge", "~> 3.0")
s.add_runtime_dependency("rouge", *rouge_versions)
s.add_runtime_dependency("safe_yaml", "~> 1.0") s.add_runtime_dependency("safe_yaml", "~> 1.0")
end end

View File

@ -57,7 +57,8 @@ class Jekyll::Converters::Markdown::RedcarpetParser
protected protected
def rouge_formatter(_lexer) def rouge_formatter(_lexer)
Jekyll::Utils::Rouge.html_formatter(:wrap => false) require "rouge"
::Rouge::Formatters::HTMLLegacy.new(:wrap => false)
end end
end end

View File

@ -112,7 +112,8 @@ MSG
end end
def render_rouge(code) def render_rouge(code)
formatter = Jekyll::Utils::Rouge.html_formatter( require "rouge"
formatter = ::Rouge::Formatters::HTMLLegacy.new(
:line_numbers => @highlight_options[:linenos], :line_numbers => @highlight_options[:linenos],
:wrap => false, :wrap => false,
:css_class => "highlight", :css_class => "highlight",

View File

@ -7,7 +7,6 @@ module Jekyll
autoload :Exec, "jekyll/utils/exec" autoload :Exec, "jekyll/utils/exec"
autoload :Internet, "jekyll/utils/internet" autoload :Internet, "jekyll/utils/internet"
autoload :Platforms, "jekyll/utils/platforms" autoload :Platforms, "jekyll/utils/platforms"
autoload :Rouge, "jekyll/utils/rouge"
autoload :ThreadEvent, "jekyll/utils/thread_event" autoload :ThreadEvent, "jekyll/utils/thread_event"
autoload :WinTZ, "jekyll/utils/win_tz" autoload :WinTZ, "jekyll/utils/win_tz"

View File

@ -1,22 +0,0 @@
# frozen_string_literal: true
Jekyll::External.require_with_graceful_fail("rouge")
module Jekyll
module Utils
module Rouge
def self.html_formatter(*args)
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

View File

@ -20,7 +20,7 @@ class TestKramdown < JekyllUnitTest
"bold_every" => 8, "bold_every" => 8,
"css" => :class, "css" => :class,
"css_class" => "highlight", "css_class" => "highlight",
"formatter" => Jekyll::Utils::Rouge.html_formatter.class, "formatter" => Rouge::Formatters::HTMLLegacy,
}, },
}, },
} }
@ -91,8 +91,7 @@ class TestKramdown < JekyllUnitTest
puts "Hello World" puts "Hello World"
~~~ ~~~
MARKDOWN MARKDOWN
div_highlight = "" div_highlight = ">div.highlight"
div_highlight = ">div.highlight" unless Utils::Rouge.old_api?
selector = "div.highlighter-rouge#{div_highlight}>pre.highlight>code" selector = "div.highlighter-rouge#{div_highlight}>pre.highlight>code"
refute result.css(selector).empty? refute result.css(selector).empty?
end end

View File

@ -323,8 +323,7 @@ EOS
) )
end end
should "render markdown with rouge 2 with line numbers" do should "render markdown with rouge with line numbers" do
skip "Skipped because using an older version of Rouge" if Utils::Rouge.old_api?
assert_match( assert_match(
%(<table class="rouge-table"><tbody>) + %(<table class="rouge-table"><tbody>) +
%(<tr><td class="gutter gl">) + %(<tr><td class="gutter gl">) +
@ -334,18 +333,6 @@ EOS
@result @result
) )
end end
should "render markdown with rouge 1 with line numbers" do
skip "Skipped because using a newer version of Rouge" unless Utils::Rouge.old_api?
assert_match(
%(<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>),
@result
)
end
end end
context "post content has raw tag" do context "post content has raw tag" do
@ -364,18 +351,7 @@ CONTENT
create_post(content) create_post(content)
end end
should "render markdown with rouge 1" do should "render markdown with rouge" do
skip "Skipped because using a newer version of Rouge" unless Utils::Rouge.old_api?
assert_match(
%(<div class="language-liquid highlighter-rouge"><pre class="highlight"><code>),
@result
)
end
should "render markdown with rouge 2" do
skip "Skipped because using an older version of Rouge" if Utils::Rouge.old_api?
assert_match( assert_match(
%(<div class="language-liquid highlighter-rouge">) + %(<div class="language-liquid highlighter-rouge">) +
%(<div class="highlight"><pre class="highlight"><code>), %(<div class="highlight"><pre class="highlight"><code>),
@ -471,24 +447,12 @@ This should not be highlighted, right?
EOS EOS
end end
should "should stop highlighting at boundary with rouge 2" do should "should stop highlighting at boundary with rouge" do
skip "Skipped because using an older version of Rouge" if Utils::Rouge.old_api?
expected = <<-EOS expected = <<-EOS
<p>This is not yet highlighted</p>\n <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 <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 </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> <p>This should not be highlighted, right?</p>
EOS
assert_match(expected, @result)
end
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">
</span></pre></td></tr></tbody></table></code></pre></figure>\n
<p>This should not be highlighted, right?</p>
EOS EOS
assert_match(expected, @result) assert_match(expected, @result)
end end