Skip to content

resolves #234 update Pygments to 2.10.0 #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[
== Unreleased

* add `Pygments.pygments_version` method to query underlying Pygments version ({uri-repo}/issues/226[#226])
* Update Pygments to 2.10.0 ({uri-repo}/issues/234[#234])

== 2.2.0 (2021-03-18) - @slonopotamus

Expand Down
4 changes: 2 additions & 2 deletions bench.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
code = File.open('test/test_pygments.rb').read.to_s * repeats

puts "Benchmarking....\n"
puts 'Size: ' + code.bytesize.to_s + " bytes\n"
puts 'Iterations: ' + num.to_s + "\n"
puts "Size: #{code.bytesize} bytes\n"
puts "Iterations: #{num}\n"

Benchmark.bm(40) do |x|
x.report('pygments popen ') do
Expand Down
7 changes: 6 additions & 1 deletion lib/pygments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ def engine
Thread.current.thread_variable_set(:pygments_engine, Pygments::Popen.new)
end

def lexer_name_for(*args)
names = engine.lexer_names_for(*args)
names&.[](0)
end

def_delegators :engine,
:formatters,
:lexers!,
:filters,
:styles,
:css,
:lexer_name_for,
:lexer_names_for,
:highlight,
:start,
:pygments_version
Expand Down
2 changes: 1 addition & 1 deletion lib/pygments/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def initialize
@mimetypes_index = {}
@raw_lexers = Pygments.lexers!

@raw_lexers.values.each do |hash|
@raw_lexers.each_value do |hash|
lexer = Lexer.new(hash[:name], hash[:aliases], hash[:filenames], hash[:mimetypes])

@lexers << lexer
Expand Down
7 changes: 3 additions & 4 deletions lib/pygments/mentos.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,12 @@ def get_data(self, method, lexer, args, kwargs, text=None):
fmt = pygments.formatters.get_formatter_by_name(args[0], **kwargs)
res = fmt.get_style_defs(args[1])

elif method == 'lexer_name_for':
elif method == 'lexer_names_for':
lexer = self.return_lexer(None, args, kwargs, text)

if lexer:
# We don't want the Lexer itself, just the name.
# Take the first alias.
res = lexer.aliases[0]
# We don't want the Lexer itself, just aliases.
res = json.dumps(list(lexer.aliases))

else:
_write_error("No lexer")
Expand Down
14 changes: 7 additions & 7 deletions lib/pygments/popen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def css(klass = '', opts = {})
mentos(:css, ['html', klass], opts)
end

# @return [String, nil] the name of a lexer.
def lexer_name_for(*args)
# @return [[String], nil] aliases of a lexer.
def lexer_names_for(*args)
# Pop off the last arg if it's a hash, which becomes our opts
opts = if args.last.is_a?(Hash)
args.pop
Expand All @@ -156,7 +156,7 @@ def lexer_name_for(*args)

code = (args.pop if args.last.is_a?(String))

mentos(:lexer_name_for, args, opts, code)
mentos(:lexer_names_for, args, opts, code)
end

# Public: Highlight code.
Expand Down Expand Up @@ -343,18 +343,18 @@ def handle_header_and_return(header)
# Read more bytes (the actual response body)
res = @out.read(bytes.to_i)

if header[:method] == 'highlight'
if header[:method] == 'highlight' && res.nil?
# Make sure we have a result back; else consider this an error.
raise MentosError, 'No highlight result back from mentos.' if res.nil?
raise MentosError, 'No highlight result back from mentos.'
end

res
end

# @return Ruby objects for the methods that want them, text otherwise.
def return_result(res, method)
res = JSON.parse(res, symbolize_names: true) unless %i[lexer_name_for highlight css].include?(method)
res = res.rstrip if res.class == String
res = JSON.parse(res, symbolize_names: true) unless %i[highlight css].include?(method)
res = res.rstrip if res.instance_of?(String)
res
end

Expand Down
6 changes: 3 additions & 3 deletions pygments.rb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Gem::Specification.new do |s|

s.metadata = {
'homepage_uri' => s.homepage,
'bug_tracker_uri' => s.homepage + '/issues',
'changelog_uri' => s.homepage + '/blob/master/CHANGELOG.adoc',
'documentation_uri' => 'https://www.rubydoc.info/gems/' + s.name,
'bug_tracker_uri' => "#{s.homepage}/issues",
'changelog_uri' => "#{s.homepage}/blob/master/CHANGELOG.adoc",
'documentation_uri' => "https://www.rubydoc.info/gems/#{s.name}",
'source_code_uri' => s.homepage
}

Expand Down
14 changes: 7 additions & 7 deletions test/test_pygments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ def test_highlight_works_with_trailing_newline
end

def test_highlight_works_with_multiple_newlines
code = P.highlight(RUBY_CODE_TRAILING_NEWLINE + "derp\n\n")
code = P.highlight("#{RUBY_CODE_TRAILING_NEWLINE}derp\n\n")
assert_match '<span class="ch">#!/usr/bin/ruby</span>', code
end

def test_highlight_works_with_trailing_cr
code = P.highlight(RUBY_CODE_TRAILING_NEWLINE + "\r")
code = P.highlight("#{RUBY_CODE_TRAILING_NEWLINE}\r")
assert_match '<span class="ch">#!/usr/bin/ruby</span>', code
end

Expand Down Expand Up @@ -127,27 +127,27 @@ class PygmentsLexerTest < Test::Unit::TestCase
RUBY_CODE = "#!/usr/bin/ruby\nputs 'foo'"

def test_lexer_by_mimetype
assert_equal 'rb', P.lexer_name_for(mimetype: 'text/x-ruby')
assert_includes P.lexer_names_for(mimetype: 'text/x-ruby'), 'rb'
assert_equal 'json', P.lexer_name_for(mimetype: 'application/json')
end

def test_lexer_by_filename
assert_equal 'rb', P.lexer_name_for(filename: 'test.rb')
assert_includes P.lexer_names_for(filename: 'test.rb'), 'rb'
assert_equal 'scala', P.lexer_name_for(filename: 'test.scala')
end

def test_lexer_by_name
assert_equal 'rb', P.lexer_name_for(lexer: 'ruby')
assert_includes P.lexer_names_for(lexer: 'ruby'), 'rb'
assert_equal 'python', P.lexer_name_for(lexer: 'python')
assert_equal 'c', P.lexer_name_for(lexer: 'c')
end

def test_lexer_by_filename_and_content
assert_equal 'rb', P.lexer_name_for(RUBY_CODE, filename: 'test.rb')
assert_includes P.lexer_names_for(RUBY_CODE, filename: 'test.rb'), 'rb'
end

def test_lexer_by_content
assert_equal 'rb', P.lexer_name_for(RUBY_CODE)
assert_includes P.lexer_names_for(RUBY_CODE), 'rb'
end

def test_lexer_by_nothing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Major developers are Tim Hatch <tim@timhatch.com> and Armin Ronacher
Other contributors, listed alphabetically, are:

* Sam Aaron -- Ioke lexer
* João Abecasis -- JSLT lexer
* Ali Afshar -- image formatter
* Thomas Aglassinger -- Easytrieve, JCL, Rexx, Transact-SQL and VBScript
lexers
Expand All @@ -32,7 +33,7 @@ Other contributors, listed alphabetically, are:
* Sébastien Bigaret -- QVT Operational lexer
* Jarrett Billingsley -- MiniD lexer
* Adam Blinkinsop -- Haskell, Redcode lexers
* Stéphane Blondon -- SGF and Sieve lexers
* Stéphane Blondon -- Procfile, SGF and Sieve lexers
* Frits van Bommel -- assembler lexers
* Pierre Bourdon -- bugfixes
* Martijn Braam -- Kernel log lexer, BARE lexer
Expand All @@ -48,6 +49,7 @@ Other contributors, listed alphabetically, are:
* Pete Curry -- bugfixes
* Bryan Davis -- EBNF lexer
* Bruno Deferrari -- Shen lexer
* Luke Drummond -- Meson lexer
* Giedrius Dubinskas -- HTML formatter improvements
* Owen Durni -- Haxe lexer
* Alexander Dutton, Oxford University Computing Services -- SPARQL lexer
Expand Down Expand Up @@ -97,6 +99,7 @@ Other contributors, listed alphabetically, are:
* Doug Hogan -- Mscgen lexer
* Ben Hollis -- Mason lexer
* Max Horn -- GAP lexer
* Fred Hornsey -- OMG IDL Lexer
* Alastair Houghton -- Lexer inheritance facility
* Tim Howard -- BlitzMax lexer
* Dustin Howett -- Logos lexer
Expand Down Expand Up @@ -200,6 +203,7 @@ Other contributors, listed alphabetically, are:
* Robert Simmons -- Standard ML lexer
* Kirill Simonov -- YAML lexer
* Corbin Simpson -- Monte lexer
* Ville Skyttä -- ASCII armored lexer
* Alexander Smishlajev -- Visual FoxPro lexer
* Steve Spigarelli -- XQuery lexer
* Jerome St-Louis -- eC lexer
Expand All @@ -208,6 +212,7 @@ Other contributors, listed alphabetically, are:
* Tom Stuart -- Treetop lexer
* Colin Sullivan -- SuperCollider lexer
* Ben Swift -- Extempore lexer
* tatt61880 -- Kuin lexer
* Edoardo Tenani -- Arduino lexer
* Tiberius Teng -- default style overhaul
* Jeremy Thurgood -- Erlang, Squid config lexers
Expand All @@ -223,6 +228,7 @@ Other contributors, listed alphabetically, are:
* Matthias Vallentin -- Bro lexer
* Benoît Vinot -- AMPL lexer
* Linh Vu Hong -- RSL lexer
* Immanuel Washington -- Smithy lexer
* Nathan Weizenbaum -- Haml and Sass lexers
* Nathan Whetsell -- Csound lexers
* Dietmar Winkler -- Modelica lexer
Expand All @@ -239,5 +245,6 @@ Other contributors, listed alphabetically, are:
* 15b3 -- Image Formatter improvements
* Fabian Neumann -- CDDL lexer
* Thomas Duboucher -- CDDL lexer
* Philipp Imhof -- Pango Markup formatter

Many thanks for all contributions!
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: Pygments
Version: 2.8.1
Version: 2.10.0
Summary: Pygments is a syntax highlighting package written in Python.
Home-page: https://pygments.org/
Author: Georg Brandl
Expand Down
Loading