mdless 1.0.10 → 1.0.16

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: b304cbb274cf4909d011239377a99fbecad0ef8cff1eef0eae9bc18407531cfc
4
- data.tar.gz: a51aa9a7f785dbfd33d3a8f635d8a2f58bd79ac95506ad49fc21b59822dd9da6
3
+ metadata.gz: 32198570a885b3c03e6ec0e35c7d19f70f89330b9f3174270835a06f0efaec51
4
+ data.tar.gz: add6fadf749c0415363c6853c10f7de58a1a41a658ad1b12f1c4a692db425cb1
5
5
  SHA512:
6
- metadata.gz: b245917f11ecf8806dc34240e5b039cb5685b68ee0b9d0c52cede089b5567bee0ebb9f68960bd59e7c54093951712577f845b03a13f75c076c6e64d41ee0e0dd
7
- data.tar.gz: 8a267746ee40a94809750a1717076126e858b8d146bcb9ee11d4234270726fd580bc82617fba70889d7c65e2f1049eff55db249d947cc759fa494bef6058d5cd
6
+ metadata.gz: ab05974fb41187a1ba7b4fc95358ec65299a6c3496372bb7067e793bba209b66ec3a21daf0a78e133d63b26f6e93ee913420c968f3e746dcd147e4ea808f2a70
7
+ data.tar.gz: 2e1954c54a87c356b2a42bb847ea6c738df729da0bce1feefc13e9fb6c22b1a858bc53bedb63375e90e44e7d15e2d44de8770db7d92e19ae9d1630e4d782d2f2
@@ -41,9 +41,9 @@ module CLIMarkdown
41
41
 
42
42
  @options[:local_images] = false
43
43
  @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')
44
+ 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|
45
+ unless exec_available('imgcat') || exec_available('chafa')# && ENV['TERM_PROGRAM'] == 'iTerm.app'
46
+ @log.warn('images turned on but imgcat/chafa not found')
47
47
  else
48
48
  if type =~ /^(r|b|a)/i
49
49
  @options[:local_images] = true
@@ -53,12 +53,12 @@ module CLIMarkdown
53
53
  end
54
54
  end
55
55
  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
56
+ opts.on('-I', '--all-images', 'Include local and remote images in output (requires imgcat or chafa)' ) do
57
+ if exec_available('imgcat') || exec_available('chafa')# && ENV['TERM_PROGRAM'] == 'iTerm.app'
60
58
  @options[:local_images] = true
61
59
  @options[:remote_images] = true
60
+ else
61
+ @log.warn('images turned on but imgcat/chafa not found')
62
62
  end
63
63
  end
64
64
 
@@ -154,6 +154,7 @@ module CLIMarkdown
154
154
  $stderr.puts "No input"
155
155
  Process.exit 1
156
156
  end
157
+
157
158
  end
158
159
 
159
160
  def color(key)
@@ -286,6 +287,7 @@ module CLIMarkdown
286
287
  end
287
288
 
288
289
  def cleanup_tables(input)
290
+
289
291
  in_table = false
290
292
  header_row = false
291
293
  all_content = []
@@ -312,6 +314,7 @@ module CLIMarkdown
312
314
  end
313
315
 
314
316
  table = this_table.join("\n").strip
317
+
315
318
  begin
316
319
  formatted = MDTableCleanup.new(table)
317
320
  res = formatted.to_md
@@ -336,6 +339,7 @@ module CLIMarkdown
336
339
 
337
340
  def clean_markers(input)
