mdless 2.0.7 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40b4de5e5f68bf91800f9f7448a8b3620c5f194b2966b786fe4621cd3ccc7ccc
4
- data.tar.gz: ee00c4e594a1c2b6d3526e6c5e1c6a0143c2ad9800577b31e8f73f558df99500
3
+ metadata.gz: 2a8bb0bc65cda56264422a8f0fc98ed7c8d75f67d6604791fe157d111223d358
4
+ data.tar.gz: 25fa19dec8c2c34bccaa00b3fccf542c13384e12498cda7f1b529f703a7b8399
5
5
  SHA512:
6
- metadata.gz: d4ba05b198c6ad16caeab6e0875fc3ef1b86181099e23a8cabf04063f73f4b6f22c2376d6f394c57165c76f7476c784e527918ea6213b978e413de8be4bb0943
7
- data.tar.gz: 76eb9fc848d10f82e557cfe880204252719c5d3aad9d5e6cee70c44c25a6d10ad1fce5493b025a97dc7fd1ddf127a10ff7fc2fd6b04e9bd400dd7f720467b9e4
6
+ metadata.gz: 65664be5ef8893f3f2c1e377633bdb69c3780e2a957c2f555e50add0e059242a966663bb0faaf609d6a9015d4ec49aba18c849bcdee58bc62e2ab7cd251505e2
7
+ data.tar.gz: 6b784620a50a0c182a49244640bf278e7ab19a6e3e840d8bc1c83eb308709f5fcb0979120157b8671101b0135cbec6a1bf52ec3cd42d765ae08aed8a940cab45
data/README.md CHANGED
@@ -94,6 +94,21 @@ Font and color settings are set using a string of color names and modifiers. A t
94
94
 
95
95
  Some extra (non-color) settings are available for certain keys, e.g. `pad_char` to define the right padding character used on level 1 and 2 headlines. Note that you can change the [Pygments](http://pygments.org/) theme used for syntax highlighting with the code_block.pygments_theme setting. For a list of available styles (assuming you have Pygments installed), use `pygmentize -L styles`.
96
96
 
97
+ The display of characters around emphasis and code spans can be configured. By default, the surrounding character for bold is `**`, italic is `_`, and code span is \`. You can leave these keys empty to not display characters at all. For triple-emphasized text, the text will be surrounded by italic and bold characters, in that order.
98
+
99
+ ```yaml
100
+ emphasis:
101
+ bold: b
102
+ bold_character: "**"
103
+ italic: u i
104
+ italic_character: ""
105
+ bold-italic: b u i
106
+ code_span:
107
+ marker: b white
108
+ color: b white on_intense_black
109
+ character: ""
110
+ ```
111
+
97
112
  *Note:* the ANSI escape codes are reset every time the color changes, so, for example, if you have a key that defines underlines for the url in a link, the underline will automatically be removed when it gets to a bracket. This also means that if you define a background color, you'll need to define it again on all the keys that it should affect.
98
113
 
99
114
  Base colors:
data/lib/mdless/colors.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  module CLIMarkdown
2
2
  module Colors
3
+ ESCAPE_REGEX = /(?<=\[)(?:(?:(?:[349]|10)[0-9]|[0-9])?;?)+(?=m)/.freeze
3
4
 
4
5
  COLORS = {
5
6
  :reset => 0, # synonym for :clear
@@ -57,6 +58,118 @@ module CLIMarkdown
57
58
  self.gsub(/\e\[[\d;]+m/,'')
58
59
  end
59
60
 
61
+ # Get the calculated ANSI color at the end of the
62
+ # string
63
+ #
64
+ # @return ANSI escape sequence to match color
65
+ #
66
+ def last_color_code
67
+ m = scan(ESCAPE_REGEX)
68
+
69
+ em = ['0']
70
+ fg = nil
71
+ bg = nil
72
+ rgbf = nil
73
+ rgbb = nil
74
+
75
+ m.each do |c|
76
+ case c
77
+ when '0'
78
+ em = ['0']
79
+ fg, bg, rgbf, rgbb = nil
80
+ when /^[34]8/
81
+ case c
82
+ when /^3/
83
+ fg = nil
84
+ rgbf = c
85
+ when /^4/
86
+ bg = nil
87
+ rgbb = c
88
+ end
89
+ else
90
+ c.split(/;/).each do |i|
91
+ x = i.to_i
92
+ if x <= 9
93
+ em << x
94
+ elsif x >= 30 && x <= 39
95
+ rgbf = nil
96
+ fg = x
97
+ elsif x >= 40 && x <= 49
98
+ rgbb = nil
99
+ bg = x
100
+ elsif x >= 90 && x <= 97
101
+ rgbf = nil
102
+ fg = x
103
+ elsif x >= 100 && x <= 107
104
+ rgbb = nil
105
+ bg = x
106
+ end
107
+ end
108
+ end
109
+ end
110
+
111
+ escape = "\e[#{em.join(';')}m"
112
+ escape += "\e[#{rgbb}m" if rgbb
113
+ escape += "\e[#{rgbf}m" if rgbf
114
+ escape + "\e[#{[fg, bg].delete_if(&:nil?).join(';')}m"
115
+ end
116
+
117
+ # Get the calculated ANSI color at the end of the
118
+ # string
119
+ #
120
+ # @return ANSI escape sequence to match color
121
+ #
122
+ def last_color_code
123
+ m = scan(ESCAPE_REGEX)
124
+
125
+ em = ['0']
126
+ fg = nil
127
+ bg = nil
128
+ rgbf = nil
129
+ rgbb = nil
130
+
131
+ m.each do |c|
132
+ case c
133
+ when '0'
134
+ em = ['0']
135
+ fg, bg, rgbf, rgbb = nil
136
+ when /^[34]8/
137
+ case c
138
+ when /^3/
139
+ fg = nil
140
+ rgbf = c
141
+ when /^4/
142
+ bg = nil
143
+ rgbb = c
144
+ end
145
+ else
146
+ c.split(/;/).each do |i|
147
+ x = i.to_i
148
+ if x <= 9
149
+ em << x
150
+ elsif x >= 30 && x <= 39
151
+ rgbf = nil
152
+ fg = x
153
+ elsif x >= 40 && x <= 49
154
+ rgbb = nil
155
+ bg = x
156
+ elsif x >= 90 && x <= 97
157
+ rgbf = nil
158
+ fg = x
159
+ elsif x >= 100 && x <= 107
160
+ rgbb = nil
161
+ bg = x
162
+ end
163
+ end
164
+ end
165
+ end
166
+
167
+ escape = "\e[#{em.join(';')}m"
168
+ escape += "\e[#{rgbb}m" if rgbb
169
+ escape += "\e[#{rgbf}m" if rgbf
170
+ escape + "\e[#{[fg, bg].delete_if(&:nil?).join(';')}m"
171
+ end
172
+
60
173
  def blackout(bgcolor)
61
174
  key = bgcolor.to_sym
62
175
  bg = COLORS.key?(key) ? COLORS[key] : 40
@@ -7,11 +7,21 @@ module Redcarpet
7
7
 
8
8
  @@listitemid = 0
9
9
  @@listid = 0
10
+ @@elementid = 0
10
11
  @@footnotes = []
11
12
  @@headers = []
12
13
  @@links = []
13
14
  @@footer_links = []
14
15
 
16
+ def pre_element
17
+ @@elementid += 1
18
+ "<<pre#{@@elementid}>>"
19
+ end
20
+
21
+ def post_element
22
+ "<<post#{@@elementid}>>"
23
+ end
24
+
15
25
  def xc
16
26
  x + color('text')
17
27
  end
@@ -268,42 +278,72 @@ module Redcarpet
268
278
 
269
279
  def autolink(link, _)
270
280
  [
281
+ pre_element,
271
282
  color('link brackets'),
272
283
  '<',
273
284
  color('link url'),
274
285
  link,
275
286
  color('link brackets'),
276
287
  '>',
277
- xc
288
+ xc,
289
+ post_element
278
290
  ].join('')
279
291
  end
280
292
 
281
293
  def codespan(code)
282
294
  [
295
+ pre_element,
283
296
  color('code_span marker'),
284
- '`',
297
+ @theme['code_span']['character'],
285
298
  color('code_span color'),
286
299
  code,
287
300
  color('code_span marker'),
288
- '`',
289
- xc
301
+ @theme['code_span']['character'],
302
+ xc,
303
+ post_element
290
304
  ].join('')
291
305
  end
292
306
 
293
307
  def double_emphasis(text)
294
- "#{color('emphasis bold')}#{text}#{xc}"
308
+ [
309
+ pre_element,
310
+ color('emphasis bold'),
311
+ @theme['emphasis']['bold_character'],
312
+ text,
313
+ @theme['emphasis']['bold_character'],
314
+ xc,
315
+ post_element
316
+ ].join
295
317
  end
296
318
 
297
319
  def emphasis(text)
298
- "#{color('emphasis italic')}#{text}#{xc}"
320
+ [
321
+ pre_element,
322
+ color('emphasis italic'),
323
+ @theme['emphasis']['italic_character'],
324
+ text,
325
+ @theme['emphasis']['italic_character'],
326
+ xc,
327
+ post_element
328
+ ].join
299
329
  end
300
330
 
301
331
  def triple_emphasis(text)
302
- "#{color('emphasis bold-italic')}#{text}#{xc}"
332
+ [
333
+ pre_element,
334
+ color('emphasis bold-italic'),
335
+ @theme['emphasis']['italic_character'],
336
+ @theme['emphasis']['bold_character'],
337
+ text,
338
+ @theme['emphasis']['bold_character'],
339
+ @theme['emphasis']['italic_character'],
340
+ xc,
341
+ post_element
342
+ ].join
303
343
  end
304
344
 
305
345
  def highlight(text)
306
- "#{color('highlight')}#{text}#{xc}"
346
+ "#{pre_element}#{color('highlight')}#{text}#{xc}#{post_element}"
307
347
  end
308
348
 
309
349
  def color_image_tag(link, title, alt_text)
@@ -321,78 +361,12 @@ module Redcarpet
321
361
  title.nil? ? '' : %( "#{title}"),
322
362
  color('image brackets'),
323
363
  ')',
324
- xc
364
+ xc,
325
365
  ].join
326
366
  end
327
367
 
328
368
  def image(link, title, alt_text)
329
- if (exec_available('imgcat') || exec_available('chafa')) && @options[:local_images]
330
- if exec_available('imgcat')
331
- @log.info('Using imgcat for image rendering')
332
- elsif exec_available('chafa')
333
- @log.info('Using chafa for image rendering')
334
- end
335
- img_path = link
336
- if img_path =~ /^http/ && @options[:remote_images]
337
- if exec_available('imgcat')
338
- @log.info('Using imgcat for image rendering')
339
- begin
340
- res, s = Open3.capture2(%(curl -sS "#{img_path}" 2> /dev/null | imgcat))
341
-
342
- if s.success?
343
- pre = !alt_text.nil? ? " #{c(%i[d blue])}[#{alt_text.strip}]\n" : ''
344
- post = !title.nil? ? "\n #{c(%i[b blue])}-- #{title} --" : ''
345
- result = pre + res + post
346
- end
347
- rescue StandardError => e
348
- @log.error(e)
349
- end
350
- elsif exec_available('chafa')
351
- @log.info('Using chafa for image rendering')
352
- term = '-f sixels'
353
- term = ENV['TERMINAL_PROGRAM'] =~ /iterm/i ? '-f iterm' : term
354
- term = ENV['TERMINAL_PROGRAM'] =~ /kitty/i ? '-f kitty' : term
355
- FileUtils.rm_r '.mdless_tmp', force: true if File.directory?('.mdless_tmp')
356
- Dir.mkdir('.mdless_tmp')
357
- Dir.chdir('.mdless_tmp')
358
- `curl -SsO #{img_path} 2> /dev/null`
359
- tmp_img = File.basename(img_path)
360
- img = `chafa #{term} "#{tmp_img}"`
361
- pre = alt_text ? " #{c(%i[d blue])}[#{alt_text.strip}]\n" : ''
362
- post = title ? "\n #{c(%i[b blue])}-- #{tail} --" : ''
363
- result = pre + img + post
364
- Dir.chdir('..')
365
- FileUtils.rm_r '.mdless_tmp', force: true
366
- else
367
- @log.warn('No viewer for remote images')
368
- end
369
- else
370
- if img_path =~ %r{^[~/]}
371
- img_path = File.expand_path(img_path)
372
- elsif @file
373
- base = File.expand_path(File.dirname(@file))
374
- img_path = File.join(base, img_path)
375
- end
376
- if File.exist?(img_path)
377
- pre = !alt_text.nil? ? " #{c(%i[d blue])}[#{alt_text.strip}]\n" : ''
378
- post = !title.nil? ? "\n #{c(%i[b blue])}-- #{title} --" : ''
379
- if exec_available('imgcat')
380
- img = `imgcat "#{img_path}"`
381
- elsif exec_available('chafa')
382
- term = '-f sixels'
383
- term = ENV['TERMINAL_PROGRAM'] =~ /iterm/i ? '-f iterm' : term
384
- term = ENV['TERMINAL_PROGRAM'] =~ /kitty/i ? '-f kitty' : term
385
- img = `chafa #{term} "#{img_path}"`
386
- end
387
- result = pre + img + post
388
- end
389
- end
390
- end
391
- if result.nil?
392
- color_image_tag(link, title, alt_text)
393
- else
394
- result + xc
395
- end
369
+ "<<img>>#{link}||#{title}||#{alt_text}<</img>>"
396
370
  end
397
371
 
398
372
  def linebreak
@@ -401,6 +375,7 @@ module Redcarpet
401
375
 
402
376
  def color_link(link, title, content)
403
377
  [
378
+ pre_element,
404
379
  color('link brackets'),
405
380
  '[',
406
381
  color('link text'),
@@ -412,12 +387,14 @@ module Redcarpet
412
387
  title.nil? ? '' : %( "#{title}"),
413
388
  color('link brackets'),
414
389
  ')',
415
- xc
390
+ xc,
391
+ post_element
416
392
  ].join
417
393
  end
418
394
 
419
395
  def color_link_reference(link, idx, content)
420
396
  [
397
+ pre_element,
421
398
  color('link brackets'),
422
399
  '[',
423
400
  color('link text'),
@@ -428,7 +405,8 @@ module Redcarpet
428
405
  idx,
429
406
  color('link brackets'),
430
407
  ']',
431
- xc
408
+ xc,
409
+ post_element
432
410
  ].join
433
411
  end
434
412
 
@@ -461,19 +439,19 @@ module Redcarpet
461
439
  end
462
440
 
463
441
  def color_tags(html)
464
- html.gsub(%r{(<\S+( .*?)?/?>)}, "#{color('html brackets')}\\1#{xc}")
442
+ html.gsub(%r{(<\S+( [^>]+)?>)}, "#{color('html brackets')}\\1#{xc}")
465
443
  end
466
444
 
467
445
  def raw_html(raw_html)
468
- "#{color('html color')}#{color_tags(raw_html)}#{xc}"
446
+ "#{pre_element}#{color('html color')}#{color_tags(raw_html)}#{xc}#{post_element}"
469
447
  end
470
448
 
471
449
  def strikethrough(text)
472
- "#{color('strikethrough')}#{text}#{xc}"
450
+ "#{pre_element}#{color('strikethrough')}#{text}#{xc}#{post_element}"
473
451
  end
474
452
 
475
453
  def superscript(text)
476
- "#{color('super')}^#{text}#{xc}"
454
+ "#{pre_element}#{color('super')}^#{text}#{xc}#{post_element}"
477
455
  end
478
456
 
479
457
  def footnotes(text)
@@ -511,9 +489,11 @@ module Redcarpet
511
489
 
512
490
  def footnote_ref(text)
513
491
  [
492
+ pre_element,
514
493
  color('footnote title'),
515
494
  "[^#{text}]",
516
- xc
495
+ xc,
496
+ post_element
517
497
  ].join('')
518
498
  end
519
499
 
@@ -572,7 +552,8 @@ module Redcarpet
572
552
 
573
553
  def preprocess(input)
574
554
  in_yaml = false
575
- if input.split("\n")[0] =~ /(?i-m)^---[ \t]*?(\n|$)/
555
+ first_line = input.split("\n").first
556
+ if first_line =~ /(?i-m)^---[ \t]*?$/
576
557
  @log.info('Found YAML')
