mdless 1.0.13 → 1.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mdless/converter.rb +64 -27
- data/lib/mdless/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8eea141a5dcf95ed15732749c7b5e975fb2e01de98b93e16dd2a4f88250f39a5
|
4
|
+
data.tar.gz: 5bc66169d0147198434cb21d8091366603412dec1745244a6b37aef483d4e909
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d36b471c343893525122228f2072342aba9ea6f880fb1edc4519ec612b878389adccfbf2a3ead4f6c11fa76afcc96f2af302f439ebfea23a5cde96d3f9ef132
|
7
|
+
data.tar.gz: a82c7b271295210979a0b205303af2e8a001872cff8767f52347e572180b1314c32b709628a03d1f5ac616bf169712b5c2bc54d0da3cca889893e9aff3f8e993
|
data/lib/mdless/converter.rb
CHANGED
@@ -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
|
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
|
57
|
-
|
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
|
|
@@ -339,6 +340,8 @@ module CLIMarkdown
|
|
339
340
|
|
340
341
|
def clean_markers(input)
|
341
342
|
input.gsub!(/^(\e\[[\d;]+m)?[%~] ?/,'\1')
|
343
|
+
input.gsub!(/^(\e\[[\d;]+m)*>(\e\[[\d;]+m)?( +)/,' \3\1\2')
|
344
|
+
input.gsub!(/^(\e\[[\d;]+m)*>(\e\[[\d;]+m)?/,'\1\2')
|
342
345
|
input.gsub!(/(\e\[[\d;]+m)?@@@(\e\[[\d;]+m)?$/,'')
|
343
346
|
input
|
344
347
|
end
|
@@ -431,8 +434,8 @@ module CLIMarkdown
|
|
431
434
|
new_code_line = l.gsub(/\t/, ' ')
|
432
435
|
new_code_line.sub!(/^#{" "*first_indent}/,'')
|
433
436
|
[
|
434
|
-
color('code_block marker'),
|
435
437
|
"> ",
|
438
|
+
color('code_block marker'),
|
436
439
|
" "*first_indent,
|
437
440
|
"#{color('code_block bg')}#{l}"
|
438
441
|
].join
|
@@ -448,8 +451,8 @@ module CLIMarkdown
|
|
448
451
|
new_code_line.sub!(/^#{" "*first_indent}/,'')
|
449
452
|
new_code_line.gsub!(/ /, "#{color('code_block color')} ")
|
450
453
|
[
|
451
|
-
color('code_block marker'),
|
452
454
|
"> ",
|
455
|
+
color('code_block marker'),
|
453
456
|
" "*first_indent,
|
454
457
|
color('code_block color'),
|
455
458
|
new_code_line,
|
@@ -847,20 +850,41 @@ module CLIMarkdown
|
|
847
850
|
else
|
848
851
|
tail = match[4].nil? ? '' : " "+match[4].strip
|
849
852
|
result = nil
|
850
|
-
if exec_available('imgcat') && @options[:local_images]
|
853
|
+
if (exec_available('imgcat') || exec_available('chafa')) && @options[:local_images]
|
851
854
|
if match[3]
|
852
855
|
img_path = match[3]
|
853
856
|
if img_path =~ /^http/ && @options[:remote_images]
|
854
|
-
begin
|
855
|
-
res, s = Open3.capture2(%Q{curl -sS "#{img_path}" 2> /dev/null | imgcat})
|
856
857
|
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
858
|
+
if exec_available('chafa')
|
859
|
+
if File.directory?('.mdless_tmp')
|
860
|
+
FileUtils.rm_r '.mdless_tmp', force: true
|
861
|
+
end
|
862
|
+
Dir.mkdir('.mdless_tmp')
|
863
|
+
Dir.chdir('.mdless_tmp')
|
864
|
+
`curl -SsO #{img_path} 2> /dev/null`
|
865
|
+
tmp_img = File.basename(img_path)
|
866
|
+
img = `chafa "#{tmp_img}"`
|
867
|
+
pre = match[2].size > 0 ? " #{c(%i[d blue])}[#{match[2].strip}]\n" : ''
|
868
|
+
post = tail.size > 0 ? "\n #{c(%i[b blue])}-- #{tail} --" : ''
|
869
|
+
result = pre + img + post
|
870
|
+
Dir.chdir('..')
|
871
|
+
FileUtils.rm_r '.mdless_tmp', force: true
|
872
|
+
else
|
873
|
+
if exec_available('imgcat')
|
874
|
+
begin
|
875
|
+
res, s = Open3.capture2(%Q{curl -sS "#{img_path}" 2> /dev/null | imgcat})
|
876
|
+
|
877
|
+
if s.success?
|
878
|
+
pre = match[2].size > 0 ? " #{c(%i[d blue])}[#{match[2].strip}]\n" : ''
|
879
|
+
post = tail.size > 0 ? "\n #{c(%i[b blue])}-- #{tail} --" : ''
|
880
|
+
result = pre + res + post
|
881
|
+
end
|
882
|
+
rescue => e
|
883
|
+
@log.error(e)
|
884
|
+
end
|
885
|
+
else
|
886
|
+
@log.warn("No viewer for remote images")
|
861
887
|
end
|
862
|
-
rescue => e
|
863
|
-
@log.error(e)
|
864
888
|
end
|
865
889
|
else
|
866
890
|
if img_path =~ /^[~\/]/
|
@@ -872,7 +896,11 @@ module CLIMarkdown
|
|
872
896
|
if File.exists?(img_path)
|
873
897
|
pre = match[2].size > 0 ? " #{c(%i[d blue])}[#{match[2].strip}]\n" : ''
|
874
898
|
post = tail.size > 0 ? "\n #{c(%i[b blue])}-- #{tail} --" : ''
|
875
|
-
|
899
|
+
if exec_available('chafa')
|
900
|
+
img = %x{chafa "#{img_path}"}
|
901
|
+
elsif exec_available('imgcat')
|
902
|
+
img = %x{imgcat "#{img_path}"}
|
903
|
+
end
|
876
904
|
result = pre + img + post
|
877
905
|
end
|
878
906
|
end
|
@@ -911,7 +939,7 @@ module CLIMarkdown
|
|
911
939
|
if File.exists?(File.expand_path(cli))
|
912
940
|
File.executable?(File.expand_path(cli))
|
913
941
|
else
|
914
|
-
system "which #{cli}", :out => File::NULL
|
942
|
+
system "which #{cli}", :out => File::NULL, :err => File::NULL
|
915
943
|
end
|
916
944
|
end
|
917
945
|
|
@@ -963,29 +991,38 @@ module CLIMarkdown
|
|
963
991
|
|
964
992
|
out = cleanup_tables(out)
|
965
993
|
out = clean_markers(out)
|
966
|
-
out = out.gsub(/\n
|
994
|
+
out = out.gsub(/\n{2,}/m,"\n\n") + "#{xc}"
|
967
995
|
|
968
996
|
unless @options[:color]
|
969
997
|
out.uncolor!
|
970
998
|
end
|
971
999
|
|
972
1000
|
if @options[:pager]
|
973
|
-
page(
|
1001
|
+
page(out)
|
974
1002
|
else
|
975
|
-
$stdout.puts (
|
1003
|
+
$stdout.puts (out)
|
976
1004
|
end
|
977
1005
|
end
|
978
1006
|
|
979
1007
|
def which_pager
|
980
|
-
pagers = [ENV['GIT_PAGER'], ENV['PAGER']
|
981
|
-
|
982
|
-
|
1008
|
+
pagers = [ENV['GIT_PAGER'], ENV['PAGER']]
|
1009
|
+
|
1010
|
+
if exec_available('git')
|
1011
|
+
git_pager = `git config --get-all core.pager || true`.split.first
|
1012
|
+
git_pager && pagers.push(git_pager)
|
1013
|
+
end
|
1014
|
+
|
1015
|
+
pagers.concat(['bat', 'less', 'more', 'cat', 'pager'])
|
1016
|
+
|
983
1017
|
pagers.select! do |f|
|
984
1018
|
if f
|
985
1019
|
if f.strip =~ /[ |]/
|
986
1020
|
f
|
1021
|
+
elsif f == 'most'
|
1022
|
+
@log.warn('most not allowed as pager')
|
1023
|
+
false
|
987
1024
|
else
|
988
|
-
system "which #{f}", :out => File::NULL
|
1025
|
+
system "which #{f}", :out => File::NULL, :err => File::NULL
|
989
1026
|
end
|
990
1027
|
else
|
991
1028
|
false
|
data/lib/mdless/version.rb
CHANGED
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.
|
4
|
+
version: 1.0.18
|
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:
|
11
|
+
date: 2021-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -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
|
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
106
|
rubygems_version: 3.0.3
|
107
|
-
signing_key:
|
107
|
+
signing_key:
|
108
108
|
specification_version: 4
|
109
109
|
summary: A pager like less, but for Markdown files
|
110
110
|
test_files: []
|