mdless 2.1.35 → 2.1.36

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: da85e4e5c08df785aec51ae04a636e77f173440b2f28a1cc87625a67914274bc
4
- data.tar.gz: c8479318f320a7be17eca74adaf65a117e9bfd5e1f70ae3e262d8ebf9f29061e
3
+ metadata.gz: 99d20a886a23bd77ae38be29d68c25ed6673fe32815ac8c06f621cf7fd101b27
4
+ data.tar.gz: a87049e15d202db34aff6960212561cb9026a3a6627d73a532d700495de070fe
5
5
  SHA512:
6
- metadata.gz: cada4d6a9d10665cb027a3120e8e83023a51ab51f868724a644db8da52b27418d30312d200ce466e50b4f7dbc5b5168aa6802fb445afabfd76ee57bb8b494842
7
- data.tar.gz: 2b99883ec4a395be78c2a621de0aca45c52e63bef9004ef056d82e682d6b6c21b66fe7cf3ef1f4b89c9aa1af8346236323f12b5271993695707358ea94ec098a
6
+ metadata.gz: 047faebf6bc49ed8c56916b36a9b0428c0af508ae956ea76f0547792a744b7e3be80726d1c4435542b5b9fbc7a2b8339b22614bffe2ebb2042e861cd28b636e2
7
+ data.tar.gz: 41c7e129de92b8cc7852aaa71ab61bca9964066a5aee1b1b196d77c6a0b23429960ca1203180a7a540a3253e387b59023e140186da36f874eed0f8eaa1020aad
data/CHANGELOG.md CHANGED
@@ -1,7 +1,3 @@
1
- 2.1.26
2
-
3
- 2.1.32
4
-
5
1
  2.1.35
6
2
  : Ruby 2.7 error (again)
7
3
 
@@ -38,6 +34,7 @@
38
34
  : TaskPaper file with metadata causing negative argument error
39
35
  : Remove `<br>` from metadata
40
36
  : YAML metadata and negative line lengths
37
+ >>>>>>> release/2.1.30
41
38
 
42
39
  2.1.14
43
40
  : Spaces on a line separating metadata won't break display
@@ -828,10 +828,15 @@ module Redcarpet
828
828
  end
829
829
  end
830
830
 
831
+ def fix_image_attributes(input)
832
+ input.gsub(/^( {0,3}\[.*?\]: *\S+) +([^"].*?)$/, '\1')
833
+ end
834
+
831
835
  def preprocess(input)
832
836
  input = color_meta(input)
833
837
  input = mmd_transclude(input) if MDLess.options[:transclude]
834
838
  input = mmd_metadata_replace(input) if MDLess.options[:mmd_metadata]
839
+ input = fix_image_attributes(input)
835
840
 
836
841
  replaced_input = input.clone
837
842
  ## Replace setex headers with ATX
@@ -280,7 +280,6 @@ module CLIMarkdown
280
280
  end
281
281
 
282
282
  @output = ''
283
- @headers = []
284
283
  @setheaders = []
285
284
 
286
285
  input = ''
@@ -304,13 +303,14 @@ module CLIMarkdown
304
303
  tables: true,
305
304
  underline: false)
306
305
 
307
- spinner = TTY::Spinner.new("[:spinner] Processing ...", format: :dots_3, clear: true)
308
-
309
306
  if !args.empty?
310
307
  files = args.delete_if { |f| !File.exist?(f) }
308
+ @multifile = files.count > 1
311
309
  files.each do |file|
310
+ spinner = TTY::Spinner.new("[:spinner] Processing #{File.basename(file)}...", format: :dots_3, clear: true)
312
311
  spinner.run do |spinner|
313
312
  MDLess.log.info(%(Processing "#{file}"))
313
+ @output << "#{c(%i[b green])}[#{c(%i[b white])}#{file}#{c(%i[b green])}]#{xc}\n\n" if @multifile
314
314
  MDLess.file = file
315
315
 
316
316
  begin
@@ -322,7 +322,7 @@ module CLIMarkdown
322
322
 
323
323
  input.scrub!
324
324
  input.gsub!(/\r?\n/, "\n")
325
-
325
+ @headers = headers(input)
326
326
  if MDLess.options[:taskpaper] == :auto
327
327
  MDLess.options[:taskpaper] = if CLIMarkdown::TaskPaper.is_taskpaper?(input)
328
328
  MDLess.log.info('TaskPaper detected')
@@ -333,26 +333,26 @@ module CLIMarkdown
333
333
  end
334
334
 
335
335
  if MDLess.options[:list]
336
- if MDLess.options[:taskpaper]
337
- puts CLIMarkdown::TaskPaper.list_projects(input)
338
- else
339
- puts list_headers(input)
340
- end
341
- Process.exit 0
336
+ @output << if MDLess.options[:taskpaper]
337
+ CLIMarkdown::TaskPaper.list_projects(input)
338
+ else
339
+ list_headers(input)
340
+ end
341
+ elsif MDLess.options[:taskpaper]
342
+ input = input.color_meta(MDLess.cols)
343
+ input = CLIMarkdown::TaskPaper.highlight(input)
344
+ @output << input.highlight_tags
342
345
  else
343
- if MDLess.options[:taskpaper]
344
- input = input.color_meta(MDLess.cols)
345
- input = CLIMarkdown::TaskPaper.highlight(input)
346
- @output = input.highlight_tags
347
- else
348
- @output = markdown.render(input)
349
- end
346
+ @output << markdown.render(input)
350
347
  end
348
+ @output << "\n\n"
351
349
  end
352
350
  end
351
+
353
352
  printout
354
353
  elsif !$stdin.isatty
355
354
  MDLess.log.info(%(Processing STDIN))
355
+ spinner = TTY::Spinner.new("[:spinner] Processing ...", format: :dots_3, clear: true)
356
356
  spinner.run do |spinner|
357
357
  MDLess.file = nil
358
358
  input = $stdin.read.scrub
@@ -366,6 +366,7 @@ module CLIMarkdown
366
366
  false
367
367
  end
368
368
  end
369
+ @headers = headers(input)
369
370
 
370
371
  if MDLess.options[:list]
371
372
  if MDLess.options[:taskpaper]
@@ -417,34 +418,32 @@ module CLIMarkdown
417
418
  end
418
419
  end
419
420
 
420
- def get_headers(string)
421
- unless @headers && !@headers.empty?
422
- @headers = []
423
- input = string.sub(/(?i-m)^---[ \t]*\n([\s\S]*?)\n[-.]{3}[ \t]*\n/m, '')
424
- headers = input.scan(/^((?!#!)(\#{1,6})\s*([^#]+?)(?: #+)?\s*|(\S.+)\n([=-]+))$/i)
425
-
426
- headers.each do |h|
427
- hlevel = 6
428
- title = nil
429
- if h[4] =~ /=+/
430
- hlevel = 1
431
- title = h[3]
432
- elsif h[4] =~ /-+/
433
- hlevel = 2
434
- title = h[3]
435
- else
436
- hlevel = h[1].length
437
- title = h[2]
438
- end
439
- @headers << [
440
- '#' * hlevel,
441
- title,
442
- h[0]
443
- ]
444
- end
421
+ def headers(string)
422
+ hs = []
423
+ input = string.remove_meta
424
+ doc_headers = input.scan(/^((?!#!)(\#{1,6})\s*([^#]+?)(?: #+)?\s*|(\S.+)\n([=-]+))$/i)
425
+
426
+ doc_headers.each do |h|
427
+ hlevel = 6
428
+ title = nil
429
+ if h[4] =~ /=+/
430
+ hlevel = 1
431
+ title = h[3]
432
+ elsif h[4] =~ /-+/
433
+ hlevel = 2
434
+ title = h[3]
435
+ else
436
+ hlevel = h[1].length
437
+ title = h[2]
438
+ end
439
+ hs << [
440
+ '#' * hlevel,
441
+ title,
442
+ h[0]
443
+ ]
445
444
  end
446
445
 
447
- @headers
446
+ hs
448
447
  end
449
448
 
450
449
  def list_headers(input)
@@ -455,7 +454,6 @@ module CLIMarkdown
455
454
  new_level.positive? ? '#' * new_level : ''
456
455
  end
457
456
 
458
- @headers = get_headers(input)
459
457
  last_level = 0
460
458
  headers_out = []
461
459
  len = (@headers.count + 1).to_s.length
@@ -479,16 +477,16 @@ module CLIMarkdown
479
477
  else
480
478
  ' '
481
479
  end
482
- headers_out.push format("%<d>#{len}d: %<s>s",
480
+ headers_out.push format("%<c>s%<d>#{len}d: %<s>s",
481
+ c: c(%i[magenta]),
483
482
  d: idx + 1,
484
483
  s: "#{c(%i[x black])}#{'.' * level}#{c(%i[x yellow])}#{subdoc}#{title.strip}#{xc}")
485
484
  end
486
485
 
487
- headers_out.join("\n")
486
+ headers_out.join("\n#{xc}")
488
487
  end
489
488
 
490
489
  def highest_header(input)
491
- @headers = get_headers(input)
492
490
  top = 6
493
491
  @headers.each { |h| top = h[0].length if h[0].length < top }
494
492
  top
@@ -564,7 +562,7 @@ module CLIMarkdown
564
562
  IO.select [input]
565
563
 
566
564
  pager = which_pager
567
- MDLess.log.info("Using #{pager} as pager")
565
+ MDLess.log.info("Using `#{pager.join(' ')}` as pager")
568
566
  begin
569
567
  exec(pager.join(' '))
570
568
  rescue SystemCallError => e
@@ -614,7 +612,7 @@ module CLIMarkdown
614
612
 
615
613
  def which_pager
616
614
  # pagers = [ENV['PAGER'], ENV['GIT_PAGER']]
617
- pagers = [ENV['PAGER']]
615
+ pagers = ENV['PAGER'] ? [ENV['PAGER']] : []
618
616
 
619
617
  # if exec_available('git')
620
618
  # git_pager = `git config --get-all core.pager || true`.split.first
@@ -623,29 +621,28 @@ module CLIMarkdown
623
621
 
624
622
  pagers.concat(['less', 'more', 'cat', 'pager'])
625
623
 
624
+ pagers.delete_if { |pg| !TTY::Which.exist?(pg) }
625
+
626
626
  pagers.select! do |f|
627
- if f
628
- if f.strip =~ /[ |]/
629
- f
630
- elsif f == 'most'
631
- MDLess.log.warn('most not allowed as pager')
632
- false
633
- else
634
- system "which #{f}", out: File::NULL, err: File::NULL
635
- end
636
- else
627
+ pg = f.split(/[ ]/)[0]
628
+ return false unless pg
629
+
630
+ if pg == 'most'
631
+ MDLess.log.warn('most not allowed as pager')
637
632
  false
633
+ else
634
+ TTY::Which.which(pg)
638
635
  end
639
636
  end
640
637
 
641
638
  pg = pagers.first
642
639
  args = case pg
643
640
  # when 'delta'
644
- # ' --pager="less -Xr"'
641
+ # ' --pager="less -FXr"'
645
642
  when 'less'
646
- ' -Xr'
643
+ '-FXr'
647
644
  # when 'bat'
648
- # ' -p --pager="less -Xr"'
645
+ # ' -p --pager="less -FXr"'
649
646
  else
650
647
  ''
651
648
  end
@@ -654,10 +651,10 @@ module CLIMarkdown
654
651
  end
655
652
 
656
653
  def exec_available(cli)
657
- if File.exist?(File.expand_path(cli))
658
- File.executable?(File.expand_path(cli))
654
+ if TTY::Which.exist?(cli)
655
+ TTY::Which.which(cli)
659
656
  else
660
- system "which #{cli}", out: File::NULL, err: File::NULL
657
+ false
661
658
  end
662
659
  end
663
660
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CLIMarkdown
4
- VERSION = '2.1.35'
4
+ VERSION = '2.1.36'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdless
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.35
4
+ version: 2.1.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra