diff --git a/jekyll.gemspec b/jekyll.gemspec index 4913951e..7d0a97fc 100644 --- a/jekyll.gemspec +++ b/jekyll.gemspec @@ -28,7 +28,7 @@ Gem::Specification.new do |s| s.rdoc_options = ['--charset=UTF-8'] s.extra_rdoc_files = %w[README.markdown LICENSE] - s.add_runtime_dependency('liquid', '~> 2.6.1') + s.add_runtime_dependency('liquid', '~> 3.0') s.add_runtime_dependency('kramdown', '~> 1.3') s.add_runtime_dependency('mercenary', '~> 0.3.3') s.add_runtime_dependency('safe_yaml', '~> 1.0') @@ -63,6 +63,7 @@ Gem::Specification.new do |s| s.add_development_dependency('jekyll_test_plugin') s.add_development_dependency('jekyll_test_plugin_malicious') s.add_development_dependency('rouge', '~> 1.7') + s.add_development_dependency('liquid-c', '~> 0.0.3') s.add_development_dependency('minitest') if RUBY_PLATFORM =~ /cygwin/ s.add_development_dependency('test-unit') if RUBY_PLATFORM =~ /cygwin/ end diff --git a/lib/jekyll.rb b/lib/jekyll.rb index 911b3ddb..bde11581 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -29,7 +29,14 @@ require 'liquid' require 'kramdown' require 'colorator' +# Conditional optimizations +begin + require 'liquid-c' +rescue LoadError +end + SafeYAML::OPTIONS[:suppress_warnings] = true +Liquid::Template.error_mode = :strict module Jekyll diff --git a/test/test_tags.rb b/test/test_tags.rb index a47ca897..bc4b48cd 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -43,6 +43,10 @@ CONTENT create_post(content, override) end + def highlight_block_with_opts(options_string) + Jekyll::Tags::HighlightBlock.parse('highlight', options_string, ["test", "{% endhighlight %}", "\n"], {}) + end + context "language name" do should "match only the required set of chars" do r = Jekyll::Tags::HighlightBlock::SYNTAX @@ -59,37 +63,51 @@ CONTENT end end - context "initialized tag" do - should "set the correct options" do - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby ', ["test", "{% endhighlight %}", "\n"]) + context "highlight tag in unsafe mode" do + should "set the no options with just a language name" do + tag = highlight_block_with_opts('ruby ') assert_equal({}, tag.instance_variable_get(:@options)) + end - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos ', ["test", "{% endhighlight %}", "\n"]) + should "set the linenos option as 'inline' if no linenos value" do + tag = highlight_block_with_opts('ruby linenos ') assert_equal({ :linenos => 'inline' }, tag.instance_variable_get(:@options)) + end - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table ', ["test", "{% endhighlight %}", "\n"]) + should "set the linenos option to 'table' if the linenos key is given the table value" do + tag = highlight_block_with_opts('ruby linenos=table ') assert_equal({ :linenos => 'table' }, tag.instance_variable_get(:@options)) + end - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table nowrap', ["test", "{% endhighlight %}", "\n"]) + should "recognize nowrap option with linenos set" do + tag = highlight_block_with_opts('ruby linenos=table nowrap ') assert_equal({ :linenos => 'table', :nowrap => true }, tag.instance_variable_get(:@options)) + end - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table cssclass=hl', ["test", "{% endhighlight %}", "\n"]) + should "recognize the cssclass option" do + tag = highlight_block_with_opts('ruby linenos=table cssclass=hl ') assert_equal({ :cssclass => 'hl', :linenos => 'table' }, tag.instance_variable_get(:@options)) + end - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table cssclass=hl hl_linenos=3', ["test", "{% endhighlight %}", "\n"]) + should "recognize the hl_linenos option and its value" do + tag = highlight_block_with_opts('ruby linenos=table cssclass=hl hl_linenos=3 ') assert_equal({ :cssclass => 'hl', :linenos => 'table', :hl_linenos => '3' }, tag.instance_variable_get(:@options)) + end - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table cssclass=hl hl_linenos="3 5 6"', ["test", "{% endhighlight %}", "\n"]) + should "recognize multiple values of hl_linenos" do + tag = highlight_block_with_opts('ruby linenos=table cssclass=hl hl_linenos="3 5 6" ') assert_equal({ :cssclass => 'hl', :linenos => 'table', :hl_linenos => ['3', '5', '6'] }, tag.instance_variable_get(:@options)) + end - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'Ruby ', ["test", "{% endhighlight %}", "\n"]) + should "treat language name as case insensitive" do + tag = highlight_block_with_opts('Ruby ') assert_equal "ruby", tag.instance_variable_get(:@lang), "lexers should be case insensitive" end end context "in safe mode" do setup do - @tag = Jekyll::Tags::HighlightBlock.new('highlight', 'text ', ["test", "{% endhighlight %}", "\n"]) + @tag = highlight_block_with_opts('text ') end should "allow linenos" do