diff --git a/.travis.yml b/.travis.yml index 587ca6f3..00e21f93 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,8 @@ rvm: matrix: include: + - rvm: *ruby1 + env: TEST_SUITE=test ROUGE=1.11.1 - rvm: *ruby1 env: TEST_SUITE=fmt - rvm: *ruby1 diff --git a/Gemfile b/Gemfile index 0dcb4776..216c2626 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,8 @@ gemspec :name => "jekyll" gem "rake", "~> 12.0" +gem "rouge", ENV["ROUGE"] if ENV["ROUGE"] + # Dependency of jekyll-mentions. RubyGems in Ruby 2.1 doesn't shield us from this. gem "activesupport", "~> 4.2", :groups => [:test_legacy, :site] if RUBY_VERSION < "2.2.2" @@ -71,7 +73,7 @@ group :jekyll_optional_dependencies do gem "jekyll-gist" gem "jekyll-paginate" gem "jekyll-redirect-from" - gem "kramdown", "~> 1.9" + gem "kramdown", "~> 1.14" gem "mime-types", "~> 3.0" gem "rdoc", "~> 5.0" gem "toml", "~> 0.1.0" diff --git a/jekyll.gemspec b/jekyll.gemspec index 87031a80..606d09da 100644 --- a/jekyll.gemspec +++ b/jekyll.gemspec @@ -35,10 +35,11 @@ Gem::Specification.new do |s| s.add_runtime_dependency("colorator", "~> 1.0") s.add_runtime_dependency("jekyll-sass-converter", "~> 1.0") s.add_runtime_dependency("jekyll-watch", "~> 1.1") - s.add_runtime_dependency("kramdown", "~> 1.3") + s.add_runtime_dependency("kramdown", "~> 1.14") s.add_runtime_dependency("liquid", "~> 4.0") s.add_runtime_dependency("mercenary", "~> 0.3.3") s.add_runtime_dependency("pathutil", "~> 0.9") - s.add_runtime_dependency("rouge", "~> #{ENV["ROUGE_VERSION"] || "1.7"}") + rouge_versions = ENV["ROUGE_VERSION"] ? ["~> #{ENV["ROUGE_VERSION"]}"] : [">= 1.7", "< 3"] + s.add_runtime_dependency("rouge", *rouge_versions) s.add_runtime_dependency("safe_yaml", "~> 1.0") end diff --git a/lib/jekyll/converters/markdown/redcarpet_parser.rb b/lib/jekyll/converters/markdown/redcarpet_parser.rb index fae09621..35c6e5fe 100644 --- a/lib/jekyll/converters/markdown/redcarpet_parser.rb +++ b/lib/jekyll/converters/markdown/redcarpet_parser.rb @@ -55,7 +55,7 @@ class Jekyll::Converters::Markdown::RedcarpetParser protected def rouge_formatter(_lexer) - Rouge::Formatters::HTML.new(:wrap => false) + Jekyll::Utils::Rouge.html_formatter(:wrap => false) end end diff --git a/lib/jekyll/tags/highlight.rb b/lib/jekyll/tags/highlight.rb index 7ea95b0b..687f9b71 100644 --- a/lib/jekyll/tags/highlight.rb +++ b/lib/jekyll/tags/highlight.rb @@ -111,10 +111,12 @@ eos end def render_rouge(code) - Jekyll::External.require_with_graceful_fail("rouge") - formatter = Rouge::Formatters::HTML.new( + formatter = Jekyll::Utils::Rouge.html_formatter( :line_numbers => @highlight_options[:linenos], - :wrap => false + :wrap => false, + :css_class => "highlight", + :gutter_class => "gutter", + :code_class => "code" ) lexer = Rouge::Lexer.find_fancy(@lang, code) || Rouge::Lexers::PlainText formatter.format(lexer.lex(code)) diff --git a/lib/jekyll/utils.rb b/lib/jekyll/utils.rb index c9dcf2fd..70605a34 100644 --- a/lib/jekyll/utils.rb +++ b/lib/jekyll/utils.rb @@ -7,6 +7,7 @@ module Jekyll autoload :Ansi, "jekyll/utils/ansi" autoload :Exec, "jekyll/utils/exec" autoload :Platforms, "jekyll/utils/platforms" + autoload :Rouge, "jekyll/utils/rouge" autoload :WinTZ, "jekyll/utils/win_tz" # Constants for use in #slugify diff --git a/lib/jekyll/utils/rouge.rb b/lib/jekyll/utils/rouge.rb new file mode 100644 index 00000000..a00a5f9e --- /dev/null +++ b/lib/jekyll/utils/rouge.rb @@ -0,0 +1,19 @@ +module Jekyll + module Utils + module Rouge + + def self.html_formatter(*args) + Jekyll::External.require_with_graceful_fail("rouge") + 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 diff --git a/test/test_kramdown.rb b/test/test_kramdown.rb index 3861416f..e1bf15a4 100644 --- a/test/test_kramdown.rb +++ b/test/test_kramdown.rb @@ -17,7 +17,10 @@ class TestKramdown < JekyllUnitTest "syntax_highlighter" => "rouge", "syntax_highlighter_opts" => { - "bold_every" => 8, "css" => :class, + "bold_every" => 8, + "css" => :class, + "css_class" => "highlight", + "formatter" => Jekyll::Utils::Rouge.html_formatter.class, }, }, } @@ -82,8 +85,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 diff --git a/test/test_tags.rb b/test/test_tags.rb index 7a60ec9d..8a7ed7d0 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -319,7 +319,20 @@ EOS ) end - should "render markdown with rouge with line numbers" do + should "render markdown with rouge 2 with line numbers" do + skip "Skipped because using an older version of Rouge" if Utils::Rouge.old_api? + assert_match( + %(
) +
+ %(1\n | ) +
+ %(test |
) +
@@ -331,6 +344,42 @@ EOS
end
end
+ context "post content has raw tag" do
+ setup do
+ content = <<-CONTENT
+---
+title: This is a test
+---
+
+```liquid
+{% raw %}
+{{ site.baseurl }}{% link _collection/name-of-document.md %}
+{% endraw %}
+```
+CONTENT
+ create_post(content)
+ end
+
+ should "render markdown with rouge 1" do
+ skip "Skipped because using a newer version of Rouge" unless Utils::Rouge.old_api?
+
+ assert_match(
+ %(
|
This should not be highlighted, right?
EOS assert_match(expected, @result)