Merge pull request #3002 from jekyll/liquid-3
This commit is contained in:
		
						commit
						38309569c4
					
				|  | @ -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 | ||||
|  |  | |||
|  | @ -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 | ||||
| 
 | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue