Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Replace Lexer with Pygments::Lexer

  • Loading branch information...
commit 0864b9847f38a8972b18276476c9f74f237320b7 1 parent bb11317
@josh josh authored
View
2  Gemfile
@@ -1,2 +1,4 @@
source :rubygems
gemspec
+
+gem 'pygments.rb', :git => 'git://github.com/tmm1/pygments.rb.git'
View
14 Rakefile
@@ -1,4 +1,3 @@
-require 'rake/clean'
require 'rake/testtask'
task :default => :test
@@ -6,16 +5,3 @@ task :default => :test
Rake::TestTask.new do |t|
t.warning = true
end
-
-CLOBBER.include 'lib/linguist/lexers.yml'
-
-file 'lib/linguist/lexers.yml' do |f|
- # GitHub vendored pygments path
- # vendor/python/pygments
- path = File.expand_path('../../../python/pygments', __FILE__)
- ENV['PYTHONPATH'] = path if File.directory?(path)
-
- sh "python ./bin/pygments-lexers > #{f.name}"
-end
-
-task :lexers => 'lib/linguist/lexers.yml'
View
27 bin/pygments-lexers
@@ -1,27 +0,0 @@
-#!/usr/bin/env python
-
-from pygments import __version__
-from pygments.lexers import get_all_lexers
-
-print "# AUTOMATICALLY GENERATED BY bin/pygments-lexers"
-print "# DO NOT MODIFIY. YOUR PULL WILL BE REJECTED."
-print "# Pygments version %s" % __version__
-print "---"
-
-for name, aliases, filenames, mimetypes in get_all_lexers():
- print "%s:" % name
-
- if any(aliases):
- print " aliases:"
- for alias in aliases:
- print " - '%s'" % alias
-
- if any(filenames):
- print " filenames:"
- for filename in filenames:
- print " - '%s'" % filename
-
- if any(mimetypes):
- print " mimetypes:"
- for mimetype in mimetypes:
- print " - '%s'" % mimetype
View
19 lib/linguist/blob_helper.rb
@@ -3,6 +3,7 @@
require 'linguist/pathname'
require 'escape_utils'
+require 'pygments'
require 'yaml'
module Linguist
@@ -343,7 +344,7 @@ def guess_language
#
# Returns a Lexer.
def lexer
- language ? language.lexer : Lexer['Text only']
+ language ? language.lexer : Pygments::Lexer.find_by_name('Text only')
end
# Internal: Disambiguates between multiple language extensions.
@@ -512,19 +513,27 @@ def shebang_language
# Public: Highlight syntax of blob
#
+ # options - A Hash of options (defaults to {})
+ #
# Returns html String
- def colorize
+ def colorize(options = {})
return if !text? || large?
- lexer.colorize(data)
+ lexer.highlight(data, options)
end
# Public: Highlight syntax of blob without the outer highlight div
# wrapper.
#
+ # options - A Hash of options (defaults to {})
+ #
# Returns html String
- def colorize_without_wrapper
+ def colorize_without_wrapper(options = {})
return if !text? || large?
- lexer.colorize_without_wrapper(data)
+ if text = lexer.highlight(data, options)
+ text[%r{<div class="highlight"><pre>(.*?)</pre>\s*</div>}m, 1]
+ else
+ ''
+ end
end
Language.overridden_extensions.each do |extension|
View
22 lib/linguist/language.rb
@@ -1,6 +1,5 @@
-require 'linguist/lexer'
-
require 'yaml'
+require 'pygments'
module Linguist
# Language names that are recognizable by GitHub. Defined languages
@@ -211,7 +210,7 @@ def initialize(attributes = {})
@aliases = [default_alias_name] + (attributes[:aliases] || [])
# Lookup Lexer object
- @lexer = Lexer.find_by_name(attributes[:lexer] || name) ||
+ @lexer = Pygments::Lexer.find_by_name(attributes[:lexer] || name) ||
raise(ArgumentError, "#{@name} is missing lexer")
# Set legacy search term
@@ -370,21 +369,12 @@ def searchable?
# Public: Highlight syntax of text
#
- # text - String of code to be highlighted
- #
- # Returns html String
- def colorize(text)
- lexer.colorize(text)
- end
-
- # Public: Highlight syntax of text without the outer highlight div
- # wrapper.
- #
- # text - String of code to be highlighted
+ # text - String of code to be highlighted
+ # options - A Hash of options (defaults to {})
#
# Returns html String
- def colorize_without_wrapper(text)
- lexer.colorize_without_wrapper(text)
+ def colorize(text, options = {})
+ lexer.highlight(text, options = {})
end
# Public: Return name as String representation
View
167 lib/linguist/lexer.rb
@@ -1,167 +0,0 @@
-require 'pygments'
-require 'yaml'
-
-module Linguist
- # Mirror of Pygments Lexer structure.
- #
- # name - Proper lexer name (JavaScript, Ruby, Python)
- # aliases - Aliases for lookup (js, javascript)
- # filenames - Filename globs (*.js)
- # mimetypes - Mime types (application/javascript)
- class Lexer < Struct.new(:name, :aliases, :filenames, :mimetypes)
- @lexers = []
- @index = {}
- @name_index = {}
- @alias_index = {}
- @mimetypes_index = {}
-
- # Internal: Create a new Lexer object
- #
- # name - Name of Lexer
- # attrs - A hash of attributes
- #
- # Returns a Lexer object
- def self.create(name, attrs)
- name = name
- aliases = attrs['aliases'] || []
- filenames = attrs['filenames'] || []
- mimetypes = attrs['mimetypes'] || []
-
- @lexers << lexer = new(name, aliases, filenames, mimetypes)
-
- # All Lexer names should be unique. Warn if there is a duplicate.
- if @name_index.key?(lexer.name)
- warn "Duplicate lexer name: #{lexer.name}"
- end
-
- @index[lexer.name] = @name_index[lexer.name] = lexer
-
- lexer.aliases.each do |name|
- # All Lexer aliases should be unique. Warn if there is a duplicate.
- if @alias_index.key?(name)
- warn "Duplicate alias: #{name}"
- end
-
- @index[name] = @alias_index[name] = lexer
- end
-
- lexer.mimetypes.each do |type|
- # All Lexer mimetypes should be unique. Warn if there is a duplicate.
- if @mimetypes_index.key?(name)
- warn "Duplicate mimetype: #{name}"
- end
-
- @mimetypes_index[type] = lexer
- end
- end
-
- # Public: Get all Lexers
- #
- # Returns an Array of Lexers
- def self.all
- @lexers
- end
-
- # Public: Look up Lexer by name or alias.
- #
- # name - A String name or alias
- #
- # Lexer['Ruby']
- # => #<Lexer name="Ruby">
- #
- # Returns the Lexer or nil if none was found.
- def self.[](name)
- @index[name]
- end
-
- # Public: Look up Lexer by its proper name.
- #
- # name - The String name of the Lexer
- #
- # Examples
- #
- # Lexer.find_by_name('Ruby')
- # # => #<Lexer name="Ruby">
- #
- # Returns the Lexer or nil if none was found.
- def self.find_by_name(name)
- @name_index[name]
- end
-
- # Public: Look up Lexer by one of its aliases.
- #
- # name - A String alias of the Lexer
- #
- # Examples
- #
- # Lexer.find_by_alias('rb')
- # # => #<Lexer name="Ruby">
- #
- # Returns the Lexer or nil if none was found.
- def self.find_by_alias(name)
- @alias_index[name]
- end
-
- # Public: Look up Lexer by one of it's mime types.
- #
- # type - A mime type String.
- #
- # Examples
- #
- # Lexer.find_by_mimetype('application/x-ruby')
- # # => #<Lexer name="Ruby">
- #
- # Returns the Lexer or nil if none was found.
- def self.find_by_mimetype(type)
- @mimetypes_index[type]
- end
-
- # Public: Return a alias of the Lexer to pass to Pygments.
- #
- # The alias we choose is arbitrary.
- #
- # Returns the alias String
- def to_s
- aliases.first
- end
-
- # Public: Highlight syntax of text
- #
- # text - String of code to be highlighted
- #
- # Returns html String
- def colorize(text)
- Pygments.highlight(text, :lexer => aliases.first, :options => {:stripnl => false})
- end
-
- # Public: Highlight syntax of text without the outer highlight div
- # wrapper.
- #
- # text - String of code to be highlighted
- #
- # Returns html String
- def colorize_without_wrapper(text)
- if text = colorize(text)
- text[%r{<div class="highlight"><pre>(.*?)</pre>\s*</div>}m, 1]
- else
- ''
- end
- end
-
- def ==(other)
- eql?(other)
- end
-
- def eql?(other)
- equal?(other)
- end
-
- # Load lexers from lexers.yml
- #
- # `bin/pygments-lexers` dumps a YAML list of all the available
- # Pygments lexers.
- YAML.load_file(File.expand_path("../lexers.yml", __FILE__)).each do |name, attrs|
- Lexer.create(name, attrs)
- end
- end
-end
View
1,652 lib/linguist/lexers.yml
@@ -1,1652 +0,0 @@
-# AUTOMATICALLY GENERATED BY bin/pygments-lexers
-# DO NOT MODIFIY. YOUR PULL WILL BE REJECTED.
-# Pygments version 1.4
----
-JavaScript+Mako:
- aliases:
- - 'js+mako'
- - 'javascript+mako'
- mimetypes:
- - 'application/x-javascript+mako'
- - 'text/x-javascript+mako'
- - 'text/javascript+mako'
-Brainfuck:
- aliases:
- - 'brainfuck'
- - 'bf'
- filenames:
- - '*.bf'
- - '*.b'
- mimetypes:
- - 'application/x-brainfuck'
-HTML+Cheetah:
- aliases:
- - 'html+cheetah'
- - 'html+spitfire'
- mimetypes:
- - 'text/html+cheetah'
- - 'text/html+spitfire'
-Nimrod:
- aliases:
- - 'nimrod'
- - 'nim'
- filenames:
- - '*.nim'
- - '*.nimrod'
- mimetypes:
- - 'text/x-nimrod'
-Bash:
- aliases:
- - 'bash'
- - 'sh'
- - 'ksh'
- filenames:
- - '*.sh'
- - '*.ksh'
- - '*.bash'
- - '*.ebuild'
- - '*.eclass'
- mimetypes:
- - 'application/x-sh'
- - 'application/x-shellscript'
-CSS+Myghty:
- aliases:
- - 'css+myghty'
- mimetypes:
- - 'text/css+myghty'
-Coldfusion HTML:
- aliases:
- - 'cfm'
- filenames:
- - '*.cfm'
- - '*.cfml'
- - '*.cfc'
- mimetypes:
- - 'application/x-coldfusion'
-Smarty:
- aliases:
- - 'smarty'
- filenames:
- - '*.tpl'
- mimetypes:
- - 'application/x-smarty'
-Protocol Buffer:
- aliases:
- - 'protobuf'
- filenames:
- - '*.proto'
-ApacheConf:
- aliases:
- - 'apacheconf'
- - 'aconf'
- - 'apache'
- filenames:
- - '.htaccess'
- - 'apache.conf'
- - 'apache2.conf'
- mimetypes:
- - 'text/x-apacheconf'
-Java:
- aliases:
- - 'java'
- filenames:
- - '*.java'
- mimetypes:
- - 'text/x-java'
-JavaScript+Genshi Text:
- aliases:
- - 'js+genshitext'
- - 'js+genshi'
- - 'javascript+genshitext'
- - 'javascript+genshi'
- mimetypes:
- - 'application/x-javascript+genshi'
- - 'text/x-javascript+genshi'
- - 'text/javascript+genshi'
-Scheme:
- aliases:
- - 'scheme'
- - 'scm'
- filenames:
- - '*.scm'
- - '*.ss'
- - '*.rkt'
- mimetypes:
- - 'text/x-scheme'
- - 'application/x-scheme'
-Nemerle:
- aliases:
- - 'nemerle'
- filenames:
- - '*.n'
- mimetypes:
- - 'text/x-nemerle'
-CoffeeScript:
- aliases:
- - 'coffee-script'
- - 'coffeescript'
- filenames:
- - '*.coffee'
- mimetypes:
- - 'text/coffeescript'
-ANTLR With ActionScript Target:
- aliases:
- - 'antlr-as'
- - 'antlr-actionscript'
- filenames:
- - '*.G'
- - '*.g'
-d-objdump:
- aliases:
- - 'd-objdump'
- filenames:
- - '*.d-objdump'
- mimetypes:
- - 'text/x-d-objdump'
-CSS+Ruby:
- aliases:
- - 'css+erb'
- - 'css+ruby'
- mimetypes:
- - 'text/css+ruby'
-MySQL:
- aliases:
- - 'mysql'
- mimetypes:
- - 'text/x-mysql'
-C++:
- aliases:
- - 'cpp'
- - 'c++'
- filenames:
- - '*.cpp'
- - '*.hpp'
- - '*.c++'
- - '*.h++'
- - '*.cc'
- - '*.hh'
- - '*.cxx'
- - '*.hxx'
- mimetypes:
- - 'text/x-c++hdr'
- - 'text/x-c++src'
-XML+Smarty:
- aliases:
- - 'xml+smarty'
- mimetypes:
- - 'application/xml+smarty'
-Groovy:
- aliases:
- - 'groovy'
- filenames:
- - '*.groovy'
- mimetypes:
- - 'text/x-groovy'
-autohotkey:
- aliases:
- - 'ahk'
- filenames:
- - '*.ahk'
- - '*.ahkl'
- mimetypes:
- - 'text/x-autohotkey'
-Felix:
- aliases:
- - 'felix'
- - 'flx'
- filenames:
- - '*.flx'
- - '*.flxh'
- mimetypes:
- - 'text/x-felix'
-CMake:
- aliases:
- - 'cmake'
- filenames:
- - '*.cmake'
- - 'CMakeLists.txt'
- mimetypes:
- - 'text/x-cmake'
-Mako:
- aliases:
- - 'mako'
- filenames:
- - '*.mao'
- mimetypes:
- - 'application/x-mako'
-Python:
- aliases:
- - 'python'
- - 'py'
- filenames:
- - '*.py'
- - '*.pyw'
- - '*.sc'
- - 'SConstruct'
- - 'SConscript'
- - '*.tac'
- mimetypes:
- - 'text/x-python'
- - 'application/x-python'
-JavaScript+Myghty:
- aliases:
- - 'js+myghty'
- - 'javascript+myghty'
- mimetypes:
- - 'application/x-javascript+myghty'
- - 'text/x-javascript+myghty'
- - 'text/javascript+mygthy'
-XML+Mako:
- aliases:
- - 'xml+mako'
- mimetypes:
- - 'application/xml+mako'
-Scaml:
- aliases:
- - 'scaml'
- - 'SCAML'
- filenames:
- - '*.scaml'
- mimetypes:
- - 'text/x-scaml'
-MAQL:
- aliases:
- - 'maql'
- filenames:
- - '*.maql'
- mimetypes:
- - 'text/x-gooddata-maql'
- - 'application/x-gooddata-maql'
-Boo:
- aliases:
- - 'boo'
- filenames:
- - '*.boo'
- mimetypes:
- - 'text/x-boo'
-ActionScript:
- aliases:
- - 'as'
- - 'actionscript'
- filenames:
- - '*.as'
- mimetypes:
- - 'application/x-actionscript3'
- - 'text/x-actionscript3'
- - 'text/actionscript3'
-VB.net:
- aliases:
- - 'vb.net'
- - 'vbnet'
- filenames:
- - '*.vb'
- - '*.bas'
- mimetypes:
- - 'text/x-vbnet'
- - 'text/x-vba'
-SquidConf:
- aliases:
- - 'squidconf'
- - 'squid.conf'
- - 'squid'
- filenames:
- - 'squid.conf'
- mimetypes:
- - 'text/x-squidconf'
-D:
- aliases:
- - 'd'
- filenames:
- - '*.d'
- - '*.di'
- mimetypes:
- - 'text/x-dsrc'
-Logtalk:
- aliases:
- - 'logtalk'
- filenames:
- - '*.lgt'
- mimetypes:
- - 'text/x-logtalk'
-SCSS:
- aliases:
- - 'scss'
- filenames:
- - '*.scss'
- mimetypes:
- - 'text/x-scss'
-BBCode:
- aliases:
- - 'bbcode'
- mimetypes:
- - 'text/x-bbcode'
-Haml:
- aliases:
- - 'haml'
- - 'HAML'
- filenames:
- - '*.haml'
- mimetypes:
- - 'text/x-haml'
-MuPAD:
- aliases:
- - 'mupad'
- filenames:
- - '*.mu'
-XML+Ruby:
- aliases:
- - 'xml+erb'
- - 'xml+ruby'
- mimetypes:
- - 'application/xml+ruby'
-Debian Control file:
- aliases:
- - 'control'
- filenames:
- - 'control'
-Jade:
- aliases:
- - 'jade'
- - 'JADE'
- filenames:
- - '*.jade'
- mimetypes:
- - 'text/x-jade'
-c-objdump:
- aliases:
- - 'c-objdump'
- filenames:
- - '*.c-objdump'
- mimetypes:
- - 'text/x-c-objdump'
-XML+Velocity:
- aliases:
- - 'xml+velocity'
- mimetypes:
- - 'application/xml+velocity'
-JavaScript+Cheetah:
- aliases:
- - 'js+cheetah'
- - 'javascript+cheetah'
- - 'js+spitfire'
- - 'javascript+spitfire'
- mimetypes:
- - 'application/x-javascript+cheetah'
- - 'text/x-javascript+cheetah'
- - 'text/javascript+cheetah'
- - 'application/x-javascript+spitfire'
- - 'text/x-javascript+spitfire'
- - 'text/javascript+spitfire'
-Python Traceback:
- aliases:
- - 'pytb'
- filenames:
- - '*.pytb'
- mimetypes:
- - 'text/x-python-traceback'
-cfstatement:
- aliases:
- - 'cfs'
-Ada:
- aliases:
- - 'ada'
- - 'ada95ada2005'
- filenames:
- - '*.adb'
- - '*.ads'
- - '*.ada'
- mimetypes:
- - 'text/x-ada'
-objdump:
- aliases:
- - 'objdump'
- filenames:
- - '*.objdump'
- mimetypes:
- - 'text/x-objdump'
-CSS+Mako:
- aliases:
- - 'css+mako'
- mimetypes:
- - 'text/css+mako'
-Gherkin:
- aliases:
- - 'Cucumber'
- - 'cucumber'
- - 'Gherkin'
- - 'gherkin'
- filenames:
- - '*.feature'
- mimetypes:
- - 'text/x-gherkin'
-Ragel in Java Host:
- aliases:
- - 'ragel-java'
- filenames:
- - '*.rl'
-Io:
- aliases:
- - 'io'
- filenames:
- - '*.io'
- mimetypes:
- - 'text/x-iosrc'
-PL/pgSQL:
- aliases:
- - 'plpgsql'
- mimetypes:
- - 'text/x-plpgsql'
-Vala:
- aliases:
- - 'vala'
- - 'vapi'
- filenames:
- - '*.vala'
- - '*.vapi'
- mimetypes:
- - 'text/x-vala'
-Haskell:
- aliases:
- - 'haskell'
- - 'hs'
- filenames:
- - '*.hs'
- mimetypes:
- - 'text/x-haskell'
-Lua:
- aliases:
- - 'lua'
- filenames:
- - '*.lua'
- - '*.wlua'
- mimetypes:
- - 'text/x-lua'
- - 'application/x-lua'
-Sass:
- aliases:
- - 'sass'
- - 'SASS'
- filenames:
- - '*.sass'
- mimetypes:
- - 'text/x-sass'
-ANTLR With ObjectiveC Target:
- aliases:
- - 'antlr-objc'
- filenames:
- - '*.G'
- - '*.g'
-XML:
- aliases:
- - 'xml'
- filenames:
- - '*.xml'
- - '*.xsl'
- - '*.rss'
- - '*.xslt'
- - '*.xsd'
- - '*.wsdl'
- mimetypes:
- - 'text/xml'
- - 'application/xml'
- - 'image/svg+xml'
- - 'application/rss+xml'
- - 'application/atom+xml'
-Groff:
- aliases:
- - 'groff'
- - 'nroff'
- - 'man'
- filenames:
- - '*.[1234567]'
- - '*.man'
- mimetypes:
- - 'application/x-troff'
- - 'text/troff'
-GLSL:
- aliases:
- - 'glsl'
- filenames:
- - '*.vert'
- - '*.frag'
- - '*.geo'
- mimetypes:
- - 'text/x-glslsrc'
-Genshi Text:
- aliases:
- - 'genshitext'
- mimetypes:
- - 'application/x-genshi-text'
- - 'text/x-genshi'
-Objective-J:
- aliases:
- - 'objective-j'
- - 'objectivej'
- - 'obj-j'
- - 'objj'
- filenames:
- - '*.j'
- mimetypes:
- - 'text/x-objective-j'
-GAS:
- aliases:
- - 'gas'
- filenames:
- - '*.s'
- - '*.S'
- mimetypes:
- - 'text/x-gas'
-Python console session:
- aliases:
- - 'pycon'
- mimetypes:
- - 'text/x-python-doctest'
-MXML:
- aliases:
- - 'mxml'
- filenames:
- - '*.mxml'
-XML+Cheetah:
- aliases:
- - 'xml+cheetah'
- - 'xml+spitfire'
- mimetypes:
- - 'application/xml+cheetah'
- - 'application/xml+spitfire'
-Go:
- aliases:
- - 'go'
- filenames:
- - '*.go'
- mimetypes:
- - 'text/x-gosrc'
-Ragel in C Host:
- aliases:
- - 'ragel-c'
- filenames:
- - '*.rl'
-aspx-cs:
- aliases:
- - 'aspx-cs'
- filenames:
- - '*.aspx'
- - '*.asax'
- - '*.ascx'
- - '*.ashx'
- - '*.asmx'
- - '*.axd'
-Properties:
- aliases:
- - 'properties'
- filenames:
- - '*.properties'
- mimetypes:
- - 'text/x-java-properties'
-Ragel in Ruby Host:
- aliases:
- - 'ragel-ruby'
- - 'ragel-rb'
- filenames:
- - '*.rl'
-BlitzMax:
- aliases:
- - 'blitzmax'
- - 'bmax'
- filenames:
- - '*.bmx'
- mimetypes:
- - 'text/x-bmx'
-HTML+Genshi:
- aliases:
- - 'html+genshi'
- - 'html+kid'
- mimetypes:
- - 'text/html+genshi'
-Perl:
- aliases:
- - 'perl'
- - 'pl'
- filenames:
- - '*.pl'
- - '*.pm'
- mimetypes:
- - 'text/x-perl'
- - 'application/x-perl'
-Scala:
- aliases:
- - 'scala'
- filenames:
- - '*.scala'
- mimetypes:
- - 'text/x-scala'
-INI:
- aliases:
- - 'ini'
- - 'cfg'
- filenames:
- - '*.ini'
- - '*.cfg'
- mimetypes:
- - 'text/x-ini'
-RHTML:
- aliases:
- - 'rhtml'
- - 'html+erb'
- - 'html+ruby'
- filenames:
- - '*.rhtml'
- mimetypes:
- - 'text/html+ruby'
-Tcsh:
- aliases:
- - 'tcsh'
- - 'csh'
- filenames:
- - '*.tcsh'
- - '*.csh'
- mimetypes:
- - 'application/x-csh'
-RConsole:
- aliases:
- - 'rconsole'
- - 'rout'
- filenames:
- - '*.Rout'
-CSS+Smarty:
- aliases:
- - 'css+smarty'
- mimetypes:
- - 'text/css+smarty'
-Text only:
- aliases:
- - 'text'
- filenames:
- - '*.txt'
- mimetypes:
- - 'text/plain'
-ANTLR With C# Target:
- aliases:
- - 'antlr-csharp'
- - 'antlr-c#'
- filenames:
- - '*.G'
- - '*.g'
-Darcs Patch:
- aliases:
- - 'dpatch'
- filenames:
- - '*.dpatch'
- - '*.darcspatch'
-LLVM:
- aliases:
- - 'llvm'
- filenames:
- - '*.ll'
- mimetypes:
- - 'text/x-llvm'
-Nginx configuration file:
- aliases:
- - 'nginx'
- mimetypes:
- - 'text/x-nginx-conf'
-AppleScript:
- aliases:
- - 'applescript'
- filenames:
- - '*.applescript'
-Python 3.0 Traceback:
- aliases:
- - 'py3tb'
- filenames:
- - '*.py3tb'
- mimetypes:
- - 'text/x-python3-traceback'
-Literate Haskell:
- aliases:
- - 'lhs'
- - 'literate-haskell'
- filenames:
- - '*.lhs'
- mimetypes:
- - 'text/x-literate-haskell'
-PHP:
- aliases:
- - 'php'
- - 'php3'
- - 'php4'
- - 'php5'
- filenames:
- - '*.php'
- - '*.php[345]'
- mimetypes:
- - 'text/x-php'
-MiniD:
- aliases:
- - 'minid'
- filenames:
- - '*.md'
- mimetypes:
- - 'text/x-minidsrc'
-Ooc:
- aliases:
- - 'ooc'
- filenames:
- - '*.ooc'
- mimetypes:
- - 'text/x-ooc'
-SQL:
- aliases:
- - 'sql'
- filenames:
- - '*.sql'
- mimetypes:
- - 'text/x-sql'
-NASM:
- aliases:
- - 'nasm'
- filenames:
- - '*.asm'
- - '*.ASM'
- mimetypes:
- - 'text/x-nasm'
-Debian Sourcelist:
- aliases:
- - 'sourceslist'
- - 'sources.list'
- filenames:
- - 'sources.list'
-Delphi:
- aliases:
- - 'delphi'
- - 'pas'
- - 'pascal'
- - 'objectpascal'
- filenames:
- - '*.pas'
- mimetypes:
- - 'text/x-pascal'
-aspx-vb:
- aliases:
- - 'aspx-vb'
- filenames:
- - '*.aspx'
- - '*.asax'
- - '*.ascx'
- - '*.ashx'
- - '*.asmx'
- - '*.axd'
-HTML+Evoque:
- aliases:
- - 'html+evoque'
- filenames:
- - '*.html'
- mimetypes:
- - 'text/html+evoque'
-NumPy:
- aliases:
- - 'numpy'
-Modula-2:
- aliases:
- - 'modula2'
- - 'm2'
- filenames:
- - '*.def'
- - '*.mod'
- mimetypes:
- - 'text/x-modula2'
-PostgreSQL SQL dialect:
- aliases:
- - 'postgresql'
- - 'postgres'
- mimetypes:
- - 'text/x-postgresql'
-HTML+Django/Jinja:
- aliases:
- - 'html+django'
- - 'html+jinja'
- mimetypes:
- - 'text/html+django'
- - 'text/html+jinja'
-CSS+PHP:
- aliases:
- - 'css+php'
- mimetypes:
- - 'text/css+php'
-VimL:
- aliases:
- - 'vim'
- filenames:
- - '*.vim'
- - '.vimrc'
- - '.exrc'
- - '.gvimrc'
- - '_vimrc'
- - '_exrc'
- - '_gvimrc'
- mimetypes:
- - 'text/x-vim'
-CSS+Genshi Text:
- aliases:
- - 'css+genshitext'
- - 'css+genshi'
- mimetypes:
- - 'text/css+genshi'
-Fancy:
- aliases:
- - 'fancy'
- - 'fy'
- filenames:
- - '*.fy'
- - '*.fancypack'
- mimetypes:
- - 'text/x-fancysrc'
-Ragel:
- aliases:
- - 'ragel'
-Scalate Server Page:
- aliases:
- - 'ssp'
- filenames:
- - '*.ssp'
- mimetypes:
- - 'application/x-ssp'
-XML+Evoque:
- aliases:
- - 'xml+evoque'
- filenames:
- - '*.xml'
- mimetypes:
- - 'application/xml+evoque'
-haXe:
- aliases:
- - 'hx'
- - 'haXe'
- filenames:
- - '*.hx'
- mimetypes:
- - 'text/haxe'
-Redcode:
- aliases:
- - 'redcode'
- filenames:
- - '*.cw'
-Django/Jinja:
- aliases:
- - 'django'
- - 'jinja'
- mimetypes:
- - 'application/x-django-templating'
- - 'application/x-jinja'
-DTD:
- aliases:
- - 'dtd'
- filenames:
- - '*.dtd'
- mimetypes:
- - 'application/xml-dtd'
-Lighttpd configuration file:
- aliases:
- - 'lighty'
- - 'lighttpd'
- mimetypes:
- - 'text/x-lighttpd-conf'
-HTML+Velocity:
- aliases:
- - 'html+velocity'
- mimetypes:
- - 'text/html+velocity'
-Ragel in D Host:
- aliases:
- - 'ragel-d'
- filenames:
- - '*.rl'
-Ruby irb session:
- aliases:
- - 'rbcon'
- - 'irb'
- mimetypes:
- - 'text/x-ruby-shellsession'
-CSS:
- aliases:
- - 'css'
- filenames:
- - '*.css'
- mimetypes:
- - 'text/css'
-JavaScript+Smarty:
- aliases:
- - 'js+smarty'
- - 'javascript+smarty'
- mimetypes:
- - 'application/x-javascript+smarty'
- - 'text/x-javascript+smarty'
- - 'text/javascript+smarty'
-Asymptote:
- aliases:
- - 'asy'
- - 'asymptote'
- filenames:
- - '*.asy'
- mimetypes:
- - 'text/x-asymptote'
-XML+PHP:
- aliases:
- - 'xml+php'
- mimetypes:
- - 'application/xml+php'
-Fortran:
- aliases:
- - 'fortran'
- filenames:
- - '*.f'
- - '*.f90'
- - '*.F'
- - '*.F90'
- mimetypes:
- - 'text/x-fortran'
-Gnuplot:
- aliases:
- - 'gnuplot'
- filenames:
- - '*.plot'
- - '*.plt'
- mimetypes:
- - 'text/x-gnuplot'
-REBOL:
- aliases:
- - 'rebol'
- filenames:
- - '*.r'
- - '*.r3'
- mimetypes:
- - 'text/x-rebol'
-ERB:
- aliases:
- - 'erb'
- mimetypes:
- - 'application/x-ruby-templating'
-Befunge:
- aliases:
- - 'befunge'
- filenames:
- - '*.befunge'
- mimetypes:
- - 'application/x-befunge'
-Dylan:
- aliases:
- - 'dylan'
- filenames:
- - '*.dylan'
- - '*.dyl'
- mimetypes:
- - 'text/x-dylan'
-MoinMoin/Trac Wiki markup:
- aliases:
- - 'trac-wiki'
- - 'moin'
- mimetypes:
- - 'text/x-trac-wiki'
-Matlab:
- aliases:
- - 'matlab'
- - 'octave'
- filenames:
- - '*.m'
- mimetypes:
- - 'text/matlab'
-C:
- aliases:
- - 'c'
- filenames:
- - '*.c'
- - '*.h'
- - '*.idc'
- mimetypes:
- - 'text/x-chdr'
- - 'text/x-csrc'
-HTML:
- aliases:
- - 'html'
- filenames:
- - '*.html'
- - '*.htm'
- - '*.xhtml'
- - '*.xslt'
- mimetypes:
- - 'text/html'
- - 'application/xhtml+xml'
-Genshi:
- aliases:
- - 'genshi'
- - 'kid'
- - 'xml+genshi'
- - 'xml+kid'
- filenames:
- - '*.kid'
- mimetypes:
- - 'application/x-genshi'
- - 'application/x-kid'
-reStructuredText:
- aliases:
- - 'rst'
- - 'rest'
- - 'restructuredtext'
- filenames:
- - '*.rst'
- - '*.rest'
- mimetypes:
- - 'text/x-rst'
- - 'text/prs.fallenstein.rst'
-Velocity:
- aliases:
- - 'velocity'
- filenames:
- - '*.vm'
- - '*.fhtml'
-IRC logs:
- aliases:
- - 'irc'
- filenames:
- - '*.weechatlog'
- mimetypes:
- - 'text/x-irclog'
-Prolog:
- aliases:
- - 'prolog'
- filenames:
- - '*.prolog'
- - '*.pro'
- - '*.pl'
- mimetypes:
- - 'text/x-prolog'
-CSS+Django/Jinja:
- aliases:
- - 'css+django'
- - 'css+jinja'
- mimetypes:
- - 'text/css+django'
- - 'text/css+jinja'
-Smalltalk:
- aliases:
- - 'smalltalk'
- - 'squeak'
- filenames:
- - '*.st'
- mimetypes:
- - 'text/x-smalltalk'
-YAML:
- aliases:
- - 'yaml'
- filenames:
- - '*.yaml'
- - '*.yml'
- mimetypes:
- - 'text/x-yaml'
-HTML+Myghty:
- aliases:
- - 'html+myghty'
- mimetypes:
- - 'text/html+myghty'
-Makefile:
- aliases:
- - 'make'
- - 'makefile'
- - 'mf'
- - 'bsdmake'
- filenames:
- - '*.mak'
- - 'Makefile'
- - 'makefile'
- - 'Makefile.*'
- - 'GNUmakefile'
- mimetypes:
- - 'text/x-makefile'
-XSLT:
- aliases:
- - 'xslt'
- filenames:
- - '*.xsl'
- - '*.xslt'
- mimetypes:
- - 'application/xsl+xml'
- - 'application/xslt+xml'
-S:
- aliases:
- - 'splus'
- - 's'
- - 'r'
- filenames:
- - '*.S'
- - '*.R'
- mimetypes:
- - 'text/S-plus'
- - 'text/S'
- - 'text/R'
-sqlite3con:
- aliases:
- - 'sqlite3'
- filenames:
- - '*.sqlite3-console'
- mimetypes:
- - 'text/x-sqlite3-console'
-OCaml:
- aliases:
- - 'ocaml'
- filenames:
- - '*.ml'
- - '*.mli'
- - '*.mll'
- - '*.mly'
- mimetypes:
- - 'text/x-ocaml'
-eC:
- aliases:
- - 'ec'
- filenames:
- - '*.ec'
- - '*.eh'
- mimetypes:
- - 'text/x-echdr'
- - 'text/x-ecsrc'
-Gettext Catalog:
- aliases:
- - 'pot'
- - 'po'
- filenames:
- - '*.pot'
- - '*.po'
- mimetypes:
- - 'application/x-gettext'
- - 'text/x-gettext'
- - 'text/gettext'
-Ruby:
- aliases:
- - 'rb'
- - 'ruby'
- - 'duby'
- filenames:
- - '*.rb'
- - '*.rbw'
- - 'Rakefile'
- - '*.rake'
- - '*.gemspec'
- - '*.rbx'
- - '*.duby'
- mimetypes:
- - 'text/x-ruby'
- - 'application/x-ruby'
-HTML+Smarty:
- aliases:
- - 'html+smarty'
- mimetypes:
- - 'text/html+smarty'
-POVRay:
- aliases:
- - 'pov'
- filenames:
- - '*.pov'
- - '*.inc'
- mimetypes:
- - 'text/x-povray'
-Ragel in CPP Host:
- aliases:
- - 'ragel-cpp'
- filenames:
- - '*.rl'
-Evoque:
- aliases:
- - 'evoque'
- filenames:
- - '*.evoque'
- mimetypes:
- - 'application/x-evoque'
-Java Server Page:
- aliases:
- - 'jsp'
- filenames:
- - '*.jsp'
- mimetypes:
- - 'application/x-jsp'
-ABAP:
- aliases:
- - 'abap'
- filenames:
- - '*.abap'
- mimetypes:
- - 'text/x-abap'
-HTML+Mako:
- aliases:
- - 'html+mako'
- mimetypes:
- - 'text/html+mako'
-Diff:
- aliases:
- - 'diff'
- - 'udiff'
- filenames:
- - '*.diff'
- - '*.patch'
- mimetypes:
- - 'text/x-diff'
- - 'text/x-patch'
-Matlab session:
- aliases:
- - 'matlabsession'
-Mason:
- aliases:
- - 'mason'
- filenames:
- - '*.m'
- - '*.mhtml'
- - '*.mc'
- - '*.mi'
- - 'autohandler'
- - 'dhandler'
- mimetypes:
- - 'application/x-mason'
-HTML+PHP:
- aliases:
- - 'html+php'
- filenames:
- - '*.phtml'
- mimetypes:
- - 'application/x-php'
- - 'application/x-httpd-php'
- - 'application/x-httpd-php3'
- - 'application/x-httpd-php4'
- - 'application/x-httpd-php5'
-PostScript:
- aliases:
- - 'postscript'
- filenames:
- - '*.ps'
- - '*.eps'
- mimetypes:
- - 'application/postscript'
-verilog:
- aliases:
- - 'v'
- filenames:
- - '*.v'
- - '*.sv'
- mimetypes:
- - 'text/x-verilog'
-ANTLR With Java Target:
- aliases:
- - 'antlr-java'
- filenames:
- - '*.G'
- - '*.g'
-Tcl:
- aliases:
- - 'tcl'
- filenames:
- - '*.tcl'
- mimetypes:
- - 'text/x-tcl'
- - 'text/x-script.tcl'
- - 'application/x-tcl'
-JavaScript+Ruby:
- aliases:
- - 'js+erb'
- - 'javascript+erb'
- - 'js+ruby'
- - 'javascript+ruby'
- mimetypes:
- - 'application/x-javascript+ruby'
- - 'text/x-javascript+ruby'
- - 'text/javascript+ruby'
-Base Makefile:
- aliases:
- - 'basemake'
-ANTLR With Python Target:
- aliases:
- - 'antlr-python'
- filenames:
- - '*.G'
- - '*.g'
-cpp-objdump:
- aliases:
- - 'cpp-objdump'
- - 'c++-objdumb'
- - 'cxx-objdump'
- filenames:
- - '*.cpp-objdump'
- - '*.c++-objdump'
- - '*.cxx-objdump'
- mimetypes:
- - 'text/x-cpp-objdump'
-Ioke:
- aliases:
- - 'ioke'
- - 'ik'
- filenames:
- - '*.ik'
- mimetypes:
- - 'text/x-iokesrc'
-PyPy Log:
- aliases:
- - 'pypylog'
- - 'pypy'
- filenames:
- - '*.pypylog'
- mimetypes:
- - 'application/x-pypylog'
-Python 3:
- aliases:
- - 'python3'
- - 'py3'
- mimetypes:
- - 'text/x-python3'
- - 'application/x-python3'
-Batchfile:
- aliases:
- - 'bat'
- filenames:
- - '*.bat'
- - '*.cmd'
- mimetypes:
- - 'application/x-dos-batch'
-ANTLR:
- aliases:
- - 'antlr'
-PostgreSQL console (psql):
- aliases:
- - 'psql'
- - 'postgresql-console'
- - 'postgres-console'
- mimetypes:
- - 'text/x-postgresql-psql'
-JavaScript+Django/Jinja:
- aliases:
- - 'js+django'
- - 'javascript+django'
- - 'js+jinja'
- - 'javascript+jinja'
- mimetypes:
- - 'application/x-javascript+django'
- - 'application/x-javascript+jinja'
- - 'text/x-javascript+django'
- - 'text/x-javascript+jinja'
- - 'text/javascript+django'
- - 'text/javascript+jinja'
-Cython:
- aliases:
- - 'cython'
- - 'pyx'
- filenames:
- - '*.pyx'
- - '*.pxd'
- - '*.pxi'
- mimetypes:
- - 'text/x-cython'
- - 'application/x-cython'
-Erlang:
- aliases:
- - 'erlang'
- filenames:
- - '*.erl'
- - '*.hrl'
- mimetypes:
- - 'text/x-erlang'
-Erlang erl session:
- aliases:
- - 'erl'
- filenames:
- - '*.erl-sh'
- mimetypes:
- - 'text/x-erl-shellsession'
-Clojure:
- aliases:
- - 'clojure'
- - 'clj'
- filenames:
- - '*.clj'
- mimetypes:
- - 'text/x-clojure'
- - 'application/x-clojure'
-Modelica:
- aliases:
- - 'modelica'
- filenames:
- - '*.mo'
- mimetypes:
- - 'text/x-modelica'
-ANTLR With Perl Target:
- aliases:
- - 'antlr-perl'
- filenames:
- - '*.G'
- - '*.g'
-Myghty:
- aliases:
- - 'myghty'
- filenames:
- - '*.myt'
- - 'autodelegate'
- mimetypes:
- - 'application/x-myghty'
-Duel:
- aliases:
- - 'duel'
- - 'Duel Engine'
- - 'Duel View'
- - 'JBST'
- - 'jbst'
- - 'JsonML+BST'
- filenames:
- - '*.duel'
- - '*.jbst'
- mimetypes:
- - 'text/x-duel'
- - 'text/x-jbst'
-FSharp:
- aliases:
- - 'fsharp'
- filenames:
- - '*.fs'
- - '*.fsi'
- mimetypes:
- - 'text/x-fsharp'
-MOOCode:
- aliases:
- - 'moocode'
- filenames:
- - '*.moo'
- mimetypes:
- - 'text/x-moocode'
-Newspeak:
- aliases:
- - 'newspeak'
- filenames:
- - '*.ns2'
- mimetypes:
- - 'text/x-newspeak'
-Bash Session:
- aliases:
- - 'console'
- filenames:
- - '*.sh-session'
- mimetypes:
- - 'application/x-shell-session'
-Raw token data:
- aliases:
- - 'raw'
- mimetypes:
- - 'application/x-pygments-tokens'
-C#:
- aliases:
- - 'csharp'
- - 'c#'
- filenames:
- - '*.cs'
- mimetypes:
- - 'text/x-csharp'
-Gosu Template:
- aliases:
- - 'gst'
- filenames:
- - '*.gst'
- mimetypes:
- - 'text/x-gosu-template'
-TeX:
- aliases:
- - 'tex'
- - 'latex'
- filenames:
- - '*.tex'
- - '*.aux'
- - '*.toc'
- mimetypes:
- - 'text/x-tex'
- - 'text/x-latex'
-Cheetah:
- aliases:
- - 'cheetah'
- - 'spitfire'
- filenames:
- - '*.tmpl'
- - '*.spt'
- mimetypes:
- - 'application/x-cheetah'
- - 'application/x-spitfire'
-GoodData-CL:
- aliases:
- - 'gooddata-cl'
- filenames:
- - '*.gdc'
- mimetypes:
- - 'text/x-gooddata-cl'
-Objective-C:
- aliases:
- - 'objective-c'
- - 'objectivec'
- - 'obj-c'
- - 'objc'
- filenames:
- - '*.m'
- mimetypes:
- - 'text/x-objective-c'
-JavaScript:
- aliases:
- - 'js'
- - 'javascript'
- filenames:
- - '*.js'
- - '*.json'
- mimetypes:
- - 'application/javascript'
- - 'application/x-javascript'
- - 'text/x-javascript'
- - 'text/javascript'
- - 'application/json'
-Common Lisp:
- aliases:
- - 'common-lisp'
- - 'cl'
- filenames:
- - '*.cl'
- - '*.lisp'
- - '*.el'
- mimetypes:
- - 'text/x-common-lisp'
-Embedded Ragel:
- aliases:
- - 'ragel-em'
- filenames:
- - '*.rl'
-ActionScript 3:
- aliases:
- - 'as3'
- - 'actionscript3'
- filenames:
- - '*.as'
- mimetypes:
- - 'application/x-actionscript'
- - 'text/x-actionscript'
- - 'text/actionscript'
-ANTLR With CPP Target:
- aliases:
- - 'antlr-cpp'
- filenames:
- - '*.G'
- - '*.g'
-Gosu:
- aliases:
- - 'gosu'
- filenames:
- - '*.gs'
- - '*.gsx'
- - '*.gsp'
- - '*.vark'
- mimetypes:
- - 'text/x-gosu'
-Hybris:
- aliases:
- - 'hybris'
- - 'hy'
- filenames:
- - '*.hy'
- - '*.hyb'
- mimetypes:
- - 'text/x-hybris'
- - 'application/x-hybris'
-JavaScript+PHP:
- aliases:
- - 'js+php'
- - 'javascript+php'
- mimetypes:
- - 'application/x-javascript+php'
- - 'text/x-javascript+php'
- - 'text/javascript+php'
-Factor:
- aliases:
- - 'factor'
- filenames:
- - '*.factor'
- mimetypes:
- - 'text/x-factor'
-XQuery:
- aliases:
- - 'xquery'
- - 'xqy'
- filenames:
- - '*.xqy'
- - '*.xquery'
- mimetypes:
- - 'text/xquery'
- - 'application/xquery'
-Ragel in Objective C Host:
- aliases:
- - 'ragel-objc'
- filenames:
- - '*.rl'
-XML+Django/Jinja:
- aliases:
- - 'xml+django'
- - 'xml+jinja'
- mimetypes:
- - 'application/xml+django'
- - 'application/xml+jinja'
-Awk:
- aliases:
- - 'awk'
- - 'gawk'
- - 'mawk'
- - 'nawk'
- filenames:
- - '*.awk'
- mimetypes:
- - 'application/x-awk'
-ANTLR With Ruby Target:
- aliases:
- - 'antlr-ruby'
- - 'antlr-rb'
- filenames:
- - '*.G'
- - '*.g'
-XML+Myghty:
- aliases:
- - 'xml+myghty'
- mimetypes:
- - 'application/xml+myghty'
View
3  lib/linguist/pathname.rb
@@ -1,5 +1,6 @@
require 'linguist/language'
require 'linguist/mime'
+require 'pygments'
module Linguist
# Similar to ::Pathname, Linguist::Pathname wraps a path string and
@@ -61,7 +62,7 @@ def language
#
# Returns a Lexer.
def lexer
- language ? language.lexer : Lexer['Text only']
+ language ? language.lexer : Pygments::Lexer.find_by_name('Text only')
end
# Public: Get the mime type
View
3  test/test_blob.rb
@@ -2,10 +2,13 @@
require 'test/unit'
require 'mime/types'
+require 'pygments'
class TestBlob < Test::Unit::TestCase
include Linguist
+ Lexer = Pygments::Lexer
+
def fixtures_path
File.expand_path("../fixtures", __FILE__)
end
View
25 test/test_language.rb
@@ -1,10 +1,13 @@
require 'linguist/language'
require 'test/unit'
+require 'pygments'
class TestLanguage < Test::Unit::TestCase
include Linguist
+ Lexer = Pygments::Lexer
+
def test_ambiguous_extensions
assert Language.ambiguous?('.h')
assert_equal Language['C'], Language.find_by_extension('h')
@@ -311,26 +314,4 @@ def test_colorize
</div>
HTML
end
-
- def test_colorize_without_wrapper
- assert_equal <<-HTML, Language['Text'].colorize_without_wrapper("Hello")
-Hello
- HTML
-
- assert_equal <<-HTML, Language['Ruby'].colorize_without_wrapper("def foo\n 'foo'\nend\n")
-<span class="k">def</span> <span class="nf">foo</span>
- <span class="s1">&#39;foo&#39;</span>
-<span class="k">end</span>
- HTML
- end
-
- def test_colorize_doesnt_strip_newlines
- assert_equal <<-HTML, Language['Ruby'].colorize_without_wrapper("\n\n# Foo\ndef 'foo'\nend\n")
-
-
-<span class="c1"># Foo</span>
-<span class="k">def</span> <span class="s1">&#39;foo&#39;</span>
-<span class="k">end</span>
- HTML
- end
end
View
91 test/test_lexer.rb
@@ -1,91 +0,0 @@
-require 'linguist/lexer'
-
-require 'test/unit'
-
-class TestLexer < Test::Unit::TestCase
- include Linguist
-
- def test_find_by_name
- assert_equal Lexer['Ruby'], Lexer.find_by_name('Ruby')
- end
-
- def test_find_all_by_name
- Lexer.all.each do |lexer|
- assert_equal lexer, Lexer.find_by_name(lexer.name)
- assert_equal lexer, Lexer[lexer.name]
- end
- end
-
- def test_find_by_alias
- assert_equal Lexer['Ruby'], Lexer.find_by_alias('rb')
- assert_equal Lexer['Ruby'], Lexer.find_by_alias('ruby')
- end
-
- def test_find_all_by_alias
- Lexer.all.each do |lexer|
- lexer.aliases.each do |name|
- assert_equal lexer, Lexer.find_by_alias(name)
- assert_equal lexer, Lexer[name]
- end
- end
- end
-
- def test_find_by_mimetype
- assert_equal Lexer['Ruby'], Lexer.find_by_mimetype('text/x-ruby')
- assert_equal Lexer['Ruby'], Lexer.find_by_mimetype('application/x-ruby')
- end
-
- def test_find_all_by_mimetype
- Lexer.all.each do |lexer|
- lexer.mimetypes.each do |type|
- assert_equal lexer, Lexer.find_by_mimetype(type)
- end
- end
- end
-
- def test_name
- assert_equal 'Ruby', Lexer['Ruby'].name
- assert_equal 'Python', Lexer['Python'].name
- assert_equal 'Perl', Lexer['Perl'].name
- end
-
- def test_aliases
- assert_equal ['rb', 'ruby', 'duby'], Lexer['Ruby'].aliases
- assert_equal ['python', 'py'], Lexer['Python'].aliases
- assert_equal ['perl', 'pl'], Lexer['Perl'].aliases
- end
-
- def test_eql
- assert Lexer['Ruby'].eql?(Lexer['Ruby'])
- assert !Lexer['Ruby'].eql?(Lexer['Python'])
- assert !Lexer['Ruby'].eql?(Lexer.new('Ruby'))
- end
-
- def test_colorize
- assert_equal <<-HTML, Lexer['Text only'].colorize("Hello")
-<div class="highlight"><pre>Hello
-</pre>
-</div>
- HTML
-
- assert_equal <<-HTML, Lexer['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
-
- def test_colorize_without_wrapper
- assert_equal <<-HTML, Lexer['Text only'].colorize_without_wrapper("Hello")
-Hello
- HTML
-
- assert_equal <<-HTML, Lexer['Ruby'].colorize_without_wrapper("def foo\n 'foo'\nend\n")
-<span class="k">def</span> <span class="nf">foo</span>
- <span class="s1">&#39;foo&#39;</span>
-<span class="k">end</span>
- HTML
- end
-end
View
3  test/test_pathname.rb
@@ -1,10 +1,13 @@
require 'linguist/pathname'
require 'test/unit'
+require 'pygments'
class TestPathname < Test::Unit::TestCase
include Linguist
+ Lexer = Pygments::Lexer
+
def test_to_s
assert_equal "file.rb", Pathname.new("file.rb").to_s
end
Please sign in to comment.
Something went wrong with that request. Please try again.