577
558
  # YAML
578
559
  in_yaml = true
@@ -596,10 +577,12 @@ module Redcarpet
596
577
  end
597
578
  end
598
579
 
599
- if !in_yaml && input.gsub(/\n/, ' ') =~ /(?i-m)^[\w ]+:\s+\S+/
580
+ if !in_yaml && first_line =~ /(?i-m)^[\w ]+:\s+\S+/
600
581
  @log.info('Found MMD Headers')
601
582
  input.sub!(/(?i-m)^([\S ]+:[\s\S]*?)+(?=\n\n)/) do |mmd|
602
583
  lines = mmd.split(/\n/)
584
+ return mmd if lines.count > 20
585
+
603
586
  longest = lines.inject { |memo, word| memo.length > word.length ? memo : word }.length
604
587
  longest = longest < @cols ? longest + 1 : @cols
605
588
  lines.map do |line|
@@ -717,7 +700,117 @@ module Redcarpet
717
700
  end
718
701
  end
719
702
 
703
+ def fix_colors(input)
704
+ input.gsub(/<<pre(?<id>\d+)>>(?<content>.*?)<<post\k<id>>>/m) do
705
+ m = Regexp.last_match
706
+ pre = m.pre_match
707
+ last_color = pre.last_color_code
708
+ "#{fix_colors(m['content'])}#{last_color}"
709
+ end.gsub(/<<(pre|post)\d+>>/, '')
710
+ end
711
+
712
+ def render_images(input)
713
+ input.gsub(%r{<<img>>(.*?)<</img>>}) do
714
+ link, title, alt_text = Regexp.last_match(1).split(/\|\|/)
715
+
716
+ if (exec_available('imgcat') || exec_available('chafa')) && @options[:local_images]
717
+ if exec_available('imgcat')
718
+ @log.info('Using imgcat for image rendering')
719
+ elsif exec_available('chafa')
720
+ @log.info('Using chafa for image rendering')
721
+ end
722
+ img_path = link
723
+ if img_path =~ /^http/ && @options[:remote_images]
724
+ if exec_available('imgcat')
725
+ @log.info('Using imgcat for image rendering')
726
+ begin
727
+ res, s = Open3.capture2(%(curl -sS "#{img_path}" 2> /dev/null | imgcat))
728
+
729
+ if s.success?
730
+ pre = !alt_text.nil? ? " #{c(%i[d blue])}[#{alt_text.strip}]\n" : ''
731
+ post = !title.nil? ? "\n #{c(%i[b blue])}-- #{title} --" : ''
732
+ result = pre + res + post
733
+ end
734
+ rescue StandardError => e
735
+ @log.error(e)
736
+ end
737
+ elsif exec_available('chafa')
738
+ @log.info('Using chafa for image rendering')
739
+ term = '-f sixels'
740
+ term = ENV['TERMINAL_PROGRAM'] =~ /iterm/i ? '-f iterm' : term
741
+ term = ENV['TERMINAL_PROGRAM'] =~ /kitty/i ? '-f kitty' : term
742
+ FileUtils.rm_r '.mdless_tmp', force: true if File.directory?('.mdless_tmp')
743
+ Dir.mkdir('.mdless_tmp')
744
+ Dir.chdir('.mdless_tmp')
745
+ `curl -SsO #{img_path} 2> /dev/null`
746
+ tmp_img = File.basename(img_path)
747
+ img = `chafa #{term} "#{tmp_img}"`
748
+ pre = alt_text ? " #{c(%i[d blue])}[#{alt_text.strip}]\n" : ''
749
+ post = title ? "\n #{c(%i[b blue])}-- #{tail} --" : ''
750
+ result = pre + img + post
751
+ Dir.chdir('..')
752
+ FileUtils.rm_r '.mdless_tmp', force: true
753
+ else
754
+ @log.warn('No viewer for remote images')
755
+ end
756
+ else
757
+ if img_path =~ %r{^[~/]}
758
+ img_path = File.expand_path(img_path)
759
+ elsif @file
760
+ base = File.expand_path(File.dirname(@file))
761
+ img_path = File.join(base, img_path)
762
+ end
763
+ if File.exist?(img_path)
764
+ pre = !alt_text.nil? ? " #{c(%i[d blue])}[#{alt_text.strip}]\n" : ''
765
+ post = !title.nil? ? "\n #{c(%i[b blue])}-- #{title} --" : ''
766
+ if exec_available('imgcat')
767
+ img = `imgcat "#{img_path}"`
768
+ elsif exec_available('chafa')
769
+ term = '-f sixels'
770
+ term = ENV['TERMINAL_PROGRAM'] =~ /iterm/i ? '-f iterm' : term
771
+ term = ENV['TERMINAL_PROGRAM'] =~ /kitty/i ? '-f kitty' : term
772
+ img = `chafa #{term} "#{img_path}"`
773
+ end
774
+ result = pre + img + post
775
+ end
776
+ end
777
+ end
778
+ if result.nil?
779
+ color_image_tag(link, title, alt_text)
780
+ else
781
+ "#{pre_element}#{result}#{xc}#{post_element}"
782
+ end
783
+ end
784
+ end
785
+
786
+ def fix_equations(input)
787
+ input.gsub(/((\\\\\[|\$\$)(.*?)(\\\\\]|\$\$)|(\\\\\(|\$)(.*?)(\\\\\)|\$))/) do
788
+ m = Regexp.last_match
789
+ if m[2]
790
+ brackets = [m[2], m[4]]
791
+ equat = m[3]
792
+ else
793
+ brackets = [m[5], m[7]]
794
+ equat = m[6]
795
+ end
796
+ [
797
+ pre_element,
798
+ color('math brackets'),
799
+ brackets[0],
800
+ xc,
801
+ color('math equation'),
802
+ equat,
803
+ color('math brackets'),
804
+ brackets[1],
805
+ xc,
806
+ post_element
807
+ ].join
808
+ end
809
+ end
810
+
720
811
  def postprocess(input)