338
341
  input.gsub!(/^(\e\[[\d;]+m)?[%~] ?/,'\1')
342
+ input.gsub!(/(\e\[[\d;]+m)?@@@(\e\[[\d;]+m)?$/,'')
339
343
  input
340
344
  end
341
345
 
@@ -451,7 +455,7 @@ module CLIMarkdown
451
455
  new_code_line,
452
456
  xc
453
457
  ].join
454
- end.join("\n") + "\n"
458
+ end.join("\n")
455
459
  end
456
460
 
457
461
  [
@@ -478,6 +482,7 @@ module CLIMarkdown
478
482
 
479
483
  def convert_markdown(input)
480
484
  @headers = get_headers(input)
485
+ input += "\n\n@@@"
481
486
  # yaml/MMD headers
482
487
  in_yaml = false
483
488
  if input.split("\n")[0] =~ /(?i-m)^---[ \t]*?(\n|$)/
@@ -842,20 +847,36 @@ module CLIMarkdown
842
847
  else
843
848
  tail = match[4].nil? ? '' : " "+match[4].strip
844
849
  result = nil
845
- if exec_available('imgcat') && @options[:local_images]
850
+ if (exec_available('imgcat') || exec_available('chafa')) && @options[:local_images]
846
851
  if match[3]
847
852
  img_path = match[3]
848
853
  if img_path =~ /^http/ && @options[:remote_images]
849
- begin
850
- res, s = Open3.capture2(%Q{curl -sS "#{img_path}" 2> /dev/null | imgcat})
851
854
 
852
- if s.success?
855
+ if exec_available('chafa')
856
+ Dir.mktmpdir do |dir|
857
+ `curl -Sso #{img_path} 2> /dev/null`
858
+ tmp_img = File.join(dir, File.basename(img_path))
859
+ img = `chafa "#{tmp_img}"`
853
860
  pre = match[2].size > 0 ? " #{c(%i[d blue])}[#{match[2].strip}]\n" : ''
854
861
  post = tail.size > 0 ? "\n #{c(%i[b blue])}-- #{tail} --" : ''
855
- result = pre + res + post
862
+ result = pre + img + post
863
+ end
864
+ else
865
+ if exec_available('imgcat')
866
+ begin
867
+ res, s = Open3.capture2(%Q{curl -sS "#{img_path}" 2> /dev/null | imgcat})
868
+
869
+ if s.success?
870
+ pre = match[2].size > 0 ? " #{c(%i[d blue])}[#{match[2].strip}]\n" : ''
871
+ post = tail.size > 0 ? "\n #{c(%i[b blue])}-- #{tail} --" : ''
872
+ result = pre + res + post
873
+ end
874
+ rescue => e
875
+ @log.error(e)
876
+ end
877
+ else
878
+ @log.warn("No viewer for remote images")
856
879
  end
857
- rescue => e
858
- @log.error(e)
859
880
  end
860
881
  else
861
882
  if img_path =~ /^[~\/]/
@@ -867,7 +888,11 @@ module CLIMarkdown
867
888
  if File.exists?(img_path)
868
889
  pre = match[2].size > 0 ? " #{c(%i[d blue])}[#{match[2].strip}]\n" : ''
869
890
  post = tail.size > 0 ? "\n #{c(%i[b blue])}-- #{tail} --" : ''
870
- img = %x{imgcat "#{img_path}"}
891
+ if exec_available('chafa')
892
+ img = %x{chafa "#{img_path}"}
893
+ elsif exec_available('imgcat')
894
+ img = %x{imgcat "#{img_path}"}
895
+ end
871
896
  result = pre + img + post
872
897
  end
873
898
  end
@@ -906,7 +931,7 @@ module CLIMarkdown
906
931
  if File.exists?(File.expand_path(cli))
907
932
  File.executable?(File.expand_path(cli))
908
933
  else
909
- system "which #{cli}", :out => File::NULL
934
+ system "which #{cli}", :out => File::NULL, :err => File::NULL
910
935
  end
911
936
  end
912
937
 
@@ -958,29 +983,38 @@ module CLIMarkdown
958
983
 
959
984
  out = cleanup_tables(out)
960
985
  out = clean_markers(out)
961
- out = out.gsub(/\n+{2,}/m,"\n\n") + "\n#{xc}\n"
986
+ out = out.gsub(/\n{2,}/m,"\n\n") + "#{xc}"
962
987
 
963
988
  unless @options[:color]
964
989
  out.uncolor!
965
990
  end
966
991
 
967
992
  if @options[:pager]
968
- page("\n\n" + out)
993
+ page(out)
969
994
  else
970
- $stdout.puts ("\n\n" + out)
995
+ $stdout.puts (out)
971
996
  end
972
997
  end
973
998
 
974
999
  def which_pager
975
- pagers = [ENV['GIT_PAGER'], ENV['PAGER'],
976
- `git config --get-all core.pager || true`.split.first,
977
- 'bat', 'less', 'more', 'cat', 'pager']
1000
+ pagers = [ENV['GIT_PAGER'], ENV['PAGER']]
1001
+
1002
+ if exec_available('git')
1003
+ git_pager = `git config --get-all core.pager || true`.split.first
1004
+ git_pager && pagers.push(git_pager)
1005
+ end
1006
+
1007
+ pagers.concat(['bat', 'less', 'more', 'cat', 'pager'])
1008
+
978
1009
  pagers.select! do |f|
979
1010
  if f
980
1011
  if f.strip =~ /[ |]/
981
1012
  f
1013
+ elsif f == 'most'
1014
+ @log.warn('most not allowed as pager')
1015
+ false
982
1016
  else
983
- system "which #{f}", :out => File::NULL
1017
+ system "which #{f}", :out => File::NULL, :err => File::NULL
984
1018
  end
985
1019
  else
986
1020
  false
data/lib/mdless/theme.rb CHANGED
@@ -80,7 +80,8 @@ module CLIMarkdown
80
80
  'border' => 'd black',
81
81
  'header' => 'yellow',
82
82
  'divider' => 'b black',
83
- 'color' => 'white'
83
+ 'color' => 'white',
84
+ 'bg' => 'on_black'
84
85
  },
85
86
  'html' => {
86
87
  'brackets' => 'd yellow on_black',
@@ -1,3 +1,3 @@
1
1
  module CLIMarkdown
2
- VERSION = '1.0.10'
2
+ VERSION = '1.0.16'
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.10
4
+ version: 1.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-15 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
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '13'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '13'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rdoc
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +80,7 @@ homepage: http://brettterpstra.com/project/mdless/
80
80
  licenses:
81
81
  - MIT
82
82
  metadata: {}
83
- post_install_message:
83
+ post_install_message:
84
84
  rdoc_options:
85
85
  - "--title"
86
86
  - mdless
@@ -103,8 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubygems_version: 3.0.6
107
- signing_key:
106
+ rubygems_version: 3.0.3
107
+ signing_key:
108
108
  specification_version: 4
109
109
  summary: A pager like less, but for Markdown files
110
110
  test_files: []