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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d80ed856b198db9752c7ac96f964b2b2e05f7706288aef8fbf901417952a967
4
- data.tar.gz: ad820a3d6a885fc2f50decf0b6f52444d267ca84f9b3bbf5f3945cce8413df15
3
+ metadata.gz: '094b8ac8273e025bee23c350cc7aee02682b2445d22523d216b4e621d067ff9b'
4
+ data.tar.gz: 495dc941df5b4235c9bb5d7cccb37739e1cc783679d276d026d36a7a9dafc937
5
5
  SHA512:
6
- metadata.gz: 60dcb01d030a0115bb49616dd507c53a2b605dc8f0d28a194092150489c36adfb33450b7ba3c87f54b4048bc6b5114cfce2b914c240e129a2cbf36f4d76ec420
7
- data.tar.gz: b67938b0f651c324845d107074f04a647d8b46c60ee09386be627a1ad2d5ff50b08f31ef9a12984a6a209aeaa7d632cb47313c425c01a47f49b6b72b7a1f6022
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`).
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ::Array
4
+ def longest_element
5
+ group_by(&:size).max.last[0]
6
+ end
7
+
8
+ def longest_elements
9
+ group_by(&:size).max.last
10
+ end
11
+ end
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
- end
158
- lines << line + self.match(/\s*$/)[0] + xc(foreground) if line
159
- return lines.join("\n") # .gsub(/\- (\S)/,'-\1')
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)
@@ -4,13 +4,13 @@ module Redcarpet
4
4
  include CLIMarkdown::Colors
5
5
  include CLIMarkdown::Theme
6
6
 
7
- attr_writer :theme, :cols, :log, :options, :file
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 valid_lexer?(language)
62
- lexers = %w(Clipper XBase Cucumber cucumber Gherkin gherkin RobotFramework robotframework abap ada ada95ada2005 ahk antlr-as antlr-actionscript antlr-cpp antlr-csharp antlr-c# antlr-java antlr-objc antlr-perl antlr-python antlr-ruby antlr-rb antlr apacheconf aconf apache applescript as actionscript as3 actionscript3 aspectj aspx-cs aspx-vb asy asymptote autoit Autoit awk gawk mawk nawk basemake bash sh ksh bat bbcode befunge blitzmax bmax boo brainfuck bf bro bugs winbugs openbugs c-objdump c ca65 cbmbas ceylon cfengine3 cf3 cfm cfs cheetah spitfire clojure clj cmake cobol cobolfree coffee-script coffeescript common-lisp cl console control coq cpp c++ cpp-objdump c++-objdumb cxx-objdump croc csharp c# css+django css+jinja css+erb css+ruby css+genshitext css+genshi css+lasso css+mako css+myghty css+php css+smarty css cuda cu cython pyx d-objdump d dart delphi pas pascal objectpascal dg diff udiff django jinja dpatch dtd duel Duel Engine Duel View JBST jbst JsonML+BST dylan-console dylan-repl dylan-lid lid dylan ec ecl elixir ex exs erb erl erlang evoque factor fan fancy fy felix flx fortran fsharp gas genshi kid xml+genshi xml+kid genshitext glsl gnuplot go gooddata-cl gosu groff nroff man groovy gst haml HAML haskell hs haxeml hxml html+cheetah html+spitfire html+django html+jinja html+evoque html+genshi html+kid html+lasso html+mako html+myghty html+php html+smarty html+velocity html http hx haXe hybris hy idl iex ini cfg io ioke ik irc jade JADE jags java jlcon js+cheetah javascript+cheetah js+spitfire javascript+spitfire js+django javascript+django js+jinja javascript+jinja js+erb javascript+erb js+ruby javascript+ruby js+genshitext js+genshi javascript+genshitext javascript+genshi js+lasso javascript+lasso js+mako javascript+mako js+myghty javascript+myghty js+php javascript+php js+smarty javascript+smarty js javascript json jsp julia jl kconfig menuconfig linux-config kernel-config koka kotlin lasso lassoscript lhs literate-haskell lighty lighttpd live-script livescript llvm logos logtalk lua make makefile mf bsdmake mako maql mason matlab matlabsession minid modelica modula2 m2 monkey moocode moon moonscript mscgen msc mupad mxml myghty mysql nasm nemerle newlisp newspeak nginx nimrod nim nsis nsi nsh numpy objdump objective-c++ objectivec++ obj-c++ objc++ objective-c objectivec obj-c objc objective-j objectivej obj-j objj ocaml octave ooc opa openedge abl progress perl pl php php3 php4 php5 plpgsql postgresql postgres postscript pot po pov powershell posh ps1 prolog properties protobuf psql postgresql-console postgres-console puppet py3tb pycon pypylog pypy pytb python py sage python3 py3 qml Qt Meta Language Qt modeling Language racket rkt ragel-c ragel-cpp ragel-d ragel-em ragel-java ragel-objc ragel-ruby ragel-rb ragel raw rb ruby duby rbcon irb rconsole rout rd rebol redcode registry rhtml html+erb html+ruby rst rest restructuredtext rust sass SASS scala scaml SCAML scheme scm scilab scss shell-session smali smalltalk squeak smarty sml snobol sourceslist sources.list sp spec splus s r sql sqlite3 squidconf squid.conf squid ssp stan systemverilog sv tcl tcsh csh tea tex latex text trac-wiki moin treetop ts urbiscript vala vapi vb.net vbnet velocity verilog v vgl vhdl vim xml+cheetah xml+spitfire xml+django xml+jinja xml+erb xml+ruby xml+evoque xml+lasso xml+mako xml+myghty xml+php xml+smarty xml+velocity xml xquery xqy xq xql xqm xslt xtend yaml)
63
- lexers.include? language.strip
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
- @log.error('Syntax highlighting requested by pygmentize is not available') if @options[:syntax_higlight] && !exec_available('pygmentize')
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 @options[:syntax_higlight] && exec_available('pygmentize')
70
- lexer = language && valid_lexer?(language) ? "-l #{language}" : '-g'
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
- 'pygmentize -f terminal256',
74
- "-O style=#{@theme['code_block']['pygments_theme']}",
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(@theme['code_block']['bg']) + "#{xc}\n"
103
+ end.join("\n").blackout(MDLess.theme['code_block']['bg']) + "#{xc}\n"
88
104
  end
89
105
  rescue StandardError => e
90
- @log.error(e)
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(@theme['code_block']['bg']) + "#{xc}\n"
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
- '-' * 20,
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
- '-' * 20,
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 @theme.key?(keys[0])
124
- val = @theme[keys.shift]
145
+ if MDLess.theme.key?(keys[0])
146
+ val = MDLess.theme[keys.shift]
125
147
  else
126
- @log.error("Invalid theme key: #{key}") unless keys[0] =~ /^text/
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
- @log.error("Invalid theme key: #{k}")
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("\n").each do |line|
174
+ quote.wrap(MDLess.cols, color('blockquote color')).split(/\n/).each do |line|
153
175
  ret += [
154
176
  color('blockquote marker color'),
155
- @theme['blockquote']['marker']['character'],
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 = @theme['h1']['pad_char'] || '='
176
- pad += text.length + 2 > @cols ? char * text.length : char * (@cols - (text.length + 1))
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 = @theme['h2']['pad_char'] || '-'
181
- pad += text.length + 2 > @cols ? char * text.length : char * (@cols - (text.length + 1))
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
- @options[:pager] == false
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')}#{'_' * @cols}#{xc}\n\n"
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
- @theme['code_span']['character'],
295
+ MDLess.theme['code_span']['character'],
272
296
  color('code_span color'),
273
297
  code,
274
298
  color('code_span marker'),
275
- @theme['code_span']['character'],
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
- @theme['emphasis']['bold_character'],
309
+ MDLess.theme['emphasis']['bold_character'],
286
310
  text,
287
- @theme['emphasis']['bold_character'],
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
- @theme['emphasis']['italic_character'],
321
+ MDLess.theme['emphasis']['italic_character'],
298
322
  text,
299
- @theme['emphasis']['italic_character'],
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
- @theme['emphasis']['italic_character'],
310
- @theme['emphasis']['bold_character'],
333
+ MDLess.theme['emphasis']['italic_character'],
334
+ MDLess.theme['emphasis']['bold_character'],
311
335
  text,
312
- @theme['emphasis']['bold_character'],
313
- @theme['emphasis']['italic_character'],
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
- body = lines.map { |l| "#{' ' * (indent + 1)}#{l}" }.join("\n")
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 @@headers && !@@headers.empty?
602
- @@headers = []
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
- @@headers << [
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
- @@headers
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
- @log.info('Found YAML')
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
- @log.info('Processing YAML Header')
666
+ MDLess.log.info('Processing YAML Header')
639
667
  lines = m[0].split(/\n/)
640
- longest = lines.inject { |memo, word| memo.length > word.length ? memo : word }.length
641
- longest = longest < @cols ? longest + 1 : @cols
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
- @log.info('Found MMD Headers')
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 < @cols ? longest + 1 : @cols
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
- @@headers = get_headers(input)
711
+ @headers = get_headers(input)
705
712
 
706
- if @options[:section]
713
+ if MDLess.options[:section]
707
714
  new_content = []
708
- @options[:section].each do |sect|
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/).each do |graf|
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 == @@headers[sect - 1][1].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
- next if graf =~ /^$/
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 @options[:links] == :paragraph
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 @options[:links] == :paragraph
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')) && @options[:local_images]
829
+ if (exec_available('imgcat') || exec_available('chafa')) && MDLess.options[:local_images]
819
830
  if exec_available('imgcat')
820
- @log.info('Using imgcat for image rendering')
831
+ MDLess.log.info('Using imgcat for image rendering')
821
832
  elsif exec_available('chafa')
822
- @log.info('Using chafa for image rendering')
833
+ MDLess.log.info('Using chafa for image rendering')
823
834
  end
824
835
  img_path = link
825
- if img_path =~ /^http/ && @options[:remote_images]
836
+ if img_path =~ /^http/ && MDLess.options[:remote_images]
826
837
  if exec_available('imgcat')
827
- @log.info('Using imgcat for image rendering')
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
- @log.error(e)
848
+ MDLess.log.error(e)
838
849
  end
839
850
  elsif exec_available('chafa')
840
- @log.info('Using chafa for image rendering')
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
- @log.warn('No viewer for remote images')
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 @file
862
- base = File.expand_path(File.dirname(@file))
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 @options[:wiki_links]
965
+ input = highlight_wiki_links(input) if MDLess.options[:wiki_links]
955
966
 
956
- if @options[:inline_footnotes]
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 @options[:links] == :reference || @options[:links] == :paragraph
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 @options[:local_images]
977
- input = highlight_tags(input) if @options[:at_tags] || @options[:taskpaper]
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