812
+ input.scrub!
813
+
721
814
  if @options[:inline_footnotes]
722
815
  input = insert_footnotes(input)
723
816
  else
@@ -731,25 +824,15 @@ module Redcarpet
731
824
  # escaped characters
732
825
  input.gsub!(/\\(\S)/, '\1')
733
826
  # equations
734
- input.gsub!(/((\\\\\[|\$\$)(.*?)(\\\\\]|\$\$)|(\\\\\(|\$)(.*?)(\\\\\)|\$))/) do
735
- m = Regexp.last_match
736
- if m[2]
737
- brackets = [m[2], m[4]]
738
- equat = m[3]
739
- else
740
- brackets = [m[5], m[7]]
741
- equat = m[6]
742
- end
743
- "#{c(%i[b black])}#{brackets[0]}#{xc}#{c(%i[b blue])}#{equat}#{c(%i[b black])}#{brackets[1]}" + xc
744
- end
827
+ input = fix_equations(input)
745
828
  # misc html
746
- input.gsub!(%r{<br */?>}, "\n")
829
+ input.gsub!(%r{<br */?>}, "#{pre_element}\n#{post_element}")
747
830
  # format links
748
- if @options[:links] == :reference || @options[:links] == :paragraph
749
- input = reference_links(input)
750
- end
831
+ input = reference_links(input) if @options[:links] == :reference || @options[:links] == :paragraph
751
832
  # lists
752
- fix_lists(input, 0)
833
+ input = fix_lists(input, 0)
834
+ input = render_images(input) if @options[:local_images]
835
+ fix_colors(input)
753
836
  end
754
837
  end
755
838
  end
@@ -14,7 +14,7 @@ module CLIMarkdown
14
14
 
15
15
  def initialize(args)
16
16
  @log = Logger.new($stderr)
17
- @log.level = Logger::ERROR
17
+ @log.level = Logger::WARN
18
18
 
19
19
  @options = {}
20
20
  config = File.expand_path('~/.config/mdless/config.yml')
@@ -47,11 +47,15 @@ module CLIMarkdown
47
47
  opts.on('-i', '--images=TYPE',
48
48
  'Include [local|remote (both)] images in output (requires chafa or imgcat, default NONE).') do |type|
