Skip to content
Snippets Groups Projects
Verified Commit b337f701 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Remove pygments.rb

parent 8a2ce36e
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -23,12 +23,6 @@ Linguist::FileBlob.new("bin/linguist").language.name #=> "Ruby"
 
See [lib/linguist/language.rb](https://github.com/github/linguist/blob/master/lib/linguist/language.rb) and [lib/linguist/languages.yml](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml).
 
### Syntax Highlighting
The actual syntax highlighting is handled by our Pygments wrapper, [pygments.rb](https://github.com/tmm1/pygments.rb). It also provides a [Lexer abstraction](https://github.com/tmm1/pygments.rb/blob/master/lib/pygments/lexer.rb) that determines which highlighter should be used on a file.
We typically run on a pre-release version of Pygments, [pygments.rb](https://github.com/tmm1/pygments.rb), to get early access to new lexers. The [languages.yml](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml) file is a dump of the lexers we have available on our server.
### Stats
 
The Language Graph you see on every repository is built by aggregating the languages of all repo's blobs. The top language in the graph determines the project's primary language. Collectively, these stats make up the [Top Languages](https://github.com/languages) page.
Loading
Loading
Loading
Loading
@@ -13,7 +13,6 @@ Gem::Specification.new do |s|
s.add_dependency 'charlock_holmes', '~> 0.6.6'
s.add_dependency 'escape_utils', '~> 0.2.4'
s.add_dependency 'mime-types', '~> 1.19'
s.add_dependency 'gitlab-pygments.rb', '~> 0.5.4'
s.add_development_dependency 'mocha'
s.add_development_dependency 'json'
s.add_development_dependency 'rake'
Loading
Loading
Loading
Loading
@@ -4,7 +4,6 @@ require 'linguist/language'
require 'charlock_holmes'
require 'escape_utils'
require 'mime/types'
require 'pygments'
require 'yaml'
 
module Linguist
Loading
Loading
@@ -189,10 +188,6 @@ module Linguist
 
# Public: Is the blob safe to colorize?
#
# We use Pygments for syntax highlighting blobs. Pygments
# can be too slow for very large blobs or for certain
# corner-case blobs.
#
# Return true or false
def safe_to_colorize?
!large? && text? && !high_ratio_of_long_lines?
Loading
Loading
@@ -200,9 +195,6 @@ module Linguist
 
# Internal: Does the blob have a ratio of long lines?
#
# These types of files are usually going to make Pygments.rb
# angry if we try to colorize them.
#
# Return true or false
def high_ratio_of_long_lines?
return false if loc == 0
Loading
Loading
@@ -298,7 +290,7 @@ module Linguist
#
# Returns a Lexer.
def lexer
language ? language.lexer : Pygments::Lexer.find_by_name('Text only')
language ? language.lexer : nil
end
 
# Public: Highlight syntax of blob
Loading
Loading
require 'escape_utils'
require 'pygments'
require 'yaml'
 
require 'linguist/classifier'
Loading
Loading
@@ -235,10 +234,6 @@ module Linguist
# Set aliases
@aliases = [default_alias_name] + (attributes[:aliases] || [])
 
# Lookup Lexer object
@lexer = Pygments::Lexer.find_by_name(attributes[:lexer] || name) ||
raise(ArgumentError, "#{@name} is missing lexer")
@ace_mode = attributes[:ace_mode]
@wrap = attributes[:wrap] || false
 
Loading
Loading
@@ -426,7 +421,7 @@ module Linguist
#
# Returns html String
def colorize(text, options = {})
lexer.highlight(text, options = {})
text
end
 
# Public: Return name as String representation
Loading
Loading
Loading
Loading
@@ -4,13 +4,10 @@ require 'linguist/samples'
require 'test/unit'
require 'mocha/setup'
require 'mime/types'
require 'pygments'
 
class TestBlob < Test::Unit::TestCase
include Linguist
 
Lexer = Pygments::Lexer
def samples_path
File.expand_path("../../samples", __FILE__)
end
Loading
Loading
@@ -318,25 +315,4 @@ class TestBlob < Test::Unit::TestCase
assert_equal sample[:language], blob.language.name, blob.name
end
end
def test_lexer
assert_equal Lexer['Ruby'], blob("Ruby/foo.rb").lexer
end
def test_colorize
assert_equal <<-HTML.chomp, blob("Ruby/foo.rb").colorize
<div class="highlight"><pre><span class="k">module</span> <span class="nn">Foo</span>
<span class="k">end</span>
</pre></div>
HTML
end
def test_colorize_does_skip_minified_files
assert_nil blob("JavaScript/jquery-1.6.1.min.js").colorize
end
# Pygments.rb was taking exceeding long on this particular file
def test_colorize_doesnt_blow_up_with_files_with_high_ratio_of_long_lines
assert_nil blob("JavaScript/steelseries-min.js").colorize
end
end
require 'linguist/language'
 
require 'test/unit'
require 'pygments'
 
class TestLanguage < Test::Unit::TestCase
include Linguist
 
Lexer = Pygments::Lexer
def test_lexer
assert_equal Lexer['ActionScript 3'], Language['ActionScript'].lexer
assert_equal Lexer['Bash'], Language['Gentoo Ebuild'].lexer
assert_equal Lexer['Bash'], Language['Gentoo Eclass'].lexer
assert_equal Lexer['Bash'], Language['Shell'].lexer
assert_equal Lexer['C'], Language['OpenCL'].lexer
assert_equal Lexer['C'], Language['XS'].lexer
assert_equal Lexer['C++'], Language['C++'].lexer
assert_equal Lexer['Coldfusion HTML'], Language['ColdFusion'].lexer
assert_equal Lexer['Coq'], Language['Coq'].lexer
assert_equal Lexer['FSharp'], Language['F#'].lexer
assert_equal Lexer['FSharp'], Language['F#'].lexer
assert_equal Lexer['Fortran'], Language['FORTRAN'].lexer
assert_equal Lexer['Gherkin'], Language['Cucumber'].lexer
assert_equal Lexer['Groovy'], Language['Groovy'].lexer
assert_equal Lexer['HTML'], Language['HTML'].lexer
assert_equal Lexer['HTML+Django/Jinja'], Language['HTML+Django'].lexer
assert_equal Lexer['HTML+PHP'], Language['HTML+PHP'].lexer
assert_equal Lexer['HTTP'], Language['HTTP'].lexer
assert_equal Lexer['JSON'], Language['JSON'].lexer
assert_equal Lexer['Java'], Language['ChucK'].lexer
assert_equal Lexer['Java'], Language['Java'].lexer
assert_equal Lexer['JavaScript'], Language['JavaScript'].lexer
assert_equal Lexer['MOOCode'], Language['Moocode'].lexer
assert_equal Lexer['MuPAD'], Language['mupad'].lexer
assert_equal Lexer['NASM'], Language['Assembly'].lexer
assert_equal Lexer['OCaml'], Language['OCaml'].lexer
assert_equal Lexer['Ooc'], Language['ooc'].lexer
assert_equal Lexer['OpenEdge ABL'], Language['OpenEdge ABL'].lexer
assert_equal Lexer['REBOL'], Language['Rebol'].lexer
assert_equal Lexer['RHTML'], Language['HTML+ERB'].lexer
assert_equal Lexer['RHTML'], Language['RHTML'].lexer
assert_equal Lexer['Ruby'], Language['Mirah'].lexer
assert_equal Lexer['Ruby'], Language['Ruby'].lexer
assert_equal Lexer['S'], Language['R'].lexer
assert_equal Lexer['Scheme'], Language['Emacs Lisp'].lexer
assert_equal Lexer['Scheme'], Language['Nu'].lexer
assert_equal Lexer['Racket'], Language['Racket'].lexer
assert_equal Lexer['Scheme'], Language['Scheme'].lexer
assert_equal Lexer['Standard ML'], Language['Standard ML'].lexer
assert_equal Lexer['TeX'], Language['TeX'].lexer
assert_equal Lexer['Verilog'], Language['Verilog'].lexer
assert_equal Lexer['XSLT'], Language['XSLT'].lexer
assert_equal Lexer['aspx-vb'], Language['ASP'].lexer
assert_equal Lexer['haXe'], Language['Haxe'].lexer
assert_equal Lexer['reStructuredText'], Language['reStructuredText'].lexer
end
def test_find_by_alias
assert_equal Language['ASP'], Language.find_by_alias('asp')
assert_equal Language['ASP'], Language.find_by_alias('aspx')
Loading
Loading
@@ -337,14 +286,4 @@ class TestLanguage < Test::Unit::TestCase
assert Language['Ruby'].eql?(Language['Ruby'])
assert !Language['Ruby'].eql?(Language['Python'])
end
def test_colorize
assert_equal <<-HTML.chomp, Language['Ruby'].colorize("def foo\n 'foo'\nend\n")
<div class="highlight"><pre><span class="k">def</span> <span class="nf">foo</span>
<span class="s1">&#39;foo&#39;</span>
<span class="k">end</span>
</pre></div>
HTML
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment