mdless 2.0.17 → 2.0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -6
- data/lib/mdless/array.rb +11 -0
- data/lib/mdless/colors.rb +13 -5
- data/lib/mdless/console.rb +105 -94
- data/lib/mdless/converter.rb +140 -103
- data/lib/mdless/string.rb +94 -8
- data/lib/mdless/taskpaper.rb +79 -9
- data/lib/mdless/version.rb +1 -1
- data/lib/mdless.rb +46 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '094b8ac8273e025bee23c350cc7aee02682b2445d22523d216b4e621d067ff9b'
|
4
|
+
data.tar.gz: 495dc941df5b4235c9bb5d7cccb37739e1cc783679d276d026d36a7a9dafc937
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f15d9fc92d6286708adc3060dfbc265a4064419eceecb25dfe4de3f7d60e1f033f7e2f157a34ef2940130ca1caea565e9fe43a2f5cab5f611c8f0d864830f54b
|
7
|
+
data.tar.gz: 9db7cd9e9914bd37bc1a97362e27ef169d899f89fcae0e2e8004da3bd48cffe539518e61396e0f325953a5008adbbb8b37debcbabffdce1d08268a7b73b27f2c
|
data/README.md
CHANGED
@@ -31,12 +31,6 @@ If you run into errors, try `gem install --user-install mdless`, or `sudo gem in
|
|
31
31
|
|
32
32
|
### Dependencies
|
33
33
|
|
34
|
-
Some OSs are missing `tput`, which is necessary for mdless.
|
35
|
-
|
36
|
-
apt update
|
37
|
-
apt install ruby ncurses-utils
|
38
|
-
gem install mdless
|
39
|
-
|
40
34
|
To render images, you need `imgcat` or `chafa` installed (`brew install chafa`).
|
41
35
|
|
42
36
|
For syntax highlighting, the `pygmentize` command must be available, part of the [Pygments](http://pygments.org/) package (`brew install pygments`).
|
data/lib/mdless/array.rb
ADDED
data/lib/mdless/colors.rb
CHANGED
@@ -55,7 +55,11 @@ module CLIMarkdown
|
|
55
55
|
}
|
56
56
|
|
57
57
|
def uncolor
|
58
|
-
self.gsub(/\e\[[\d;]+m/,'')
|
58
|
+
self.unpad.gsub(/\e\[[\d;]+m/,'')
|
59
|
+
end
|
60
|
+
|
61
|
+
def unpad
|
62
|
+
self.gsub(/\u00A0/, ' ')
|
59
63
|
end
|
60
64
|
|
61
65
|
# Get the calculated ANSI color at the end of the
|
@@ -129,7 +133,6 @@ module CLIMarkdown
|
|
129
133
|
end
|
130
134
|
|
131
135
|
def wrap(width=78,foreground=:x)
|
132
|
-
|
133
136
|
if self.uncolor =~ /(^([%~] |\s*>)| +[=\-]{5,})/
|
134
137
|
return self
|
135
138
|
end
|
@@ -141,6 +144,9 @@ module CLIMarkdown
|
|
141
144
|
|
142
145
|
line += self.match(/^\s*/)[0].gsub(/\t/,' ')
|
143
146
|
input = self.dup # .gsub(/(\w-)(\w)/,'\1 \2')
|
147
|
+
input.gsub!(/\[.*?\]\(.*?\)/) do |link|
|
148
|
+
link.gsub(/ /, "\u00A0")
|
149
|
+
end
|
144
150
|
input.split(/\s+/).each do |word|
|
145
151
|
last_ansi = line.scan(/\e\[[\d;]+m/)[-1] || ''
|
146
152
|
if visible_width + word.size_clean >= width
|
@@ -154,9 +160,11 @@ module CLIMarkdown
|
|
154
160
|
visible_width += word.size_clean + 1
|
155
161
|
line << " " << last_ansi + word
|
156
162
|
end
|
157
|
-
|
158
|
-
|
159
|
-
|
163
|
+
end
|
164
|
+
lines << line + match(/\s*$/)[0] + xc(foreground) if line
|
165
|
+
lines.join("\n").gsub(/\[.*?\]\(.*?\)/) do |link|
|
166
|
+
link.gsub(/\u00A0/, ' ')
|
167
|
+
end
|
160
168
|
end
|
161
169
|
|
162
170
|
def c(args)
|
data/lib/mdless/console.rb
CHANGED
@@ -4,13 +4,13 @@ module Redcarpet
|
|
4
4
|
include CLIMarkdown::Colors
|
5
5
|
include CLIMarkdown::Theme
|
6
6
|
|
7
|
-
|
7
|
+
attr_accessor :headers
|
8
|
+
attr_writer :file
|
8
9
|
|
9
10
|
@@listitemid = 0
|
10
11
|
@@listid = 0
|
11
12
|
@@elementid = 0
|
12
13
|
@@footnotes = []
|
13
|
-
@@headers = []
|
14
14
|
@@links = []
|
15
15
|
@@footer_links = []
|
16
16
|
|
@@ -58,20 +58,36 @@ module Redcarpet
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
def
|
62
|
-
|
63
|
-
|
61
|
+
def code_bg(input, width)
|
62
|
+
input.split(/\n/).map do |line|
|
63
|
+
tail = line.uncolor.length < width ? "\u00A0" * (width - line.uncolor.length) : ''
|
64
|
+
"#{x}#{line}#{tail}#{x}"
|
65
|
+
end.join("\n")
|
64
66
|
end
|
65
67
|
|
66
68
|
def hilite_code(code_block, language)
|
67
|
-
|
69
|
+
if MDLess.options[:syntax_higlight] && !exec_available('pygmentize')
|
70
|
+
MDLess.log.error('Syntax highlighting requested by pygmentize is not available')
|
71
|
+
MDLess.options[:syntax_higlight] = false
|
72
|
+
end
|
73
|
+
|
74
|
+
longest_line = code_block.uncolor.split(/\n/).longest_element.length + 4
|
75
|
+
longest_line = longest_line > MDLess.cols ? MDLess.cols : longest_line
|
68
76
|
|
69
|
-
if
|
70
|
-
|
77
|
+
if MDLess.options[:syntax_higlight]
|
78
|
+
pyg = TTY::Which.which('pygmentize')
|
79
|
+
lexer = language&.valid_lexer? ? "-l #{language}" : '-g'
|
71
80
|
begin
|
81
|
+
pygments_theme = MDLess.options[:pygments_theme] || MDLess.theme['code_block']['pygments_theme']
|
82
|
+
|
83
|
+
unless pygments_theme.valid_pygments_theme?
|
84
|
+
MDLess.log.error("Invalid Pygments theme #{pygments_theme}, defaulting to 'default' for highlighting")
|
85
|
+
pygments_theme = 'default'
|
86
|
+
end
|
87
|
+
|
72
88
|
cmd = [
|
73
|
-
|
74
|
-
"-O style=#{
|
89
|
+
"#{pyg} -f terminal256",
|
90
|
+
"-O style=#{pygments_theme}",
|
75
91
|
lexer,
|
76
92
|
'2> /dev/null'
|
77
93
|
].join(' ')
|
@@ -84,10 +100,10 @@ module Redcarpet
|
|
84
100
|
'> ',
|
85
101
|
"#{color('code_block bg')}#{l.strip}#{xc}"
|
86
102
|
].join
|
87
|
-
end.join("\n").blackout(
|
103
|
+
end.join("\n").blackout(MDLess.theme['code_block']['bg']) + "#{xc}\n"
|
88
104
|
end
|
89
105
|
rescue StandardError => e
|
90
|
-
|
106
|
+
MDLess.log.error(e)
|
91
107
|
hilite = code_block
|
92
108
|
end
|
93
109
|
else
|
@@ -99,20 +115,26 @@ module Redcarpet
|
|
99
115
|
line,
|
100
116
|
xc
|
101
117
|
].join
|
102
|
-
end.join("\n").blackout(
|
118
|
+
end.join("\n").blackout(MDLess.theme['code_block']['bg']) + "#{xc}\n"
|
103
119
|
end
|
104
120
|
|
121
|
+
top_border = if language.nil? || language.empty?
|
122
|
+
'-' * longest_line
|
123
|
+
else
|
124
|
+
"--[ #{language} ]#{'-' * (longest_line - 6 - language.length)}"
|
125
|
+
end
|
126
|
+
|
105
127
|
[
|
106
128
|
xc,
|
107
129
|
color('code_block border'),
|
108
|
-
|
130
|
+
top_border,
|
109
131
|
xc,
|
110
132
|
"\n",
|
111
133
|
color('code_block color'),
|
112
|
-
hilite.chomp,
|
134
|
+
code_bg(hilite.chomp, longest_line),
|
113
135
|
"\n",
|
114
136
|
color('code_block border'),
|
115
|
-
'-' *
|
137
|
+
'-' * longest_line,
|
116
138
|
xc
|
117
139
|
].join
|
118
140
|
end
|
@@ -120,17 +142,17 @@ module Redcarpet
|
|
120
142
|
def color(key)
|
121
143
|
val = nil
|
122
144
|
keys = key.split(/[ ,>]/)
|
123
|
-
if
|
124
|
-
val =
|
145
|
+
if MDLess.theme.key?(keys[0])
|
146
|
+
val = MDLess.theme[keys.shift]
|
125
147
|
else
|
126
|
-
|
148
|
+
MDLess.log.error("Invalid theme key: #{key}") unless keys[0] =~ /^text/
|
127
149
|
return c([:reset])
|
128
150
|
end
|
129
151
|
keys.each do |k|
|
130
152
|
if val.key?(k)
|
131
153
|
val = val[k]
|
132
154
|
else
|
133
|
-
|
155
|
+
MDLess.log.error("Invalid theme key: #{k}")
|
134
156
|
return c([:reset])
|
135
157
|
end
|
136
158
|
end
|
@@ -149,11 +171,12 @@ module Redcarpet
|
|
149
171
|
|
150
172
|
def block_quote(quote)
|
151
173
|
ret = "\n\n"
|
152
|
-
quote.split(
|
174
|
+
quote.wrap(MDLess.cols, color('blockquote color')).split(/\n/).each do |line|
|
153
175
|
ret += [
|
154
176
|
color('blockquote marker color'),
|
155
|
-
|
177
|
+
MDLess.theme['blockquote']['marker']['character'],
|
156
178
|
color('blockquote color'),
|
179
|
+
' ',
|
157
180
|
line,
|
158
181
|
"\n"
|
159
182
|
].join('')
|
@@ -168,17 +191,18 @@ module Redcarpet
|
|
168
191
|
def header(text, header_level)
|
169
192
|
pad = ''
|
170
193
|
ansi = ''
|
194
|
+
text.clean_header_ids!
|
171
195
|
case header_level
|
172
196
|
when 1
|
173
197
|
ansi = color('h1 color')
|
174
198
|
pad = color('h1 pad')
|
175
|
-
char =
|
176
|
-
pad += text.length + 2 >
|
199
|
+
char = MDLess.theme['h1']['pad_char'] || '='
|
200
|
+
pad += text.length + 2 > MDLess.cols ? char * text.length : char * (MDLess.cols - (text.length + 1))
|
177
201
|
when 2
|
178
202
|
ansi = color('h2 color')
|
179
203
|
pad = color('h2 pad')
|
180
|
-
char =
|
181
|
-
pad += text.length + 2 >
|
204
|
+
char = MDLess.theme['h2']['pad_char'] || '-'
|
205
|
+
pad += text.length + 2 > MDLess.cols ? char * text.length : char * (MDLess.cols - (text.length + 1))
|
182
206
|
when 3
|
183
207
|
ansi = color('h3 color')
|
184
208
|
when 4
|
@@ -193,15 +217,15 @@ module Redcarpet
|
|
193
217
|
# iTerm Marks for navigation on h1-3
|
194
218
|
if header_level < 4 &&
|
195
219
|
ENV['TERM_PROGRAM'] =~ /^iterm/i &&
|
196
|
-
|
220
|
+
MDLess.options[:pager] == false
|
197
221
|
ansi = "\e]1337;SetMark\a#{ansi}"
|
198
222
|
end
|
199
223
|
|
200
|
-
"\n#{xc}#{ansi}#{text} #{pad}#{xc}\n\n"
|
224
|
+
"\n\n#{xc}#{ansi}#{text} #{pad}#{xc}\n\n"
|
201
225
|
end
|
202
226
|
|
203
227
|
def hrule()
|
204
|
-
"\n\n#{color('hr color')}#{'_' *
|
228
|
+
"\n\n#{color('hr color')}#{'_' * MDLess.cols}#{xc}\n\n"
|
205
229
|
end
|
206
230
|
|
207
231
|
def paragraph(text)
|
@@ -268,11 +292,11 @@ module Redcarpet
|
|
268
292
|
[
|
269
293
|
pre_element,
|
270
294
|
color('code_span marker'),
|
271
|
-
|
295
|
+
MDLess.theme['code_span']['character'],
|
272
296
|
color('code_span color'),
|
273
297
|
code,
|
274
298
|
color('code_span marker'),
|
275
|
-
|
299
|
+
MDLess.theme['code_span']['character'],
|
276
300
|
xc,
|
277
301
|
post_element
|
278
302
|
].join('')
|
@@ -282,9 +306,9 @@ module Redcarpet
|
|
282
306
|
[
|
283
307
|
pre_element,
|
284
308
|
color('emphasis bold'),
|
285
|
-
|
309
|
+
MDLess.theme['emphasis']['bold_character'],
|
286
310
|
text,
|
287
|
-
|
311
|
+
MDLess.theme['emphasis']['bold_character'],
|
288
312
|
xc,
|
289
313
|
post_element
|
290
314
|
].join
|
@@ -294,9 +318,9 @@ module Redcarpet
|
|
294
318
|
[
|
295
319
|
pre_element,
|
296
320
|
color('emphasis italic'),
|
297
|
-
|
321
|
+
MDLess.theme['emphasis']['italic_character'],
|
298
322
|
text,
|
299
|
-
|
323
|
+
MDLess.theme['emphasis']['italic_character'],
|
300
324
|
xc,
|
301
325
|
post_element
|
302
326
|
].join
|
@@ -306,11 +330,11 @@ module Redcarpet
|
|
306
330
|
[
|
307
331
|
pre_element,
|
308
332
|
color('emphasis bold-italic'),
|
309
|
-
|
310
|
-
|
333
|
+
MDLess.theme['emphasis']['italic_character'],
|
334
|
+
MDLess.theme['emphasis']['bold_character'],
|
311
335
|
text,
|
312
|
-
|
313
|
-
|
336
|
+
MDLess.theme['emphasis']['bold_character'],
|
337
|
+
MDLess.theme['emphasis']['italic_character'],
|
314
338
|
xc,
|
315
339
|
post_element
|
316
340
|
].join
|
@@ -505,7 +529,9 @@ module Redcarpet
|
|
505
529
|
|
506
530
|
lines = input.split(/\n/)
|
507
531
|
line1 = lines.shift
|
508
|
-
|
532
|
+
pre = ' ' * (indent + 1)
|
533
|
+
cols = MDLess.cols - pre.length
|
534
|
+
body = lines.map { |l| "#{pre}#{l}" }.join("\n")
|
509
535
|
"#{line1}\n#{body}"
|
510
536
|
end
|
511
537
|
|
@@ -598,8 +624,8 @@ module Redcarpet
|
|
598
624
|
end
|
599
625
|
|
600
626
|
def get_headers(input)
|
601
|
-
unless
|
602
|
-
|
627
|
+
unless @headers && !@headers.empty?
|
628
|
+
@headers = []
|
603
629
|
headers = input.scan(/^((?!#!)(\#{1,6})\s*([^#]+?)(?: #+)?\s*|(\S.+)\n([=-]+))$/i)
|
604
630
|
|
605
631
|
headers.each do |h|
|
@@ -615,7 +641,7 @@ module Redcarpet
|
|
615
641
|
hlevel = h[1].length
|
616
642
|
title = h[2]
|
617
643
|
end
|
618
|
-
|
644
|
+
@headers << [
|
619
645
|
'#' * hlevel,
|
620
646
|
title,
|
621
647
|
h[0]
|
@@ -623,22 +649,24 @@ module Redcarpet
|
|
623
649
|
end
|
624
650
|
end
|
625
651
|
|
626
|
-
|
652
|
+
@headers
|
627
653
|
end
|
628
654
|
|
629
655
|
def color_meta(text)
|
630
656
|
input = text.dup
|
657
|
+
input.clean_empty_lines!
|
658
|
+
|
631
659
|
first_line = input.split("\n").first
|
632
660
|
if first_line =~ /(?i-m)^---[ \t]*?$/
|
633
|
-
|
661
|
+
MDLess.log.info('Found YAML')
|
634
662
|
# YAML
|
635
663
|
in_yaml = true
|
636
664
|
input.sub!(/(?i-m)^---[ \t]*\n([\s\S]*?)\n[-.]{3}[ \t]*\n/m) do
|
637
665
|
m = Regexp.last_match
|
638
|
-
|
666
|
+
MDLess.log.info('Processing YAML Header')
|
639
667
|
lines = m[0].split(/\n/)
|
640
|
-
longest = lines.
|
641
|
-
longest = longest <
|
668
|
+
longest = lines.longest_element.length
|
669
|
+
longest = longest < MDLess.cols ? longest + 1 : MDLess.cols
|
642
670
|
lines.map do |line|
|
643
671
|
if line =~ /^[-.]{3}\s*$/
|
644
672
|
line = "#{color('metadata marker')}#{'%' * longest}"
|
@@ -654,13 +682,13 @@ module Redcarpet
|
|
654
682
|
end
|
655
683
|
|
656
684
|
if !in_yaml && first_line =~ /(?i-m)^[\w ]+:\s+\S+/
|
657
|
-
|
685
|
+
MDLess.log.info('Found MMD Headers')
|
658
686
|
input.sub!(/(?i-m)^([\S ]+:[\s\S]*?)+(?=\n\n)/) do |mmd|
|
659
687
|
lines = mmd.split(/\n/)
|
660
688
|
return mmd if lines.count > 20
|
661
689
|
|
662
690
|
longest = lines.inject { |memo, word| memo.length > word.length ? memo : word }.length
|
663
|
-
longest = longest <
|
691
|
+
longest = longest < MDLess.cols ? longest + 1 : MDLess.cols
|
664
692
|
lines.map do |line|
|
665
693
|
line.sub!(/^(.*?:)[ \t]+(\S)/, '\1 \2')
|
666
694
|
line = "#{color('metadata color')}#{line}"
|
@@ -674,41 +702,23 @@ module Redcarpet
|
|
674
702
|
end
|
675
703
|
|
676
704
|
def preprocess(input)
|
677
|
-
in_yaml = false
|
678
|
-
|
679
|
-
if @options[:taskpaper] == :auto
|
680
|
-
@options[:taskpaper] = if @file =~ /\.taskpaper/
|
681
|
-
@log.info('TaskPaper extension detected')
|
682
|
-
true
|
683
|
-
elsif CLIMarkdown::TaskPaper.is_taskpaper?(input)
|
684
|
-
@log.info('TaskPaper document detected')
|
685
|
-
true
|
686
|
-
else
|
687
|
-
false
|
688
|
-
end
|
689
|
-
end
|
690
|
-
|
691
705
|
input = color_meta(input)
|
692
706
|
|
693
|
-
if @options[:taskpaper]
|
694
|
-
input = CLIMarkdown::TaskPaper.highlight(input, @theme)
|
695
|
-
input = highlight_tags(input)
|
696
|
-
return input
|
697
|
-
end
|
698
|
-
|
699
|
-
|
700
707
|
## Replace setex headers with ATX
|
701
708
|
input.gsub!(/^([^\n]+)\n={2,}\s*$/m, "# \\1\n")
|
702
709
|
input.gsub!(/^([^\n]+?)\n-{2,}\s*$/m, "## \\1\n")
|
703
710
|
|
704
|
-
|
711
|
+
@headers = get_headers(input)
|
705
712
|
|
706
|
-
if
|
713
|
+
if MDLess.options[:section]
|
707
714
|
new_content = []
|
708
|
-
|
715
|
+
MDLess.log.info("Matching section(s) #{MDLess.options[:section].join(', ')}")
|
716
|
+
MDLess.options[:section].each do |sect|
|
717
|
+
comparison = MDLess.options[:section][0].is_a?(String) ? :regex : :numeric
|
718
|
+
|
709
719
|
in_section = false
|
710
720
|
top_level = 1
|
711
|
-
input.split(/\n/).
|
721
|
+
input.split(/\n/).each_with_index do |graf, idx|
|
712
722
|
if graf =~ /^(#+) *(.*?)( *#+)?$/
|
713
723
|
m = Regexp.last_match
|
714
724
|
level = m[1].length
|
@@ -720,7 +730,8 @@ module Redcarpet
|
|
720
730
|
in_section = false
|
721
731
|
break
|
722
732
|
end
|
723
|
-
elsif title.downcase
|
733
|
+
elsif (comparison == :regex && title.downcase =~ sect.downcase.to_rx) ||
|
734
|
+
(comparison == :numeric && title.downcase == @headers[sect - 1][1].downcase)
|
724
735
|
in_section = true
|
725
736
|
top_level = level + 1
|
726
737
|
new_content.push(graf)
|
@@ -769,7 +780,7 @@ module Redcarpet
|
|
769
780
|
counter = 1
|
770
781
|
|
771
782
|
grafs.map! do |graf|
|
772
|
-
|
783
|
+
return "\n" if graf =~ /^ *\n$/
|
773
784
|
|
774
785
|
links_added = false
|
775
786
|
|
@@ -779,7 +790,7 @@ module Redcarpet
|
|
779
790
|
content = link[:content]
|
780
791
|
title = link[:title]&.uncolor
|
781
792
|
graf.gsub!(/#{Regexp.escape(link[:link])}/, color_link_reference(url, counter, content))
|
782
|
-
if
|
793
|
+
if MDLess.options[:links] == :paragraph
|
783
794
|
if links_added
|
784
795
|
graf += "\n#{color_reference_link(url, title, counter)}"
|
785
796
|
else
|
@@ -795,7 +806,7 @@ module Redcarpet
|
|
795
806
|
"\n#{graf}\n"
|
796
807
|
end
|
797
808
|
|
798
|
-
if
|
809
|
+
if MDLess.options[:links] == :paragraph
|
799
810
|
grafs.join("\n")
|
800
811
|
else
|
801
812
|
grafs.join("\n") + "\n#{@@footer_links.join("\n")}\n"
|
@@ -815,16 +826,16 @@ module Redcarpet
|
|
815
826
|
input.gsub(%r{<<img>>(.*?)<</img>>}) do
|
816
827
|
link, title, alt_text = Regexp.last_match(1).split(/\|\|/)
|
817
828
|
|
818
|
-
if (exec_available('imgcat') || exec_available('chafa')) &&
|
829
|
+
if (exec_available('imgcat') || exec_available('chafa')) && MDLess.options[:local_images]
|
819
830
|
if exec_available('imgcat')
|
820
|
-
|
831
|
+
MDLess.log.info('Using imgcat for image rendering')
|
821
832
|
elsif exec_available('chafa')
|
822
|
-
|
833
|
+
MDLess.log.info('Using chafa for image rendering')
|
823
834
|
end
|
824
835
|
img_path = link
|
825
|
-
if img_path =~ /^http/ &&
|
836
|
+
if img_path =~ /^http/ && MDLess.options[:remote_images]
|
826
837
|
if exec_available('imgcat')
|
827
|
-
|
838
|
+
MDLess.log.info('Using imgcat for image rendering')
|
828
839
|
begin
|
829
840
|
res, s = Open3.capture2(%(curl -sS "#{img_path}" 2> /dev/null | imgcat))
|
830
841
|
|
@@ -834,10 +845,10 @@ module Redcarpet
|
|
834
845
|
result = pre + res + post
|
835
846
|
end
|
836
847
|
rescue StandardError => e
|
837
|
-
|
848
|
+
MDLess.log.error(e)
|
838
849
|
end
|
839
850
|
elsif exec_available('chafa')
|
840
|
-
|
851
|
+
MDLess.log.info('Using chafa for image rendering')
|
841
852
|
term = '-f sixels'
|
842
853
|
term = ENV['TERMINAL_PROGRAM'] =~ /iterm/i ? '-f iterm' : term
|
843
854
|
term = ENV['TERMINAL_PROGRAM'] =~ /kitty/i ? '-f kitty' : term
|
@@ -853,13 +864,13 @@ module Redcarpet
|
|
853
864
|
Dir.chdir('..')
|
854
865
|
FileUtils.rm_r '.mdless_tmp', force: true
|
855
866
|
else
|
856
|
-
|
867
|
+
MDLess.log.warn('No viewer for remote images')
|
857
868
|
end
|
858
869
|
else
|
859
870
|
if img_path =~ %r{^[~/]}
|
860
871
|
img_path = File.expand_path(img_path)
|
861
|
-
elsif
|
862
|
-
base = File.expand_path(File.dirname(
|
872
|
+
elsif MDLess.file
|
873
|
+
base = File.expand_path(File.dirname(MDLess.file))
|
863
874
|
img_path = File.join(base, img_path)
|
864
875
|
end
|
865
876
|
if File.exist?(img_path)
|
@@ -951,9 +962,9 @@ module Redcarpet
|
|
951
962
|
def postprocess(input)
|
952
963
|
input.scrub!
|
953
964
|
|
954
|
-
input = highlight_wiki_links(input) if
|
965
|
+
input = highlight_wiki_links(input) if MDLess.options[:wiki_links]
|
955
966
|
|
956
|
-
if
|
967
|
+
if MDLess.options[:inline_footnotes]
|
957
968
|
input = insert_footnotes(input)
|
958
969
|
else
|
959
970
|
footnotes = @@footnotes.map.with_index do |fn, i|
|
@@ -970,11 +981,11 @@ module Redcarpet
|
|
970
981
|
# misc html
|
971
982
|
input.gsub!(%r{<br */?>}, "#{pre_element}\n#{post_element}")
|
972
983
|
# format links
|
973
|
-
input = reference_links(input) if
|
984
|
+
input = reference_links(input) if MDLess.options[:links] == :reference || MDLess.options[:links] == :paragraph
|
974
985
|
# lists
|
975
986
|
input = fix_lists(input)
|
976
|
-
input = render_images(input) if
|
977
|
-
input = highlight_tags(input) if
|
987
|
+
input = render_images(input) if MDLess.options[:local_images]
|
988
|
+
input = highlight_tags(input) if MDLess.options[:at_tags] || MDLess.options[:taskpaper]
|
978
989
|
fix_colors(input)
|
979
990
|
end
|
980
991
|
end
|