From bd1d44493f559039c877203ffb52add57b47d732 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 29 Nov 2017 03:17:08 -0500 Subject: [PATCH] Upgrade pygments to v1.x (#5937) Merge pull request 5937 --- Gemfile | 2 +- lib/jekyll/tags/highlight.rb | 4 ++-- test/test_redcarpet.rb | 13 +++++++------ test/test_tags.rb | 23 ++++++++++++++--------- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Gemfile b/Gemfile index 2ba32da7..8590544e 100644 --- a/Gemfile +++ b/Gemfile @@ -81,7 +81,7 @@ group :jekyll_optional_dependencies do platform :ruby, :mswin, :mingw, :x64_mingw do gem "classifier-reborn", "~> 2.1.0" gem "liquid-c", "~> 3.0" - gem "pygments.rb", "~> 0.6.0" + gem "pygments.rb", "~> 1.0" gem "rdiscount", "~> 2.0" gem "redcarpet", "~> 3.2", ">= 3.2.3" gem "yajl-ruby", "~> 1.2" diff --git a/lib/jekyll/tags/highlight.rb b/lib/jekyll/tags/highlight.rb index 683e3b2b..256342c3 100644 --- a/lib/jekyll/tags/highlight.rb +++ b/lib/jekyll/tags/highlight.rb @@ -86,7 +86,7 @@ MSG end def render_pygments(code, is_safe) - Jekyll::External.require_with_graceful_fail("pygments") + Jekyll::External.require_with_graceful_fail("pygments") unless defined?(Pygments) highlighted_code = Pygments.highlight( code, @@ -118,7 +118,7 @@ MSG :gutter_class => "gutter", :code_class => "code" ) - lexer = Rouge::Lexer.find_fancy(@lang, code) || Rouge::Lexers::PlainText + lexer = ::Rouge::Lexer.find_fancy(@lang, code) || Rouge::Lexers::PlainText formatter.format(lexer.lex(code)) end diff --git a/test/test_redcarpet.rb b/test/test_redcarpet.rb index f4208570..29d787ae 100644 --- a/test/test_redcarpet.rb +++ b/test/test_redcarpet.rb @@ -46,16 +46,17 @@ class TestRedcarpet < JekyllUnitTest end should "render fenced code blocks with syntax highlighting" do - assert_equal "
puts "Hello world"\n
", - @markdown.convert( - <<-EOS + assert_equal \ + "
puts "Hello world"\n
", + @markdown.convert( + <<-EOS ```ruby puts "Hello world" ``` EOS - ).strip + ).strip end end diff --git a/test/test_tags.rb b/test/test_tags.rb index 43d83464..a76f0df1 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -185,7 +185,8 @@ CONTENT should "render markdown with pygments" do assert_match( - %(
test
), + %(
) +
+          %(test
), @result ) end @@ -193,7 +194,7 @@ CONTENT should "render markdown with pygments with line numbers" do assert_match( %(
) +
-          %(1 test
), + %(1 test), @result ) end @@ -206,7 +207,7 @@ CONTENT should "not embed the file" do assert_match( - %(
) +
+          %(
) +
           %(./jekyll.gemspec
), @result ) @@ -220,7 +221,8 @@ CONTENT should "render markdown with pygments line handling" do assert_match( - %(
Æ
), + %(
) +
+          %(Æ
), @result ) end @@ -240,7 +242,8 @@ EOS should "only strip the preceding newlines" do assert_match( - %(
     [,1] [,2]),
+          %(
) +
+          %(     [,1] [,2]),
           @result
         )
       end
@@ -265,8 +268,8 @@ EOS
 
       should "only strip the newlines which precede and succeed the entire block" do
         assert_match(
-          "
" \
-          "     [,1] [,2]\n\n\n[1,] FALSE TRUE\n[2,] FALSE TRUE
", + %(
) +
+          %(     [,1] [,2]\n\n\n[1,] FALSE TRUE\n[2,] FALSE TRUE
), @result ) end @@ -280,7 +283,8 @@ EOS should "only strip the preceding newlines" do assert_match( - %(
     [,1] [,2]),
+          %(
) +
+          %(     [,1] [,2]),
           @result
         )
       end
@@ -298,7 +302,8 @@ EOS
 
       should "only strip the preceding newlines" do
         assert_match(
-          %(
     [,1] [,2]),
+          %(
) +
+          %(     [,1] [,2]),
           @result
         )
       end