49
49
  if exec_available('imgcat') || exec_available('chafa')
50
- if type =~ /^(r|b|a)/i
50
+ case type
51
+ when /^(r|b|a)/i
51
52
  @options[:local_images] = true
52
53
  @options[:remote_images] = true
53
- elsif type =~ /^l/i
54
+ when /^l/i
54
55
  @options[:local_images] = true
56
+ when /^n/
57
+ @options[:local_images] = false
58
+ @options[:remote_images] = false
55
59
  end
56
60
  else
57
61
  @log.warn('images turned on but imgcat/chafa not found')
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # String helpers
4
+ class ::String
5
+ def scrub
6
+ encode('utf-16', invalid: :replace).encode('utf-8')
7
+ end
8
+
9
+ def scrub!
10
+ replace scrub
11
+ end
12
+ end
data/lib/mdless/theme.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  module CLIMarkdown
2
2
  module Theme
3
-
4
3
  THEME_DEFAULTS = {
5
4
  'metadata' => {
6
5
  'border' => 'd blue on_black',
@@ -9,9 +8,12 @@ module CLIMarkdown
9
8
  },
10
9
  'emphasis' => {
11
10
  'bold' => 'b',
11
+ 'bold_character' => '**',
12
12
  'italic' => 'u i',
13
+ 'italic_character' => '_',
13
14
  'bold-italic' => 'b u i'
14
15
  },
16
+ 'highlight' => 'b black on_yellow',
15
17
  'h1' => {
16
18
  'color' => 'b intense_black on_white',
17
19
  'pad' => 'd black on_white',
@@ -58,7 +60,8 @@ module CLIMarkdown
58
60
  },
59
61
  'code_span' => {
60
62
  'marker' => 'b white',
61
- 'color' => 'b white on_intense_black'
63
+ 'color' => 'b white on_intense_black',
64
+ 'character' => '`'
62
65
  },
63
66
  'code_block' => {
64
67
  'marker' => 'intense_black',
@@ -69,6 +72,13 @@ module CLIMarkdown
69
72
  'eol' => 'intense_black on_black',
70
73
  'pygments_theme' => 'monokai'
71
74
  },
75
+ 'blockquote' => {
76
+ 'marker' => {
77
+ 'character' => '>',
78
+ 'color' => 'yellow'
79
+ },
80
+ 'color' => 'b white'
81
+ },
72
82
  'dd' => {
73
83
  'term' => 'black on_white',
74
84
  'marker' => 'd red',
@@ -88,6 +98,10 @@ module CLIMarkdown
88
98
  'brackets' => 'd yellow on_black',
89
99
  'color' => 'yellow on_black'
90
100
  },
101
+ 'math' => {
102
+ 'brackets' => 'b black',
103
+ 'equation' => 'b blue'
104
+ },
91
105
  'super' => 'b green',
92
106
  'text' => 'white'
93
107
  }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CLIMarkdown
2
- VERSION = '2.0.7'
4
+ VERSION = '2.0.9'
3
5
  end
data/lib/mdless.rb CHANGED
@@ -8,6 +8,7 @@ require 'mdless/version.rb'
8
8
  require 'mdless/colors'
9
9
  require 'mdless/tables'
10
10
  require 'mdless/hash'
11
+ require 'mdless/string'
11
12
  require 'mdless/theme'
12
13
  require 'redcarpet'
13
14
  require 'mdless/console'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdless
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.7
4
+ version: 2.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-23 00:00:00.000000000 Z
11
+ date: 2023-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet
@@ -82,6 +82,7 @@ files:
82
82
  - lib/mdless/console.rb
83
83
  - lib/mdless/converter.rb
84
84
  - lib/mdless/hash.rb
85
+ - lib/mdless/string.rb
85
86
  - lib/mdless/tables.rb
86
87
  - lib/mdless/theme.rb
87
88
  - lib/mdless/version.rb
@@ -112,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
113
  - !ruby/object:Gem::Version
113
114
  version: '0'
114
115
  requirements: []
115
- rubygems_version: 3.2.16
116
+ rubygems_version: 3.2.15
116
117
  signing_key:
117
118
  specification_version: 4
118
119
  summary: A pager like less, but for Markdown files