mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	Switch to Pygments.rb
This commit is contained in:
		| @@ -1,4 +1,4 @@ | ||||
| require 'albino' | ||||
| require 'pygments' | ||||
| require 'yaml' | ||||
|  | ||||
| module Linguist | ||||
| @@ -55,16 +55,6 @@ module Linguist | ||||
|       end | ||||
|     end | ||||
|  | ||||
|     # Internal: Test if system has Pygments | ||||
|     # | ||||
|     # Only used in tests to disable tests that require Pygments. | ||||
|     # | ||||
|     # Returns true if `pygmentize` in is PATH otherwise false. | ||||
|     def self.has_pygments? | ||||
|       `which #{Albino.bin}` | ||||
|       $?.success? | ||||
|     end | ||||
|  | ||||
|     # Public: Get all Lexers | ||||
|     # | ||||
|     # Returns an Array of Lexers | ||||
| @@ -141,7 +131,7 @@ module Linguist | ||||
|     # | ||||
|     # Returns html String | ||||
|     def colorize(text) | ||||
|       Albino.new(text, self).colorize(:O => 'stripnl=false') | ||||
|       Pygments.highlight(text, :lexer => aliases.first, :options => {:stripnl => false}) | ||||
|     end | ||||
|  | ||||
|     # Public: Highlight syntax of text without the outer highlight div | ||||
|   | ||||
| @@ -6,8 +6,8 @@ Gem::Specification.new do |s| | ||||
|   s.files = Dir['lib/**/*'] | ||||
|   s.executables << 'linguist' | ||||
|  | ||||
|   s.add_dependency 'albino',       '1.3.2' | ||||
|   s.add_dependency 'escape_utils', '0.2.3' | ||||
|   s.add_dependency 'mime-types',   '1.16' | ||||
|   s.add_dependency 'pygments.rb' | ||||
|   s.add_development_dependency 'rake' | ||||
| end | ||||
|   | ||||
| @@ -380,7 +380,6 @@ class TestBlob < Test::Unit::TestCase | ||||
|     assert_equal nil, blob("foo.rb").shebang_language | ||||
|   end | ||||
|  | ||||
|   if Lexer.has_pygments? | ||||
|   def test_colorize | ||||
|     assert_equal <<-HTML, blob("foo.rb").colorize | ||||
| <div class="highlight"><pre><span class="k">module</span> <span class="nn">Foo</span> | ||||
| @@ -396,5 +395,4 @@ class TestBlob < Test::Unit::TestCase | ||||
| <span class="k">end</span> | ||||
|     HTML | ||||
|   end | ||||
|   end | ||||
| end | ||||
|   | ||||
| @@ -296,7 +296,6 @@ class TestLanguage < Test::Unit::TestCase | ||||
|   end | ||||
|  | ||||
|  | ||||
|   if Lexer.has_pygments? | ||||
|   def test_colorize | ||||
|     assert_equal <<-HTML, Language['Text'].colorize("Hello") | ||||
| <div class="highlight"><pre>Hello | ||||
| @@ -334,5 +333,4 @@ Hello | ||||
| <span class="k">end</span> | ||||
|     HTML | ||||
|   end | ||||
|   end | ||||
| end | ||||
|   | ||||
| @@ -61,7 +61,6 @@ class TestLexer < Test::Unit::TestCase | ||||
|     assert !Lexer['Ruby'].eql?(Lexer.new('Ruby')) | ||||
|   end | ||||
|  | ||||
|   if Lexer.has_pygments? | ||||
|   def test_colorize | ||||
|     assert_equal <<-HTML, Lexer['Text only'].colorize("Hello") | ||||
| <div class="highlight"><pre>Hello | ||||
| @@ -89,5 +88,4 @@ Hello | ||||
| <span class="k">end</span> | ||||
|     HTML | ||||
|   end | ||||
|   end | ||||
| end | ||||
|   | ||||
		Reference in New Issue
	
	Block a user