mdless 1.0.15 → 1.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 721c2ba19c8a2e2fe201254c4d988855d208d8c9e339a435897d5ed08696cc33
4
- data.tar.gz: 0ffd801640a457d78ad076b05ddf44b2e735d8ca57928b94916db5c48f718663
3
+ metadata.gz: 388ed46c03bdf676e441d063ac9efd9e1491c87d40048dc5346014d9aa1cf7a5
4
+ data.tar.gz: 06c1958a97494c2b77b4f22c704c096ec06499e04ffb2fddae1c28c8311d3920
5
5
  SHA512:
6
- metadata.gz: '0380d39b79517ec7f1c278728b598c7780e5ccec1b1dd0fda74fd063430e20e18551a4d08bf6cc0d9091c68bb4ace60dac62ab5c78804dc10cca62cce81ab1b4'
7
- data.tar.gz: 19e1df9c6bb6a7cf4289463f52e74bdad480b5d41a8f387145ca99b935068149d8cc53a8815f0fa1c0cffeee2ef280bfbe5a3c72062b5568ff375a71901d53ce
6
+ metadata.gz: eb1035bbd071a64f84386f4c3ce6ce9b17219ba9408c705a80abb931ffb9e4255e40275414f6b9a409d13aa071871c4f6b687ce1c7d56ba8e7a601fec9b92dd7
7
+ data.tar.gz: c343ec9cb5715d938736bc343858669175d1c3e1c4685534a83ec1c9fdad869d59cb45da0d2b81aba7980f0d18c39a20c0e69c89f44d31fc041d1e1b4246ecd7
data/README.md CHANGED
@@ -27,6 +27,14 @@ I often use iTerm2 in visor mode, so `qlmanage -p` is annoying. I still wanted a
27
27
 
28
28
  gem install mdless
29
29
 
30
+ ### Dependencies
31
+
32
+ Some OSs are missing `tput`, which is necessary for mdless.
33
+
34
+ apt update
35
+ apt install ruby ncurses-utils
36
+ gem install mdless
37
+
30
38
  ## Usage
31
39
 
32
40
  `mdless [options] path` or `cat [path] | mdless`
@@ -1,5 +1,6 @@
1
1
  require 'fileutils'
2
2
  require 'yaml'
3
+ require 'fileutils'
3
4
 
4
5
  module CLIMarkdown
5
6
  class Converter
@@ -41,9 +42,9 @@ module CLIMarkdown
41
42
 
42
43
  @options[:local_images] = false
43
44
  @options[:remote_images] = false
44
- opts.on('-i', '--images=TYPE', 'Include [local|remote (both)] images in output (requires imgcat and iTerm2, default NONE). Does not work with pagers, use with -P' ) do |type|
45
- unless exec_available('imgcat')# && ENV['TERM_PROGRAM'] == 'iTerm.app'
46
- @log.warn('images turned on but imgcat not found')
45
+ opts.on('-i', '--images=TYPE', 'Include [local|remote (both)] images in output (requires chafa or imgcat, default NONE). imgcat does not work with pagers, use with -P' ) do |type|
46
+ unless exec_available('imgcat') || exec_available('chafa')# && ENV['TERM_PROGRAM'] == 'iTerm.app'
47
+ @log.warn('images turned on but imgcat/chafa not found')
47
48
  else
48
49
  if type =~ /^(r|b|a)/i
49
50
  @options[:local_images] = true
@@ -53,12 +54,12 @@ module CLIMarkdown
53
54
  end
54
55
  end
55
56
  end
56
- opts.on('-I', '--all-images', 'Include local and remote images in output (requires imgcat and iTerm2)' ) do
57
- unless exec_available('imgcat')# && ENV['TERM_PROGRAM'] == 'iTerm.app'
58
- @log.warn('images turned on but imgcat not found')
59
- else
57
+ opts.on('-I', '--all-images', 'Include local and remote images in output (requires imgcat or chafa)' ) do
58
+ if exec_available('imgcat') || exec_available('chafa')# && ENV['TERM_PROGRAM'] == 'iTerm.app'
60
59
  @options[:local_images] = true
61
60
  @options[:remote_images] = true
61
+ else
62
+ @log.warn('images turned on but imgcat/chafa not found')
62
63
  end
63
64
  end
64
65
 
@@ -104,7 +105,12 @@ module CLIMarkdown
104
105
  end
105
106
  end
106
107
 
107
- optparse.parse!
108
+ begin
109
+ optparse.parse!
110
+ rescue OptionParser::ParseError => pe
111
+ $stderr.puts "error: #{pe.message}"
112
+ exit 1
113
+ end
108
114
 
109
115
  @theme = load_theme(@options[:theme])
110
116
  @cols = @options[:width]
@@ -339,6 +345,8 @@ module CLIMarkdown
339
345
 
340
346
  def clean_markers(input)
