@@ -171,18 +171,16 @@ def self.token_path_to_hint hint, kinds
171
171
def setup options
172
172
super
173
173
174
- check_options options
174
+ check_options! options
175
175
176
176
if options [ :wrap ] || options [ :line_numbers ]
177
177
@real_out = @out
178
178
@out = ''
179
179
end
180
180
181
- options [ :break_lines ] = true if options [ :line_numbers ] == :inline
182
181
@break_lines = ( options [ :break_lines ] == true )
183
182
184
- @HTML_ESCAPE = HTML_ESCAPE . dup
185
- @HTML_ESCAPE [ "\t " ] = ' ' * options [ :tab_width ]
183
+ @HTML_ESCAPE = HTML_ESCAPE . merge ( "\t " => ' ' * options [ :tab_width ] )
186
184
187
185
@opened = [ ]
188
186
@last_opened = nil
@@ -271,32 +269,31 @@ def end_line kind
271
269
272
270
protected
273
271
274
- def check_options options
272
+ def check_options! options
275
273
unless [ false , nil , :debug , :info , :info_long ] . include? options [ :hint ]
276
274
raise ArgumentError , "Unknown value %p for :hint; expected :info, :info_long, :debug, false, or nil." % [ options [ :hint ] ]
277
275
end
278
276
279
277
unless [ :class , :style ] . include? options [ :css ]
280
278
raise ArgumentError , 'Unknown value %p for :css.' % [ options [ :css ] ]
281
279
end
280
+
281
+ options [ :break_lines ] = true if options [ :line_numbers ] == :inline
282
282
end
283
283
284
284
def make_span_for_kind method , hint , css
285
- css_classes = TokenKinds
286
-
287
- Hash . new do |h , k |
288
- kind = k . is_a? ( Symbol ) ? k : k . first
289
-
290
- h [ k . is_a? ( Symbol ) ? k : k . dup ] =
291
- if kind != :space && ( ( css_class = css_classes [ kind ] ) || hint )
292
- title = HTML . token_path_to_hint hint , k if hint
293
- if method == :class
294
- "<span#{ title } #{ " class=\" #{ css_class } \" " if css_class } >"
295
- else
296
- style = css . get_style k . is_a? ( Array ) ? k . map { |c | css_classes [ c ] } : [ css_class ]
297
- "<span#{ title } #{ " style=\" #{ style } \" " if style } >"
298
- end
299
- end
285
+ Hash . new do |h , kinds |
286
+ h [ kinds . is_a? ( Symbol ) ? kinds : kinds . dup ] = begin
287
+ css_class = TokenKinds [ kinds . is_a? ( Symbol ) ? kinds : kinds . first ]
288
+ title = HTML . token_path_to_hint hint , kinds if hint
289
+
290
+ if method == :style
291
+ style = css . get_style ( kinds . is_a? ( Array ) ? kinds . map { |c | TokenKinds [ c ] } : [ TokenKinds [ kinds ] ] )
292
+ "<span#{ title } #{ " style=\" #{ style } \" " if style } >"
293
+ else
294
+ "<span#{ title } #{ " class=\" #{ css_class } \" " if css_class } >"
295
+ end if css_class || title
296
+ end
300
297
end
301
298
end
302
299
0 commit comments