mdless 2.1.51 → 2.1.53
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -1
- data/lib/mdless/console.rb +330 -315
- data/lib/mdless/emoji.rb +1894 -0
- data/lib/mdless/string.rb +2 -2
- data/lib/mdless/theme.rb +3 -1
- data/lib/mdless/version.rb +1 -1
- data/lib/mdless.rb +1 -1
- metadata +3 -2
data/lib/mdless/console.rb
CHANGED
@@ -36,16 +36,16 @@ module Redcarpet
|
|
36
36
|
input.split(/\n/).map do |line|
|
37
37
|
if first
|
38
38
|
if line =~ /^\+-+/
|
39
|
-
line.gsub!(/^/, color(
|
39
|
+
line.gsub!(/^/, color('table border'))
|
40
40
|
else
|
41
41
|
first = false
|
42
|
-
line.gsub!(/\|/, "#{color(
|
42
|
+
line.gsub!(/\|/, "#{color('table border')}|#{color('table header')}")
|
43
43
|
end
|
44
44
|
elsif line.strip =~ /^[|:\- +]+$/
|
45
|
-
line.gsub!(/^(.*)$/, "#{color(
|
46
|
-
line.gsub!(/([:\-+]+)/, "#{color(
|
45
|
+
line.gsub!(/^(.*)$/, "#{color('table border')}\\1#{color('table color')}")
|
46
|
+
line.gsub!(/([:\-+]+)/, "#{color('table divider')}\\1#{color('table border')}")
|
47
47
|
else
|
48
|
-
line.gsub!(/\|/, "#{color(
|
48
|
+
line.gsub!(/\|/, "#{color('table border')}|#{color('table color')}")
|
49
49
|
end
|
50
50
|
end.join("\n")
|
51
51
|
end
|
@@ -60,7 +60,7 @@ module Redcarpet
|
|
60
60
|
|
61
61
|
def code_bg(input, width)
|
62
62
|
input.split(/\n/).map do |line|
|
63
|
-
tail = line.uncolor.length < width ? "\u00A0" * (width - line.uncolor.length) :
|
63
|
+
tail = line.uncolor.length < width ? "\u00A0" * (width - line.uncolor.length) : ''
|
64
64
|
"#{x}#{line}#{tail}#{x}"
|
65
65
|
end.join("\n")
|
66
66
|
end
|
@@ -96,39 +96,39 @@ module Redcarpet
|
|
96
96
|
# end.join("\n").blackout(MDLess.theme['code_block']['bg']) + "#{xc}\n"
|
97
97
|
# end
|
98
98
|
|
99
|
-
if MDLess.options[:syntax_higlight] && !exec_available(
|
100
|
-
MDLess.log.error(
|
99
|
+
if MDLess.options[:syntax_higlight] && !exec_available('pygmentize')
|
100
|
+
MDLess.log.error('Syntax highlighting requested by pygmentize is not available')
|
101
101
|
MDLess.options[:syntax_higlight] = false
|
102
102
|
end
|
103
103
|
|
104
104
|
if MDLess.options[:syntax_higlight]
|
105
|
-
pyg = TTY::Which.which(
|
106
|
-
lexer = language&.valid_lexer? ? "-l #{language}" :
|
105
|
+
pyg = TTY::Which.which('pygmentize')
|
106
|
+
lexer = language&.valid_lexer? ? "-l #{language}" : '-g'
|
107
107
|
begin
|
108
|
-
pygments_theme = MDLess.options[:pygments_theme] || MDLess.theme[
|
108
|
+
pygments_theme = MDLess.options[:pygments_theme] || MDLess.theme['code_block']['pygments_theme']
|
109
109
|
|
110
110
|
unless pygments_theme.valid_pygments_theme?
|
111
111
|
MDLess.log.error("Invalid Pygments theme #{pygments_theme}, defaulting to 'default' for highlighting")
|
112
|
-
pygments_theme =
|
112
|
+
pygments_theme = 'default'
|
113
113
|
end
|
114
114
|
|
115
115
|
cmd = [
|
116
116
|
"#{pyg} -f terminal256",
|
117
117
|
"-O style=#{pygments_theme}",
|
118
118
|
lexer,
|
119
|
-
|
120
|
-
].join(
|
119
|
+
'2> /dev/null'
|
120
|
+
].join(' ')
|
121
121
|
hilite, s = Open3.capture2(cmd,
|
122
122
|
stdin_data: code_block)
|
123
123
|
|
124
124
|
if s.success?
|
125
125
|
hilite = xc + hilite.split(/\n/).map do |l|
|
126
126
|
[
|
127
|
-
color(
|
128
|
-
MDLess.theme[
|
129
|
-
"#{color(
|
127
|
+
color('code_block marker'),
|
128
|
+
MDLess.theme['code_block']['character'],
|
129
|
+
"#{color('code_block bg')}#{l}#{xc}"
|
130
130
|
].join
|
131
|
-
end.join("\n").blackout(MDLess.theme[
|
131
|
+
end.join("\n").blackout(MDLess.theme['code_block']['bg']) + "#{xc}\n"
|
132
132
|
end
|
133
133
|
rescue StandardError => e
|
134
134
|
MDLess.log.error(e)
|
@@ -137,32 +137,32 @@ module Redcarpet
|
|
137
137
|
else
|
138
138
|
hilite = code_block.split(/\n/).map do |line|
|
139
139
|
[
|
140
|
-
color(
|
141
|
-
MDLess.theme[
|
142
|
-
color(
|
140
|
+
color('code_block marker'),
|
141
|
+
MDLess.theme['code_block']['character'],
|
142
|
+
color('code_block color'),
|
143
143
|
line,
|
144
|
-
xc
|
144
|
+
xc
|
145
145
|
].join
|
146
|
-
end.join("\n").blackout(MDLess.theme[
|
146
|
+
end.join("\n").blackout(MDLess.theme['code_block']['bg']) + "#{xc}\n"
|
147
147
|
end
|
148
148
|
|
149
149
|
top_border = if language.nil? || language.empty?
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
150
|
+
'-' * longest_line
|
151
|
+
else
|
152
|
+
"--[ #{language} ]#{'-' * (longest_line - 6 - language.length)}"
|
153
|
+
end
|
154
154
|
[
|
155
155
|
xc,
|
156
|
-
color(
|
156
|
+
color('code_block border'),
|
157
157
|
top_border,
|
158
158
|
xc,
|
159
159
|
"\n",
|
160
|
-
color(
|
160
|
+
color('code_block color'),
|
161
161
|
code_bg(hilite.chomp, longest_line),
|
162
162
|
"\n",
|
163
|
-
color(
|
164
|
-
|
165
|
-
xc
|
163
|
+
color('code_block border'),
|
164
|
+
'-' * longest_line,
|
165
|
+
xc
|
166
166
|
].join
|
167
167
|
end
|
168
168
|
|
@@ -173,14 +173,14 @@ module Redcarpet
|
|
173
173
|
if MDLess.theme.key?(keys[0])
|
174
174
|
val = MDLess.theme[keys.shift]
|
175
175
|
else
|
176
|
-
MDLess.log.error("Invalid theme key
|
176
|
+
MDLess.log.error("Invalid theme key~: #{key}") unless keys[0] =~ /^text/
|
177
177
|
return c([:reset])
|
178
178
|
end
|
179
179
|
keys.each do |k|
|
180
180
|
if val.key?(k)
|
181
181
|
val = val[k]
|
182
182
|
else
|
183
|
-
MDLess.log.error("Invalid theme key
|
183
|
+
MDLess.log.error("Invalid theme key*: #{k}")
|
184
184
|
return c([:reset])
|
185
185
|
end
|
186
186
|
end
|
@@ -199,56 +199,56 @@ module Redcarpet
|
|
199
199
|
|
200
200
|
def block_quote(quote)
|
201
201
|
ret = "\n\n"
|
202
|
-
quote.strip.wrap(MDLess.cols, color(
|
202
|
+
quote.strip.wrap(MDLess.cols, color('blockquote color')).split(/\n/).each do |line|
|
203
203
|
ret += [
|
204
|
-
color(
|
205
|
-
MDLess.theme[
|
206
|
-
color(
|
207
|
-
|
204
|
+
color('blockquote marker color'),
|
205
|
+
MDLess.theme['blockquote']['marker']['character'],
|
206
|
+
color('blockquote color'),
|
207
|
+
' ',
|
208
208
|
line,
|
209
|
-
"\n"
|
210
|
-
].join(
|
209
|
+
"\n"
|
210
|
+
].join('')
|
211
211
|
end
|
212
212
|
"#{ret}\n\n"
|
213
213
|
end
|
214
214
|
|
215
215
|
def block_html(raw_html)
|
216
|
-
"#{color(
|
216
|
+
"#{color('html color')}#{color_tags(raw_html)}#{xc}"
|
217
217
|
end
|
218
218
|
|
219
219
|
def header(text, header_level)
|
220
|
-
pad =
|
221
|
-
ansi =
|
220
|
+
pad = ''
|
221
|
+
ansi = ''
|
222
222
|
text.clean_header_ids!
|
223
|
-
uncolored = text.uncolor.gsub(/<<(pre|post)\d+>>/,
|
223
|
+
uncolored = text.uncolor.gsub(/<<(pre|post)\d+>>/, '')
|
224
224
|
uncolored.sub!(/\[(.*?)\]\(.*?\)/, '[\1][xxx]') if MDLess.options[:links] != :inline
|
225
225
|
|
226
226
|
text_length = uncolored.length
|
227
227
|
case header_level
|
228
228
|
when 1
|
229
|
-
ansi = color(
|
230
|
-
pad = color(
|
231
|
-
char = MDLess.theme[
|
229
|
+
ansi = color('h1 color')
|
230
|
+
pad = color('h1 pad')
|
231
|
+
char = MDLess.theme['h1']['pad_char'] || '='
|
232
232
|
pad += text_length + 2 > MDLess.cols ? char * text_length : char * (MDLess.cols - (text_length + 1))
|
233
233
|
when 2
|
234
|
-
ansi = color(
|
235
|
-
pad = color(
|
236
|
-
char = MDLess.theme[
|
234
|
+
ansi = color('h2 color')
|
235
|
+
pad = color('h2 pad')
|
236
|
+
char = MDLess.theme['h2']['pad_char'] || '-'
|
237
237
|
pad += text_length + 2 > MDLess.cols ? char * text_length : char * (MDLess.cols - (text_length + 1))
|
238
238
|
when 3
|
239
|
-
ansi = color(
|
239
|
+
ansi = color('h3 color')
|
240
240
|
when 4
|
241
|
-
ansi = color(
|
241
|
+
ansi = color('h4 color')
|
242
242
|
when 5
|
243
|
-
ansi = color(
|
243
|
+
ansi = color('h5 color')
|
244
244
|
else
|
245
|
-
ansi = color(
|
245
|
+
ansi = color('h6 color')
|
246
246
|
end
|
247
247
|
|
248
248
|
# If we're in iTerm and not paginating, add
|
249
249
|
# iTerm Marks for navigation on h1-3
|
250
250
|
if header_level < 4 &&
|
251
|
-
ENV[
|
251
|
+
ENV['TERM_PROGRAM'] =~ /^iterm/i &&
|
252
252
|
MDLess.options[:pager] == false
|
253
253
|
ansi = "\e]1337;SetMark\a#{ansi}"
|
254
254
|
end
|
@@ -256,21 +256,21 @@ module Redcarpet
|
|
256
256
|
"\n\n#{xc}#{ansi}#{text} #{pad}#{xc}\n\n"
|
257
257
|
end
|
258
258
|
|
259
|
-
def hrule
|
260
|
-
"\n\n#{color(
|
259
|
+
def hrule
|
260
|
+
"\n\n#{color('hr color')}#{'_' * MDLess.cols}#{xc}\n\n"
|
261
261
|
end
|
262
262
|
|
263
263
|
def paragraph(text)
|
264
264
|
text.scrub!
|
265
265
|
out = if MDLess.options[:preserve_linebreaks]
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
266
|
+
"#{xc}#{text.gsub(/ +/, ' ').strip}#{xc}#{x}\n\n"
|
267
|
+
else
|
268
|
+
if text.uncolor =~ / {2,}$/ || text.uncolor =~ /^%/
|
269
|
+
"#{xc}#{text.gsub(/ +/, ' ').strip}#{xc}#{x}\n"
|
270
|
+
else
|
271
|
+
"#{xc}#{text.gsub(/ +/, ' ').gsub(/\n+(?![:-])/, ' ').strip}#{xc}#{x}\n\n"
|
272
|
+
end
|
273
|
+
end
|
274
274
|
if MDLess.options[:at_tags] || MDLess.options[:taskpaper]
|
275
275
|
highlight_tags(out)
|
276
276
|
else
|
@@ -279,7 +279,7 @@ module Redcarpet
|
|
279
279
|
end
|
280
280
|
|
281
281
|
def uncolor_grafs(text)
|
282
|
-
text.gsub(/#{Regexp.escape(color("text"))}/, color(
|
282
|
+
text.gsub(/#{Regexp.escape(color("text"))}/, color('list color'))
|
283
283
|
end
|
284
284
|
|
285
285
|
@table_cols = nil
|
@@ -288,24 +288,24 @@ module Redcarpet
|
|
288
288
|
@header_row.map do |alignment|
|
289
289
|
case alignment
|
290
290
|
when :left
|
291
|
-
|
291
|
+
'|:---'
|
292
292
|
when :right
|
293
|
-
|
293
|
+
'|---:'
|
294
294
|
when :center
|
295
|
-
|
295
|
+
'|:--:'
|
296
296
|
else
|
297
|
-
|
297
|
+
'|----'
|
298
298
|
end
|
299
|
-
end.join(
|
299
|
+
end.join('') + '|'
|
300
300
|
end
|
301
301
|
|
302
302
|
def table(header, body)
|
303
303
|
formatted = CLIMarkdown::MDTableCleanup.new([
|
304
|
-
|
304
|
+
header.to_s,
|
305
305
|
table_header_row,
|
306
306
|
"|\n",
|
307
|
-
"#{body}\n\n"
|
308
|
-
].join(
|
307
|
+
"#{body}\n\n"
|
308
|
+
].join(''))
|
309
309
|
@header_row = []
|
310
310
|
res = formatted.to_md
|
311
311
|
"#{color_table(res)}\n\n"
|
@@ -319,80 +319,78 @@ module Redcarpet
|
|
319
319
|
|
320
320
|
def table_cell(content, alignment)
|
321
321
|
@header_row ||= []
|
322
|
-
if @table_cols && @header_row.count < @table_cols
|
323
|
-
@header_row << alignment
|
324
|
-
end
|
322
|
+
@header_row << alignment if @table_cols && @header_row.count < @table_cols
|
325
323
|
%(#{content} |)
|
326
324
|
end
|
327
325
|
|
328
326
|
def autolink(link, _)
|
329
327
|
[
|
330
328
|
pre_element,
|
331
|
-
color(
|
332
|
-
|
333
|
-
color(
|
329
|
+
color('link brackets'),
|
330
|
+
'<',
|
331
|
+
color('link url'),
|
334
332
|
link,
|
335
|
-
color(
|
336
|
-
|
333
|
+
color('link brackets'),
|
334
|
+
'>',
|
337
335
|
xc,
|
338
|
-
post_element
|
339
|
-
].join(
|
336
|
+
post_element
|
337
|
+
].join('')
|
340
338
|
end
|
341
339
|
|
342
340
|
def codespan(code)
|
343
341
|
out = [
|
344
342
|
pre_element,
|
345
|
-
color(
|
346
|
-
MDLess.theme[
|
347
|
-
color(
|
343
|
+
color('code_span marker'),
|
344
|
+
MDLess.theme['code_span']['character'],
|
345
|
+
color('code_span color'),
|
348
346
|
code,
|
349
|
-
color(
|
350
|
-
MDLess.theme[
|
347
|
+
color('code_span marker'),
|
348
|
+
MDLess.theme['code_span']['character'],
|
351
349
|
xc,
|
352
|
-
post_element
|
350
|
+
post_element
|
353
351
|
].join
|
354
352
|
end
|
355
353
|
|
356
354
|
def double_emphasis(text)
|
357
355
|
[
|
358
356
|
pre_element,
|
359
|
-
color(
|
360
|
-
MDLess.theme[
|
357
|
+
color('emphasis bold'),
|
358
|
+
MDLess.theme['emphasis']['bold_character'],
|
361
359
|
text,
|
362
|
-
MDLess.theme[
|
360
|
+
MDLess.theme['emphasis']['bold_character'],
|
363
361
|
xc,
|
364
|
-
post_element
|
362
|
+
post_element
|
365
363
|
].join
|
366
364
|
end
|
367
365
|
|
368
366
|
def emphasis(text)
|
369
367
|
[
|
370
368
|
pre_element,
|
371
|
-
color(
|
372
|
-
MDLess.theme[
|
369
|
+
color('emphasis italic'),
|
370
|
+
MDLess.theme['emphasis']['italic_character'],
|
373
371
|
text,
|
374
|
-
MDLess.theme[
|
372
|
+
MDLess.theme['emphasis']['italic_character'],
|
375
373
|
xc,
|
376
|
-
post_element
|
374
|
+
post_element
|
377
375
|
].join
|
378
376
|
end
|
379
377
|
|
380
378
|
def triple_emphasis(text)
|
381
379
|
[
|
382
380
|
pre_element,
|
383
|
-
color(
|
384
|
-
MDLess.theme[
|
385
|
-
MDLess.theme[
|
381
|
+
color('emphasis bold-italic'),
|
382
|
+
MDLess.theme['emphasis']['italic_character'],
|
383
|
+
MDLess.theme['emphasis']['bold_character'],
|
386
384
|
text,
|
387
|
-
MDLess.theme[
|
388
|
-
MDLess.theme[
|
385
|
+
MDLess.theme['emphasis']['bold_character'],
|
386
|
+
MDLess.theme['emphasis']['italic_character'],
|
389
387
|
xc,
|
390
|
-
post_element
|
388
|
+
post_element
|
391
389
|
].join
|
392
390
|
end
|
393
391
|
|
394
392
|
def highlight(text)
|
395
|
-
"#{pre_element}#{color(
|
393
|
+
"#{pre_element}#{color('highlight')}#{text}#{xc}#{post_element}"
|
396
394
|
end
|
397
395
|
|
398
396
|
def image(link, title, alt_text)
|
@@ -406,35 +404,35 @@ module Redcarpet
|
|
406
404
|
def color_link(link, title, content)
|
407
405
|
[
|
408
406
|
pre_element,
|
409
|
-
color(
|
410
|
-
|
411
|
-
color(
|
407
|
+
color('link brackets'),
|
408
|
+
'[',
|
409
|
+
color('link text'),
|
412
410
|
content,
|
413
|
-
color(
|
414
|
-
|
415
|
-
color(
|
411
|
+
color('link brackets'),
|
412
|
+
'](',
|
413
|
+
color('link url'),
|
416
414
|
link,
|
417
|
-
title.nil? ?
|
418
|
-
color(
|
419
|
-
|
415
|
+
title.nil? ? '' : %( "#{title}"),
|
416
|
+
color('link brackets'),
|
417
|
+
')',
|
420
418
|
xc,
|
421
|
-
post_element
|
419
|
+
post_element
|
422
420
|
].join
|
423
421
|
end
|
424
422
|
|
425
423
|
def color_image_tag(link, title, alt_text)
|
426
424
|
image = [
|
427
|
-
color(
|
428
|
-
|
429
|
-
color(
|
425
|
+
color('image brackets'),
|
426
|
+
'[',
|
427
|
+
color('image title'),
|
430
428
|
alt_text,
|
431
|
-
color(
|
432
|
-
|
433
|
-
color(
|
429
|
+
color('image brackets'),
|
430
|
+
'](',
|
431
|
+
color('image url'),
|
434
432
|
link,
|
435
|
-
title.nil? ?
|
436
|
-
color(
|
437
|
-
|
433
|
+
title.nil? ? '' : %( "#{title}"),
|
434
|
+
color('image brackets'),
|
435
|
+
')'
|
438
436
|
].join
|
439
437
|
|
440
438
|
@@links << {
|
@@ -442,67 +440,67 @@ module Redcarpet
|
|
442
440
|
url: link,
|
443
441
|
title: title,
|
444
442
|
content: alt_text,
|
445
|
-
image: true
|
443
|
+
image: true
|
446
444
|
}
|
447
445
|
|
448
446
|
[
|
449
|
-
color(
|
450
|
-
|
447
|
+
color('image bang'),
|
448
|
+
'!',
|
451
449
|
image,
|
452
|
-
xc
|
450
|
+
xc
|
453
451
|
].join
|
454
452
|
end
|
455
453
|
|
456
|
-
def color_link_reference(
|
454
|
+
def color_link_reference(_link, idx, content)
|
457
455
|
[
|
458
456
|
pre_element,
|
459
|
-
color(
|
460
|
-
|
461
|
-
color(
|
457
|
+
color('link brackets'),
|
458
|
+
'[',
|
459
|
+
color('link text'),
|
462
460
|
content,
|
463
|
-
color(
|
464
|
-
|
465
|
-
color(
|
461
|
+
color('link brackets'),
|
462
|
+
'][',
|
463
|
+
color('link url'),
|
466
464
|
idx,
|
467
|
-
color(
|
468
|
-
|
465
|
+
color('link brackets'),
|
466
|
+
']',
|
469
467
|
xc,
|
470
|
-
post_element
|
468
|
+
post_element
|
471
469
|
].join
|
472
470
|
end
|
473
471
|
|
474
472
|
def color_reference_link(link, title, content, image: false)
|
475
473
|
[
|
476
|
-
color(
|
477
|
-
|
478
|
-
color(
|
474
|
+
color('link brackets'),
|
475
|
+
'[',
|
476
|
+
color('link text'),
|
479
477
|
content,
|
480
|
-
color(
|
481
|
-
|
482
|
-
color(
|
483
|
-
|
484
|
-
image ? color(
|
478
|
+
color('link brackets'),
|
479
|
+
']:',
|
480
|
+
color('text'),
|
481
|
+
' ',
|
482
|
+
image ? color('image url') : color('link url'),
|
485
483
|
link,
|
486
|
-
title.nil? ?
|
487
|
-
xc
|
484
|
+
title.nil? ? '' : %( "#{title}"),
|
485
|
+
xc
|
488
486
|
].join
|
489
487
|
end
|
490
488
|
|
491
489
|
def color_image_reference(idx, content)
|
492
490
|
[
|
493
491
|
pre_element,
|
494
|
-
color(
|
495
|
-
|
496
|
-
color(
|
492
|
+
color('image brackets'),
|
493
|
+
'[',
|
494
|
+
color('image title'),
|
497
495
|
content,
|
498
|
-
color(
|
499
|
-
|
500
|
-
color(
|
496
|
+
color('image brackets'),
|
497
|
+
'][',
|
498
|
+
color('link url'),
|
501
499
|
idx,
|
502
|
-
color(
|
503
|
-
|
500
|
+
color('image brackets'),
|
501
|
+
']',
|
504
502
|
xc,
|
505
|
-
post_element
|
503
|
+
post_element
|
506
504
|
].join
|
507
505
|
end
|
508
506
|
|
@@ -512,28 +510,28 @@ module Redcarpet
|
|
512
510
|
link: res,
|
513
511
|
url: link,
|
514
512
|
title: title,
|
515
|
-
content: content
|
513
|
+
content: content
|
516
514
|
}
|
517
515
|
res
|
518
516
|
end
|
519
517
|
|
520
518
|
def color_tags(html)
|
521
|
-
html.gsub(%r{((?!<)</?\w+( [^>]+)?>)}, "#{color(
|
519
|
+
html.gsub(%r{((?!<)</?\w+( [^>]+)?>)}, "#{color('html brackets')}\\1#{xc}")
|
522
520
|
end
|
523
521
|
|
524
522
|
def raw_html(raw_html)
|
525
|
-
"#{pre_element}#{color(
|
523
|
+
"#{pre_element}#{color('html color')}#{color_tags(raw_html)}#{xc}#{post_element}"
|
526
524
|
end
|
527
525
|
|
528
526
|
def strikethrough(text)
|
529
|
-
"#{pre_element}#{color(
|
527
|
+
"#{pre_element}#{color('deletion')}#{text}#{xc}#{post_element}"
|
530
528
|
end
|
531
529
|
|
532
530
|
def superscript(text)
|
533
|
-
"#{pre_element}#{color(
|
531
|
+
"#{pre_element}#{color('super')}^#{text}#{xc}#{post_element}"
|
534
532
|
end
|
535
533
|
|
536
|
-
def footnotes(
|
534
|
+
def footnotes(_text)
|
537
535
|
# [
|
538
536
|
# color('footnote note'),
|
539
537
|
# text,
|
@@ -546,20 +544,20 @@ module Redcarpet
|
|
546
544
|
def color_footnote_def(idx)
|
547
545
|
text = @@footnotes[idx]
|
548
546
|
[
|
549
|
-
color(
|
550
|
-
|
551
|
-
color(
|
552
|
-
|
553
|
-
color(
|
547
|
+
color('footnote brackets'),
|
548
|
+
'[',
|
549
|
+
color('footnote caret'),
|
550
|
+
'^',
|
551
|
+
color('footnote title'),
|
554
552
|
idx,
|
555
|
-
color(
|
556
|
-
|
557
|
-
color(
|
558
|
-
|
553
|
+
color('footnote brackets'),
|
554
|
+
']:',
|
555
|
+
color('footnote note'),
|
556
|
+
' ',
|
559
557
|
text.uncolor.strip,
|
560
558
|
xc,
|
561
|
-
"\n"
|
562
|
-
].join(
|
559
|
+
"\n"
|
560
|
+
].join('')
|
563
561
|
end
|
564
562
|
|
565
563
|
def footnote_def(text, idx)
|
@@ -569,18 +567,18 @@ module Redcarpet
|
|
569
567
|
def footnote_ref(text)
|
570
568
|
[
|
571
569
|
pre_element,
|
572
|
-
color(
|
570
|
+
color('footnote title'),
|
573
571
|
"[^#{text}]",
|
574
572
|
xc,
|
575
|
-
post_element
|
576
|
-
].join(
|
573
|
+
post_element
|
574
|
+
].join('')
|
577
575
|
end
|
578
576
|
|
579
577
|
def insert_footnotes(input)
|
580
578
|
input.split(/\n/).map do |line|
|
581
579
|
notes = line.to_enum(:scan, /\[\^(?<ref>\d+)\]/).map { Regexp.last_match }
|
582
580
|
if notes.count.positive?
|
583
|
-
footnotes = notes.map { |n| color_footnote_def(n[
|
581
|
+
footnotes = notes.map { |n| color_footnote_def(n['ref'].to_i) }.join("\n")
|
584
582
|
"#{line}\n\n#{footnotes}\n\n\n"
|
585
583
|
else
|
586
584
|
line
|
@@ -608,7 +606,7 @@ module Redcarpet
|
|
608
606
|
|
609
607
|
lines = input.split(/\n/)
|
610
608
|
line1 = lines.shift
|
611
|
-
pre =
|
609
|
+
pre = ' '
|
612
610
|
|
613
611
|
body = lines.map { |l| "#{pre}#{l.rstrip}" }.join("\n")
|
614
612
|
"#{line1}\n#{body}"
|
@@ -616,26 +614,26 @@ module Redcarpet
|
|
616
614
|
|
617
615
|
def color_list_item(indent, content, type, counter)
|
618
616
|
out = case type
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
617
|
+
when :unordered
|
618
|
+
[
|
619
|
+
' ' * indent,
|
620
|
+
color('list bullet'),
|
621
|
+
MDLess.theme['list']['ul_char'].strip,
|
622
|
+
' ',
|
623
|
+
color('list color'),
|
624
|
+
indent_lines(content).strip,
|
625
|
+
xc
|
626
|
+
].join
|
627
|
+
when :ordered
|
628
|
+
[
|
629
|
+
' ' * indent,
|
630
|
+
color('list number'),
|
631
|
+
"#{counter}. ",
|
632
|
+
color('list color'),
|
633
|
+
indent_lines(content).strip,
|
634
|
+
xc
|
635
|
+
].join
|
636
|
+
end
|
639
637
|
if MDLess.options[:at_tags] || MDLess.options[:taskpaper]
|
640
638
|
color_tags(out)
|
641
639
|
else
|
@@ -656,7 +654,7 @@ module Redcarpet
|
|
656
654
|
def nest_lists(input, indent = 0)
|
657
655
|
input.gsub!(%r{<<list(?<id>\d+)-(?<type>.*?)>>(?<content>.*?)<</list\k<id>>>}m) do
|
658
656
|
m = Regexp.last_match
|
659
|
-
lines = m[
|
657
|
+
lines = m['content'].strip.split(/\n/)
|
660
658
|
|
661
659
|
list = nest_lists(lines.map do |l|
|
662
660
|
outdent = l.scan(%r{<</list\d+>>}).count
|
@@ -666,18 +664,18 @@ module Redcarpet
|
|
666
664
|
end.join("\n"), indent)
|
667
665
|
next if list.nil?
|
668
666
|
|
669
|
-
"<<main#{m[
|
667
|
+
"<<main#{m['id']}>>#{list}<</main#{m['id']}>>\n\n"
|
670
668
|
end
|
671
669
|
|
672
|
-
input.gsub(
|
670
|
+
input.gsub(%r{^(?<indent> +)<<main(?<id>\d+)>>(?<content>.*?)<</main\k<id>>>}m) do
|
673
671
|
m = Regexp.last_match
|
674
|
-
"#{m[
|
672
|
+
"#{m['indent']}#{m['content']}"
|
675
673
|
end
|
676
674
|
end
|
677
675
|
|
678
676
|
def normalize_indentation(line)
|
679
677
|
line.gsub(/^([ \t]+)/) do |pre|
|
680
|
-
pre.gsub(/\t/,
|
678
|
+
pre.gsub(/\t/, ' ')
|
681
679
|
end
|
682
680
|
end
|
683
681
|
|
@@ -685,8 +683,8 @@ module Redcarpet
|
|
685
683
|
content.gsub(%r{^(?<indent> *)<<listitem(?<id>\d+)-(?<type>(?:un)?ordered)>>(?<content>.*?)<</listitem\k<id>>>}m) do
|
686
684
|
m = Regexp.last_match
|
687
685
|
|
688
|
-
indent = m[
|
689
|
-
if m[
|
686
|
+
indent = m['indent'].length
|
687
|
+
if m['type'].to_sym == :ordered
|
690
688
|
if indent == last_indent
|
691
689
|
levels[indent] ||= 0
|
692
690
|
levels[indent] += 1
|
@@ -700,15 +698,15 @@ module Redcarpet
|
|
700
698
|
end
|
701
699
|
end
|
702
700
|
|
703
|
-
content = m[
|
704
|
-
color_list_item(indent, uncolor_grafs(content), m[
|
701
|
+
content = m['content'] =~ /<<listitem/ ? fix_items(m['content'], indent, levels) : m['content']
|
702
|
+
color_list_item(indent, uncolor_grafs(content), m['type'].to_sym, levels[indent])
|
705
703
|
end
|
706
704
|
end
|
707
705
|
|
708
706
|
def fix_list_items(input)
|
709
707
|
input.gsub(%r{<<main(?<id>\d+)>>(?<content>.*?)<</main\k<id>>>}m) do
|
710
708
|
m = Regexp.last_match
|
711
|
-
fix_items(m[
|
709
|
+
fix_items(m['content'])
|
712
710
|
end
|
713
711
|
end
|
714
712
|
|
@@ -731,9 +729,9 @@ module Redcarpet
|
|
731
729
|
title = h[2]
|
732
730
|
end
|
733
731
|
@headers << [
|
734
|
-
|
732
|
+
'#' * hlevel,
|
735
733
|
title,
|
736
|
-
h[0]
|
734
|
+
h[0]
|
737
735
|
]
|
738
736
|
end
|
739
737
|
end
|
@@ -747,16 +745,16 @@ module Redcarpet
|
|
747
745
|
MDLess.meta = {}
|
748
746
|
first_line = input.split("\n").first
|
749
747
|
if first_line =~ /(?i-m)^---[ \t]*?$/
|
750
|
-
MDLess.log.info(
|
748
|
+
MDLess.log.info('Found YAML')
|
751
749
|
# YAML
|
752
750
|
in_yaml = true
|
753
751
|
input.sub!(/(?i-m)^---[ \t]*\n(?<content>(?:[\s\S]*?))\n[-.]{3}[ \t]*\n/m) do
|
754
752
|
m = Regexp.last_match
|
755
|
-
MDLess.log.info(
|
753
|
+
MDLess.log.info('Processing YAML header')
|
756
754
|
begin
|
757
|
-
MDLess.meta = YAML.unsafe_load(m[
|
755
|
+
MDLess.meta = YAML.unsafe_load(m['content']).each_with_object({}) { |(k, v), h| h[k.downcase] = v }
|
758
756
|
rescue Psych::DisallowedClass => e
|
759
|
-
@log.error(
|
757
|
+
@log.error('Error reading YAML header')
|
760
758
|
@log.error(e)
|
761
759
|
MDLess.meta = {}
|
762
760
|
rescue StandardError => e
|
@@ -768,19 +766,21 @@ module Redcarpet
|
|
768
766
|
longest = longest < MDLess.cols ? longest + 1 : MDLess.cols
|
769
767
|
lines.map do |line|
|
770
768
|
if line =~ /^[-.]{3}\s*$/
|
771
|
-
line = "#{color(
|
769
|
+
line = "#{color('metadata marker')}#{'%' * longest}"
|
772
770
|
else
|
773
771
|
line.sub!(/^(.*?:)[ \t]+(\S)/, '\1 \2')
|
774
|
-
line = "#{color(
|
772
|
+
line = "#{color('metadata marker')}% #{color('metadata color')}#{line}"
|
773
|
+
end
|
774
|
+
if (longest - line.uncolor.strip.length).positive?
|
775
|
+
line += "\u00A0" * (longest - line.uncolor.strip.length)
|
775
776
|
end
|
776
|
-
line += "\u00A0" * (longest - line.uncolor.strip.length) if (longest - line.uncolor.strip.length).positive?
|
777
777
|
line + xc
|
778
778
|
end.join("\n") + "#{xc}\n"
|
779
779
|
end
|
780
780
|
end
|
781
781
|
|
782
782
|
if !in_yaml && first_line =~ /(?i-m)^[\w ]+:\s+\S+/
|
783
|
-
MDLess.log.info(
|
783
|
+
MDLess.log.info('Found MMD Headers')
|
784
784
|
input.sub!(/(?i-m)^([\S ]+:[\s\S]*?)+(?=\n *\n)/) do |mmd|
|
785
785
|
lines = mmd.split(/\n/)
|
786
786
|
return mmd if lines.count > 20
|
@@ -792,12 +792,14 @@ module Redcarpet
|
|
792
792
|
line.sub!(/^(.*?:)[ \t]+(\S)/, '\1 \2')
|
793
793
|
parts = line.match(/^[ \t]*(\S.*?):[ \t]+(\S.*?)$/)
|
794
794
|
if parts
|
795
|
-
key = parts[1].gsub(/[^a-z0-9\-_]/i,
|
795
|
+
key = parts[1].gsub(/[^a-z0-9\-_]/i, '')
|
796
796
|
value = parts[2].strip
|
797
797
|
MDLess.meta[key] = value
|
798
798
|
end
|
799
|
-
line = "#{color(
|
800
|
-
|
799
|
+
line = "#{color('metadata marker')}%#{color('metadata color')}#{line}"
|
800
|
+
if (longest - line.uncolor.strip.length).positive?
|
801
|
+
line += "\u00A0" * (longest - line.uncolor.strip.length)
|
802
|
+
end
|
801
803
|
line + xc
|
802
804
|
end.join("\n") + "#{xc}\n"
|
803
805
|
end
|
@@ -807,15 +809,15 @@ module Redcarpet
|
|
807
809
|
end
|
808
810
|
|
809
811
|
def mmd_transclude(input)
|
810
|
-
return input unless MDLess.file || MDLess.meta.key?(
|
812
|
+
return input unless MDLess.file || MDLess.meta.key?('transcludebase')
|
811
813
|
|
812
814
|
input.gsub(/^{{(.*?)}}/) do |m|
|
813
815
|
filename = Regexp.last_match(1).strip
|
814
|
-
file = if MDLess.meta.key?(
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
816
|
+
file = if MDLess.meta.key?('transcludebase')
|
817
|
+
File.join(File.expand_path(MDLess.meta['transcludebase']), filename)
|
818
|
+
else
|
819
|
+
File.join(File.dirname(MDLess.file), filename)
|
820
|
+
end
|
819
821
|
File.exist?(file) ? "\n\n#{mmd_transclude(IO.read(file).remove_meta)}\n\n" : m
|
820
822
|
end
|
821
823
|
end
|
@@ -850,13 +852,13 @@ module Redcarpet
|
|
850
852
|
|
851
853
|
if MDLess.options[:section]
|
852
854
|
new_content = []
|
853
|
-
MDLess.log.info("Matching section(s) #{MDLess.options[:section].join(
|
855
|
+
MDLess.log.info("Matching section(s) #{MDLess.options[:section].join(', ')}")
|
854
856
|
MDLess.options[:section].each do |sect|
|
855
857
|
comparison = MDLess.options[:section][0].is_a?(String) ? :regex : :numeric
|
856
858
|
|
857
859
|
in_section = false
|
858
860
|
top_level = 1
|
859
|
-
input.split(/\n/).each_with_index do |graf,
|
861
|
+
input.split(/\n/).each_with_index do |graf, _idx|
|
860
862
|
if graf =~ /^(#+) *(.*?)( *#+)?$/
|
861
863
|
m = Regexp.last_match
|
862
864
|
level = m[1].length
|
@@ -887,7 +889,20 @@ module Redcarpet
|
|
887
889
|
# definition lists
|
888
890
|
input.gsub!(/(?mi)(?<=\n|\A)(?<term>(?!<:)[^\n]+)(?<def>(\n+: [^\n]+)+)/) do
|
889
891
|
m = Regexp.last_match
|
890
|
-
"#{color(
|
892
|
+
"#{color('dd term')}#{m['term']}#{xc}#{color('dd color')}#{color_dd_def(m['def'])}"
|
893
|
+
end
|
894
|
+
|
895
|
+
# deletions
|
896
|
+
input.gsub!(/(?mi)(?<=\n|\A)~~(?<text>.*?)~~/) do
|
897
|
+
m = Regexp.last_match
|
898
|
+
"#{color('deletion')}#{m['text']}#{xc}"
|
899
|
+
end
|
900
|
+
|
901
|
+
# emojis
|
902
|
+
input.gsub!(/(?<=\s|\A):(?<emoji>[\w-]+):/) do
|
903
|
+
m = Regexp.last_match
|
904
|
+
emoji = CLIMarkdown::Emoji.convert_emoji(m['emoji'])
|
905
|
+
"#{emoji}#{xc}"
|
891
906
|
end
|
892
907
|
|
893
908
|
input
|
@@ -897,11 +912,11 @@ module Redcarpet
|
|
897
912
|
input.gsub(/(?<=\n|\A)(?::)\s+(.*)/) do
|
898
913
|
m = Regexp.last_match
|
899
914
|
[
|
900
|
-
color(
|
901
|
-
|
902
|
-
color(
|
915
|
+
color('dd marker'),
|
916
|
+
': ',
|
917
|
+
color('dd color'),
|
903
918
|
m[1],
|
904
|
-
xc
|
919
|
+
xc
|
905
920
|
].join
|
906
921
|
end
|
907
922
|
end
|
@@ -909,7 +924,7 @@ module Redcarpet
|
|
909
924
|
def color_links(input)
|
910
925
|
input.gsub(/(?mi)(?<!\\e)\[(?<text>[^\[]+)\]\((?<url>\S+)(?: +"(?<title>.*?)")? *\)/) do
|
911
926
|
m = Regexp.last_match
|
912
|
-
color_link(m[
|
927
|
+
color_link(m['url'].uncolor, m['title']&.uncolor, m['text'].uncolor)
|
913
928
|
end
|
914
929
|
end
|
915
930
|
|
@@ -923,38 +938,38 @@ module Redcarpet
|
|
923
938
|
links_added = false
|
924
939
|
|
925
940
|
@@links.each do |link|
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
else
|
944
|
-
graf.gsub!(/#{Regexp.escape(link[:link].gsub(/\n/, " "))}/, colored_link)
|
941
|
+
next unless graf =~ /#{Regexp.escape(link[:link].gsub(/\n/, " "))}/
|
942
|
+
|
943
|
+
table = graf.uncolor =~ /^ *\|/
|
944
|
+
url = link[:url].uncolor
|
945
|
+
content = link[:content]
|
946
|
+
title = link[:title]&.uncolor
|
947
|
+
image = link.key?(:image) && link[:image] ? true : false
|
948
|
+
colored_link = image ? color_image_reference(counter, content) : color_link_reference(url, counter, content)
|
949
|
+
if table
|
950
|
+
diff = link[:link].gsub(/\n/, ' ').uncolor.length - colored_link.uncolor.gsub(/\n/, ' ').length
|
951
|
+
graf.gsub!(/(?<=\|)([^\|]*?)#{Regexp.escape(link[:link].gsub(/\n/, " "))}(.*?)(?=\|)/) do
|
952
|
+
before = Regexp.last_match(1)
|
953
|
+
after = Regexp.last_match(2)
|
954
|
+
surround = "#{before}#{after}"
|
955
|
+
puts "**#{surround}**"
|
956
|
+
diff += 2 if surround.uncolor.gsub(/#{CLIMarkdown::MDTableCleanup::PAD_CHAR}*/, '').strip.length.zero?
|
957
|
+
"#{before}#{colored_link}#{after}#{' ' * diff}"
|
945
958
|
end
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
end
|
959
|
+
else
|
960
|
+
graf.gsub!(/#{Regexp.escape(link[:link].gsub(/\n/, " "))}/, colored_link)
|
961
|
+
end
|
962
|
+
if MDLess.options[:links] == :paragraph
|
963
|
+
if links_added
|
964
|
+
graf += "\n#{color_reference_link(url, title, counter, image: image)}"
|
953
965
|
else
|
954
|
-
|
966
|
+
graf = "#{graf}\n\n#{color_reference_link(url, title, counter, image: image)}"
|
967
|
+
links_added = true
|
955
968
|
end
|
956
|
-
|
969
|
+
else
|
970
|
+
@@footer_links << color_reference_link(url, title, counter, image: image)
|
957
971
|
end
|
972
|
+
counter += 1
|
958
973
|
end
|
959
974
|
"\n#{graf}\n"
|
960
975
|
end
|
@@ -969,56 +984,56 @@ module Redcarpet
|
|
969
984
|
def fix_colors(input)
|
970
985
|
input.gsub(/<<pre(?<id>\d+)>>(?<content>.*?)<<post\k<id>>>/m) do
|
971
986
|
m = Regexp.last_match
|
972
|
-
pre = m.pre_match.gsub(/<<pre(?<id>\d+)>>.*?<<post\k<id>>>/m,
|
987
|
+
pre = m.pre_match.gsub(/<<pre(?<id>\d+)>>.*?<<post\k<id>>>/m, '')
|
973
988
|
last_color = pre.last_color_code
|
974
989
|
|
975
|
-
"#{fix_colors(m[
|
976
|
-
end.gsub(/<<(pre|post)\d+>>/,
|
990
|
+
"#{fix_colors(m['content'])}#{last_color}"
|
991
|
+
end.gsub(/<<(pre|post)\d+>>/, '')
|
977
992
|
end
|
978
993
|
|
979
994
|
def render_images(input)
|
980
995
|
input.gsub(%r{<<img>>(.*?)<</img>>}) do
|
981
996
|
link, title, alt_text = Regexp.last_match(1).split(/\|\|/)
|
982
997
|
|
983
|
-
if (exec_available(
|
984
|
-
if exec_available(
|
985
|
-
MDLess.log.info(
|
986
|
-
elsif exec_available(
|
987
|
-
MDLess.log.info(
|
998
|
+
if (exec_available('imgcat') || exec_available('chafa')) && MDLess.options[:local_images]
|
999
|
+
if exec_available('imgcat')
|
1000
|
+
MDLess.log.info('Using imgcat for image rendering')
|
1001
|
+
elsif exec_available('chafa')
|
1002
|
+
MDLess.log.info('Using chafa for image rendering')
|
988
1003
|
end
|
989
1004
|
img_path = link
|
990
1005
|
if img_path =~ /^http/ && MDLess.options[:remote_images]
|
991
|
-
if exec_available(
|
992
|
-
MDLess.log.info(
|
1006
|
+
if exec_available('imgcat')
|
1007
|
+
MDLess.log.info('Using imgcat for image rendering')
|
993
1008
|
begin
|
994
1009
|
res, s = Open3.capture2(%(curl -sS "#{img_path}" 2> /dev/null | imgcat))
|
995
1010
|
|
996
1011
|
if s.success?
|
997
|
-
pre = !alt_text.nil? ? " #{c(%i[d blue])}[#{alt_text.strip}]\n" :
|
998
|
-
post = !title.nil? ? "\n #{c(%i[b blue])}-- #{title} --" :
|
1012
|
+
pre = !alt_text.nil? ? " #{c(%i[d blue])}[#{alt_text.strip}]\n" : ''
|
1013
|
+
post = !title.nil? ? "\n #{c(%i[b blue])}-- #{title} --" : ''
|
999
1014
|
result = pre + res + post
|
1000
1015
|
end
|
1001
1016
|
rescue StandardError => e
|
1002
1017
|
MDLess.log.error(e)
|
1003
1018
|
end
|
1004
|
-
elsif exec_available(
|
1005
|
-
MDLess.log.info(
|
1006
|
-
term =
|
1007
|
-
term = ENV[
|
1008
|
-
term = ENV[
|
1009
|
-
FileUtils.rm_r
|
1010
|
-
Dir.mkdir(
|
1011
|
-
Dir.chdir(
|
1019
|
+
elsif exec_available('chafa')
|
1020
|
+
MDLess.log.info('Using chafa for image rendering')
|
1021
|
+
term = '-f sixels'
|
1022
|
+
term = ENV['TERMINAL_PROGRAM'] =~ /iterm/i ? '-f iterm' : term
|
1023
|
+
term = ENV['TERMINAL_PROGRAM'] =~ /kitty/i ? '-f kitty' : term
|
1024
|
+
FileUtils.rm_r '.mdless_tmp', force: true if File.directory?('.mdless_tmp')
|
1025
|
+
Dir.mkdir('.mdless_tmp')
|
1026
|
+
Dir.chdir('.mdless_tmp')
|
1012
1027
|
`curl -SsO #{img_path} 2> /dev/null`
|
1013
1028
|
tmp_img = File.basename(img_path)
|
1014
1029
|
img = `chafa #{term} "#{tmp_img}"`
|
1015
|
-
pre = alt_text ? " #{c(%i[d blue])}[#{alt_text.strip}]\n" :
|
1016
|
-
post = title ? "\n #{c(%i[b blue])}-- #{title} --" :
|
1030
|
+
pre = alt_text ? " #{c(%i[d blue])}[#{alt_text.strip}]\n" : ''
|
1031
|
+
post = title ? "\n #{c(%i[b blue])}-- #{title} --" : ''
|
1017
1032
|
result = pre + img + post
|
1018
|
-
Dir.chdir(
|
1019
|
-
FileUtils.rm_r
|
1033
|
+
Dir.chdir('..')
|
1034
|
+
FileUtils.rm_r '.mdless_tmp', force: true
|
1020
1035
|
else
|
1021
|
-
MDLess.log.warn(
|
1036
|
+
MDLess.log.warn('No viewer for remote images')
|
1022
1037
|
end
|
1023
1038
|
else
|
1024
1039
|
if img_path =~ %r{^[~/]}
|
@@ -1028,14 +1043,14 @@ module Redcarpet
|
|
1028
1043
|
img_path = File.join(base, img_path)
|
1029
1044
|
end
|
1030
1045
|
if File.exist?(img_path)
|
1031
|
-
pre = !alt_text.nil? ? " #{c(%i[d blue])}[#{alt_text.strip}]\n" :
|
1032
|
-
post = !title.nil? ? "\n #{c(%i[b blue])}-- #{title} --" :
|
1033
|
-
if exec_available(
|
1046
|
+
pre = !alt_text.nil? ? " #{c(%i[d blue])}[#{alt_text.strip}]\n" : ''
|
1047
|
+
post = !title.nil? ? "\n #{c(%i[b blue])}-- #{title} --" : ''
|
1048
|
+
if exec_available('imgcat')
|
1034
1049
|
img = `imgcat "#{img_path}"`
|
1035
|
-
elsif exec_available(
|
1036
|
-
term =
|
1037
|
-
term = ENV[
|
1038
|
-
term = ENV[
|
1050
|
+
elsif exec_available('chafa')
|
1051
|
+
term = '-f sixels'
|
1052
|
+
term = ENV['TERMINAL_PROGRAM'] =~ /iterm/i ? '-f iterm' : term
|
1053
|
+
term = ENV['TERMINAL_PROGRAM'] =~ /kitty/i ? '-f kitty' : term
|
1039
1054
|
img = `chafa #{term} "#{img_path}"`
|
1040
1055
|
end
|
1041
1056
|
result = pre + img + post
|
@@ -1062,36 +1077,36 @@ module Redcarpet
|
|
1062
1077
|
end
|
1063
1078
|
[
|
1064
1079
|
pre_element,
|
1065
|
-
color(
|
1080
|
+
color('math brackets'),
|
1066
1081
|
brackets[0],
|
1067
1082
|
xc,
|
1068
|
-
color(
|
1083
|
+
color('math equation'),
|
1069
1084
|
equat,
|
1070
|
-
color(
|
1085
|
+
color('math brackets'),
|
1071
1086
|
brackets[1],
|
1072
1087
|
xc,
|
1073
|
-
post_element
|
1088
|
+
post_element
|
1074
1089
|
].join
|
1075
1090
|
end
|
1076
1091
|
end
|
1077
1092
|
|
1078
1093
|
def highlight_tags(input)
|
1079
|
-
tag_color = color(
|
1080
|
-
value_color = color(
|
1094
|
+
tag_color = color('at_tags tag')
|
1095
|
+
value_color = color('at_tags value')
|
1081
1096
|
input.gsub(/(?<pre>\s|m)(?<tag>@[^ \]:;.?!,("'\n]+)(?:(?<lparen>\()(?<value>.*?)(?<rparen>\)))?/) do
|
1082
1097
|
m = Regexp.last_match
|
1083
1098
|
last_color = m.pre_match.last_color_code
|
1084
1099
|
[
|
1085
|
-
m[
|
1100
|
+
m['pre'],
|
1086
1101
|
tag_color,
|
1087
|
-
m[
|
1088
|
-
m[
|
1102
|
+
m['tag'],
|
1103
|
+
m['lparen'],
|
1089
1104
|
value_color,
|
1090
|
-
m[
|
1105
|
+
m['value'],
|
1091
1106
|
tag_color,
|
1092
|
-
m[
|
1107
|
+
m['rparen'],
|
1093
1108
|
xc,
|
1094
|
-
last_color
|
1109
|
+
last_color
|
1095
1110
|
].join
|
1096
1111
|
end
|
1097
1112
|
end
|
@@ -1101,14 +1116,14 @@ module Redcarpet
|
|
1101
1116
|
content = Regexp.last_match(1)
|
1102
1117
|
[
|
1103
1118
|
pre_element,
|
1104
|
-
color(
|
1105
|
-
|
1106
|
-
color(
|
1119
|
+
color('link brackets'),
|
1120
|
+
'[[',
|
1121
|
+
color('link text'),
|
1107
1122
|
content,
|
1108
|
-
color(
|
1109
|
-
|
1123
|
+
color('link brackets'),
|
1124
|
+
']]',
|
1110
1125
|
xc,
|
1111
|
-
post_element
|
1126
|
+
post_element
|
1112
1127
|
].join
|
1113
1128
|
end
|
1114
1129
|
end
|