341
347
  input.gsub!(/^(\e\[[\d;]+m)?[%~] ?/,'\1')
348
+ input.gsub!(/^(\e\[[\d;]+m)*>(\e\[[\d;]+m)?( +)/,' \3\1\2')
349
+ input.gsub!(/^(\e\[[\d;]+m)*>(\e\[[\d;]+m)?/,'\1\2')
342
350
  input.gsub!(/(\e\[[\d;]+m)?@@@(\e\[[\d;]+m)?$/,'')
343
351
  input
344
352
  end
@@ -431,8 +439,8 @@ module CLIMarkdown
431
439
  new_code_line = l.gsub(/\t/, ' ')
432
440
  new_code_line.sub!(/^#{" "*first_indent}/,'')
433
441
  [
434
- color('code_block marker'),
435
442
  "> ",
443
+ color('code_block marker'),
436
444
  " "*first_indent,
437
445
  "#{color('code_block bg')}#{l}"
438
446
  ].join
@@ -448,8 +456,8 @@ module CLIMarkdown
448
456
  new_code_line.sub!(/^#{" "*first_indent}/,'')
449
457
  new_code_line.gsub!(/ /, "#{color('code_block color')} ")
450
458
  [
451
- color('code_block marker'),
452
459
  "> ",
460
+ color('code_block marker'),
453
461
  " "*first_indent,
454
462
  color('code_block color'),
455
463
  new_code_line,
@@ -847,20 +855,41 @@ module CLIMarkdown
847
855
  else
848
856
  tail = match[4].nil? ? '' : " "+match[4].strip
849
857
  result = nil
850
- if exec_available('imgcat') && @options[:local_images]
858
+ if (exec_available('imgcat') || exec_available('chafa')) && @options[:local_images]
851
859
  if match[3]
852
860
  img_path = match[3]
853
861
  if img_path =~ /^http/ && @options[:remote_images]
854
- begin
855
- res, s = Open3.capture2(%Q{curl -sS "#{img_path}" 2> /dev/null | imgcat})
856
862
 
857
- if s.success?
858
- pre = match[2].size > 0 ? " #{c(%i[d blue])}[#{match[2].strip}]\n" : ''
859
- post = tail.size > 0 ? "\n #{c(%i[b blue])}-- #{tail} --" : ''
860
- result = pre + res + post
863
+ if exec_available('chafa')
864
+ if File.directory?('.mdless_tmp')
865
+ FileUtils.rm_r '.mdless_tmp', force: true
866
+ end
867
+ Dir.mkdir('.mdless_tmp')
868
+ Dir.chdir('.mdless_tmp')
869
+ `curl -SsO #{img_path} 2> /dev/null`
870
+ tmp_img = File.basename(img_path)
871
+ img = `chafa "#{tmp_img}"`
872
+ pre = match[2].size > 0 ? " #{c(%i[d blue])}[#{match[2].strip}]\n" : ''
873
+ post = tail.size > 0 ? "\n #{c(%i[b blue])}-- #{tail} --" : ''
874
+ result = pre + img + post
875
+ Dir.chdir('..')
876
+ FileUtils.rm_r '.mdless_tmp', force: true
877
+ else
878
+ if exec_available('imgcat')
879
+ begin
880
+ res, s = Open3.capture2(%Q{curl -sS "#{img_path}" 2> /dev/null | imgcat})
881
+
882
+ if s.success?
883
+ pre = match[2].size > 0 ? " #{c(%i[d blue])}[#{match[2].strip}]\n" : ''
884
+ post = tail.size > 0 ? "\n #{c(%i[b blue])}-- #{tail} --" : ''
885
+ result = pre + res + post
886
+ end
887
+ rescue => e
888
+ @log.error(e)
889
+ end
890
+ else
891
+ @log.warn("No viewer for remote images")
861
892
  end
862
- rescue => e
863
- @log.error(e)
864
893
  end
865
894
  else
866
895
  if img_path =~ /^[~\/]/
@@ -872,7 +901,11 @@ module CLIMarkdown
872
901
  if File.exists?(img_path)
873
902
  pre = match[2].size > 0 ? " #{c(%i[d blue])}[#{match[2].strip}]\n" : ''
874
903
  post = tail.size > 0 ? "\n #{c(%i[b blue])}-- #{tail} --" : ''
875
- img = %x{imgcat "#{img_path}"}
904
+ if exec_available('chafa')
905
+ img = %x{chafa "#{img_path}"}
906
+ elsif exec_available('imgcat')
907
+ img = %x{imgcat "#{img_path}"}
908
+ end
876
909
  result = pre + img + post
877
910
  end
878
911
  end
@@ -963,16 +996,16 @@ module CLIMarkdown
963
996
 
964
997
  out = cleanup_tables(out)
965
998
  out = clean_markers(out)
966
- out = out.gsub(/\n+{2,}/m,"\n\n") + "\n#{xc}\n"
999
+ out = out.gsub(/\n{2,}/m,"\n\n") + "#{xc}"
967
1000
 
968
1001
  unless @options[:color]
969
1002
  out.uncolor!
970
1003
  end
971
1004
 
972
1005
  if @options[:pager]
973
- page("\n\n" + out)
1006
+ page(out)
974
1007
  else
975
- $stdout.puts ("\n\n" + out)
1008
+ $stdout.puts (out)
976
1009
  end
977
1010
  end
978
1011
 
@@ -990,6 +1023,9 @@ module CLIMarkdown
990
1023
  if f
991
1024
  if f.strip =~ /[ |]/
992
1025
  f
1026
+ elsif f == 'most'
1027
+ @log.warn('most not allowed as pager')
1028
+ false
993
1029
  else
994
1030
  system "which #{f}", :out => File::NULL, :err => File::NULL
995
1031
  end
@@ -1,3 +1,3 @@
1
1
  module CLIMarkdown
2
- VERSION = '1.0.15'
2
+ VERSION = '1.0.20'
3
3
  end
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: 1.0.15
4
+ version: 1.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-19 00:00:00.000000000 Z
11
+ date: 2021-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubygems_version: 3.1.4
106
+ rubygems_version: 3.0.3
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: A pager like less, but for Markdown files