Skip to content

Commit 2daae12

Browse files
authored
resolves #234 update Pygments to 2.10.0 (#235)
1 parent 1b066aa commit 2daae12

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+4136
-1455
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[
88
== Unreleased
99

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

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

bench.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
code = File.open('test/test_pygments.rb').read.to_s * repeats
1313

1414
puts "Benchmarking....\n"
15-
puts 'Size: ' + code.bytesize.to_s + " bytes\n"
16-
puts 'Iterations: ' + num.to_s + "\n"
15+
puts "Size: #{code.bytesize} bytes\n"
16+
puts "Iterations: #{num}\n"
1717

1818
Benchmark.bm(40) do |x|
1919
x.report('pygments popen ') do

lib/pygments.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ def engine
1818
Thread.current.thread_variable_set(:pygments_engine, Pygments::Popen.new)
1919
end
2020

21+
def lexer_name_for(*args)
22+
names = engine.lexer_names_for(*args)
23+
names&.[](0)
24+
end
25+
2126
def_delegators :engine,
2227
:formatters,
2328
:lexers!,
2429
:filters,
2530
:styles,
2631
:css,
27-
:lexer_name_for,
32+
:lexer_names_for,
2833
:highlight,
2934
:start,
3035
:pygments_version

lib/pygments/lexer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def initialize
133133
@mimetypes_index = {}
134134
@raw_lexers = Pygments.lexers!
135135

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

139139
@lexers << lexer

lib/pygments/mentos.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,12 @@ def get_data(self, method, lexer, args, kwargs, text=None):
163163
fmt = pygments.formatters.get_formatter_by_name(args[0], **kwargs)
164164
res = fmt.get_style_defs(args[1])
165165

166-
elif method == 'lexer_name_for':
166+
elif method == 'lexer_names_for':
167167
lexer = self.return_lexer(None, args, kwargs, text)
168168

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

174173
else:
175174
_write_error("No lexer")

lib/pygments/popen.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ def css(klass = '', opts = {})
145145
mentos(:css, ['html', klass], opts)
146146
end
147147

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

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

159-
mentos(:lexer_name_for, args, opts, code)
159+
mentos(:lexer_names_for, args, opts, code)
160160
end
161161

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

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

351351
res
352352
end
353353

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

pygments.rb.gemspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ Gem::Specification.new do |s|
1616

1717
s.metadata = {
1818
'homepage_uri' => s.homepage,
19-
'bug_tracker_uri' => s.homepage + '/issues',
20-
'changelog_uri' => s.homepage + '/blob/master/CHANGELOG.adoc',
21-
'documentation_uri' => 'https://www.rubydoc.info/gems/' + s.name,
19+
'bug_tracker_uri' => "#{s.homepage}/issues",
20+
'changelog_uri' => "#{s.homepage}/blob/master/CHANGELOG.adoc",
21+
'documentation_uri' => "https://www.rubydoc.info/gems/#{s.name}",
2222
'source_code_uri' => s.homepage
2323
}
2424

test/test_pygments.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ def test_highlight_works_with_trailing_newline
9292
end
9393

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

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

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

129129
def test_lexer_by_mimetype
130-
assert_equal 'rb', P.lexer_name_for(mimetype: 'text/x-ruby')
130+
assert_includes P.lexer_names_for(mimetype: 'text/x-ruby'), 'rb'
131131
assert_equal 'json', P.lexer_name_for(mimetype: 'application/json')
132132
end
133133

134134
def test_lexer_by_filename
135-
assert_equal 'rb', P.lexer_name_for(filename: 'test.rb')
135+
assert_includes P.lexer_names_for(filename: 'test.rb'), 'rb'
136136
assert_equal 'scala', P.lexer_name_for(filename: 'test.scala')
137137
end
138138

139139
def test_lexer_by_name
140-
assert_equal 'rb', P.lexer_name_for(lexer: 'ruby')
140+
assert_includes P.lexer_names_for(lexer: 'ruby'), 'rb'
141141
assert_equal 'python', P.lexer_name_for(lexer: 'python')
142142
assert_equal 'c', P.lexer_name_for(lexer: 'c')
143143
end
144144

145145
def test_lexer_by_filename_and_content
146-
assert_equal 'rb', P.lexer_name_for(RUBY_CODE, filename: 'test.rb')
146+
assert_includes P.lexer_names_for(RUBY_CODE, filename: 'test.rb'), 'rb'
147147
end
148148

149149
def test_lexer_by_content
150-
assert_equal 'rb', P.lexer_name_for(RUBY_CODE)
150+
assert_includes P.lexer_names_for(RUBY_CODE), 'rb'
151151
end
152152

153153
def test_lexer_by_nothing

vendor/pygments-main/Pygments-2.8.1.dist-info/AUTHORS renamed to vendor/pygments-main/Pygments-2.10.0.dist-info/AUTHORS

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Major developers are Tim Hatch <[email protected]> and Armin Ronacher
66
Other contributors, listed alphabetically, are:
77

88
* Sam Aaron -- Ioke lexer
9+
* João Abecasis -- JSLT lexer
910
* Ali Afshar -- image formatter
1011
* Thomas Aglassinger -- Easytrieve, JCL, Rexx, Transact-SQL and VBScript
1112
lexers
@@ -32,7 +33,7 @@ Other contributors, listed alphabetically, are:
3233
* Sébastien Bigaret -- QVT Operational lexer
3334
* Jarrett Billingsley -- MiniD lexer
3435
* Adam Blinkinsop -- Haskell, Redcode lexers
35-
* Stéphane Blondon -- SGF and Sieve lexers
36+
* Stéphane Blondon -- Procfile, SGF and Sieve lexers
3637
* Frits van Bommel -- assembler lexers
3738
* Pierre Bourdon -- bugfixes
3839
* Martijn Braam -- Kernel log lexer, BARE lexer
@@ -48,6 +49,7 @@ Other contributors, listed alphabetically, are:
4849
* Pete Curry -- bugfixes
4950
* Bryan Davis -- EBNF lexer
5051
* Bruno Deferrari -- Shen lexer
52+
* Luke Drummond -- Meson lexer
5153
* Giedrius Dubinskas -- HTML formatter improvements
5254
* Owen Durni -- Haxe lexer
5355
* Alexander Dutton, Oxford University Computing Services -- SPARQL lexer
@@ -97,6 +99,7 @@ Other contributors, listed alphabetically, are:
9799
* Doug Hogan -- Mscgen lexer
98100
* Ben Hollis -- Mason lexer
99101
* Max Horn -- GAP lexer
102+
* Fred Hornsey -- OMG IDL Lexer
100103
* Alastair Houghton -- Lexer inheritance facility
101104
* Tim Howard -- BlitzMax lexer
102105
* Dustin Howett -- Logos lexer
@@ -200,6 +203,7 @@ Other contributors, listed alphabetically, are:
200203
* Robert Simmons -- Standard ML lexer
201204
* Kirill Simonov -- YAML lexer
202205
* Corbin Simpson -- Monte lexer
206+
* Ville Skyttä -- ASCII armored lexer
203207
* Alexander Smishlajev -- Visual FoxPro lexer
204208
* Steve Spigarelli -- XQuery lexer
205209
* Jerome St-Louis -- eC lexer
@@ -208,6 +212,7 @@ Other contributors, listed alphabetically, are:
208212
* Tom Stuart -- Treetop lexer
209213
* Colin Sullivan -- SuperCollider lexer
210214
* Ben Swift -- Extempore lexer
215+
* tatt61880 -- Kuin lexer
211216
* Edoardo Tenani -- Arduino lexer
212217
* Tiberius Teng -- default style overhaul
213218
* Jeremy Thurgood -- Erlang, Squid config lexers
@@ -223,6 +228,7 @@ Other contributors, listed alphabetically, are:
223228
* Matthias Vallentin -- Bro lexer
224229
* Benoît Vinot -- AMPL lexer
225230
* Linh Vu Hong -- RSL lexer
231+
* Immanuel Washington -- Smithy lexer
226232
* Nathan Weizenbaum -- Haml and Sass lexers
227233
* Nathan Whetsell -- Csound lexers
228234
* Dietmar Winkler -- Modelica lexer
@@ -239,5 +245,6 @@ Other contributors, listed alphabetically, are:
239245
* 15b3 -- Image Formatter improvements
240246
* Fabian Neumann -- CDDL lexer
241247
* Thomas Duboucher -- CDDL lexer
248+
* Philipp Imhof -- Pango Markup formatter
242249

243250
Many thanks for all contributions!

0 commit comments

Comments
 (0)