mdless 1.0.14 → 1.0.19
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 +4 -4
- data/lib/mdless/converter.rb +55 -24
- 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: 177d5a80ad079db4b2ee9598a9cd723ca275a2b81ad7e933558cc57268a2a7bb
|
4
|
+
data.tar.gz: 8bd13a6eaea6098de22d044a0221fe4f80b95ed6876f6796021812e976dec751
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9f4f5e25bf137670ce14151334faa970fe4125ee39d4d243fc2498c2df57a77ef0f254b7adeeda3eaf8eabc18cf082e1513f177e10a3627aa824141e8e7af7c
|
7
|
+
data.tar.gz: f1c59f8420703918c2c398e595f87dc51c27f29c9b8ed5f6fa69a4889ec094eb6ef4c183525c5386fd4783efdf37f66b776b7c78a444f36969fe24c795ac0103
|
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,16 +991,16 @@ 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
|
|
@@ -990,8 +1018,11 @@ module CLIMarkdown
|
|
990
1018
|
if f
|
991
1019
|
if f.strip =~ /[ |]/
|
992
1020
|
f
|
1021
|
+
elsif f == 'most'
|
1022
|
+
@log.warn('most not allowed as pager')
|
1023
|
+
false
|
993
1024
|
else
|
994
|
-
system "which #{f}", :out => File::NULL
|
1025
|
+
system "which #{f}", :out => File::NULL, :err => File::NULL
|
995
1026
|
end
|
996
1027
|
else
|
997
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.19
|
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: []
|