mdless 1.0.12 → 1.0.17
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 +60 -25
- data/lib/mdless/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ac64b734fe42bba2b3b4ad71b9d660f8bb0b3e4dfed50b022386784c5fd7d49
|
4
|
+
data.tar.gz: 74d77256b4d9dba3e6aab1ff39f253b70ce8c0268f0ce7275f5622bce94d5ac9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d3358e267c7f3fa453bbe8fbcb73c6ab506b4d8bd2e275239ca407e7913a08cffdf4a04ad2d8c7a9c4152a08036cd47039aafa0b00beec85bffd6273b47d45b
|
7
|
+
data.tar.gz: f88b17617997dae9ffa4b7aec4bed55d02085af6625a45b331843a91fecad364619c6798f692b12c274c6a67831fa41835f39e3f4d66241e7a16615e4971775e
|
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
|
|
@@ -847,20 +848,41 @@ module CLIMarkdown
|
|
847
848
|
else
|
848
849
|
tail = match[4].nil? ? '' : " "+match[4].strip
|
849
850
|
result = nil
|
850
|
-
if exec_available('imgcat') && @options[:local_images]
|
851
|
+
if (exec_available('imgcat') || exec_available('chafa')) && @options[:local_images]
|
851
852
|
if match[3]
|
852
853
|
img_path = match[3]
|
853
854
|
if img_path =~ /^http/ && @options[:remote_images]
|
854
|
-
begin
|
855
|
-
res, s = Open3.capture2(%Q{curl -sS "#{img_path}" 2> /dev/null | imgcat})
|
856
855
|
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
856
|
+
if exec_available('chafa')
|
857
|
+
if File.directory?('.mdless_tmp')
|
858
|
+
FileUtils.rm_r '.mdless_tmp', force: true
|
859
|
+
end
|
860
|
+
Dir.mkdir('.mdless_tmp')
|
861
|
+
Dir.chdir('.mdless_tmp')
|
862
|
+
`curl -SsO #{img_path} 2> /dev/null`
|
863
|
+
tmp_img = File.basename(img_path)
|
864
|
+
img = `chafa "#{tmp_img}"`
|
865
|
+
pre = match[2].size > 0 ? " #{c(%i[d blue])}[#{match[2].strip}]\n" : ''
|
866
|
+
post = tail.size > 0 ? "\n #{c(%i[b blue])}-- #{tail} --" : ''
|
867
|
+
result = pre + img + post
|
868
|
+
Dir.chdir('..')
|
869
|
+
FileUtils.rm_r '.mdless_tmp', force: true
|
870
|
+
else
|
871
|
+
if exec_available('imgcat')
|
872
|
+
begin
|
873
|
+
res, s = Open3.capture2(%Q{curl -sS "#{img_path}" 2> /dev/null | imgcat})
|
874
|
+
|
875
|
+
if s.success?
|
876
|
+
pre = match[2].size > 0 ? " #{c(%i[d blue])}[#{match[2].strip}]\n" : ''
|
877
|
+
post = tail.size > 0 ? "\n #{c(%i[b blue])}-- #{tail} --" : ''
|
878
|
+
result = pre + res + post
|
879
|
+
end
|
880
|
+
rescue => e
|
881
|
+
@log.error(e)
|
882
|
+
end
|
883
|
+
else
|
884
|
+
@log.warn("No viewer for remote images")
|
861
885
|
end
|
862
|
-
rescue => e
|
863
|
-
@log.error(e)
|
864
886
|
end
|
865
887
|
else
|
866
888
|
if img_path =~ /^[~\/]/
|
@@ -872,7 +894,11 @@ module CLIMarkdown
|
|
872
894
|
if File.exists?(img_path)
|
873
895
|
pre = match[2].size > 0 ? " #{c(%i[d blue])}[#{match[2].strip}]\n" : ''
|
874
896
|
post = tail.size > 0 ? "\n #{c(%i[b blue])}-- #{tail} --" : ''
|
875
|
-
|
897
|
+
if exec_available('chafa')
|
898
|
+
img = %x{chafa "#{img_path}"}
|
899
|
+
elsif exec_available('imgcat')
|
900
|
+
img = %x{imgcat "#{img_path}"}
|
901
|
+
end
|
876
902
|
result = pre + img + post
|
877
903
|
end
|
878
904
|
end
|
@@ -911,7 +937,7 @@ module CLIMarkdown
|
|
911
937
|
if File.exists?(File.expand_path(cli))
|
912
938
|
File.executable?(File.expand_path(cli))
|
913
939
|
else
|
914
|
-
system "which #{cli}", :out => File::NULL
|
940
|
+
system "which #{cli}", :out => File::NULL, :err => File::NULL
|
915
941
|
end
|
916
942
|
end
|
917
943
|
|
@@ -963,29 +989,38 @@ module CLIMarkdown
|
|
963
989
|
|
964
990
|
out = cleanup_tables(out)
|
965
991
|
out = clean_markers(out)
|
966
|
-
out = out.gsub(/\n
|
992
|
+
out = out.gsub(/\n{2,}/m,"\n\n") + "#{xc}"
|
967
993
|
|
968
994
|
unless @options[:color]
|
969
995
|
out.uncolor!
|
970
996
|
end
|
971
997
|
|
972
998
|
if @options[:pager]
|
973
|
-
page(
|
999
|
+
page(out)
|
974
1000
|
else
|
975
|
-
$stdout.puts (
|
1001
|
+
$stdout.puts (out)
|
976
1002
|
end
|
977
1003
|
end
|
978
1004
|
|
979
1005
|
def which_pager
|
980
|
-
pagers = [ENV['GIT_PAGER'], ENV['PAGER']
|
981
|
-
|
982
|
-
|
1006
|
+
pagers = [ENV['GIT_PAGER'], ENV['PAGER']]
|
1007
|
+
|
1008
|
+
if exec_available('git')
|
1009
|
+
git_pager = `git config --get-all core.pager || true`.split.first
|
1010
|
+
git_pager && pagers.push(git_pager)
|
1011
|
+
end
|
1012
|
+
|
1013
|
+
pagers.concat(['bat', 'less', 'more', 'cat', 'pager'])
|
1014
|
+
|
983
1015
|
pagers.select! do |f|
|
984
1016
|
if f
|
985
1017
|
if f.strip =~ /[ |]/
|
986
1018
|
f
|
1019
|
+
elsif f == 'most'
|
1020
|
+
@log.warn('most not allowed as pager')
|
1021
|
+
false
|
987
1022
|
else
|
988
|
-
system "which #{f}", :out => File::NULL
|
1023
|
+
system "which #{f}", :out => File::NULL, :err => File::NULL
|
989
1024
|
end
|
990
1025
|
else
|
991
1026
|
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.17
|
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
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
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: '
|
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
|
@@ -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: []
|