mdless 2.1.33 → 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: 28e57a0026d9d1c04661fa866f6e66ad2c657d27651882a740b23c1966b28313
4
- data.tar.gz: 3674e77fab13e7d0f8a80a4293c316579691cf4e4c3eef57863c61a677e31753
3
+ metadata.gz: 99d20a886a23bd77ae38be29d68c25ed6673fe32815ac8c06f621cf7fd101b27
4
+ data.tar.gz: a87049e15d202db34aff6960212561cb9026a3a6627d73a532d700495de070fe
5
5
  SHA512:
6
- metadata.gz: eda195225bc5efc055263da9e1f5b329d8342cb5441c91e04da42b24996047a4fbb0a179657d8b654e2646f945e9887948f78fd4f04dc2faa9b39f8187a2f132
7
- data.tar.gz: 7c63899a2e3510d4c568be1b67c39cd3d3449250bece779c296e37ea0c1b1c49d255e90056ae139206c1b5a0e252ab1a8dd1bb5d3f0d0ffae521e4e1e51cf585
6
+ metadata.gz: 047faebf6bc49ed8c56916b36a9b0428c0af508ae956ea76f0547792a744b7e3be80726d1c4435542b5b9fbc7a2b8339b22614bffe2ebb2042e861cd28b636e2
7
+ data.tar.gz: 41c7e129de92b8cc7852aaa71ab61bca9964066a5aee1b1b196d77c6a0b23429960ca1203180a7a540a3253e387b59023e140186da36f874eed0f8eaa1020aad
data/CHANGELOG.md CHANGED
@@ -1,6 +1,7 @@
1
- 2.1.33
1
+ 2.1.35
2
+ : Ruby 2.7 error (again)
2
3
 
3
- 2.1.32
4
+ 2.1.30
4
5
  : Error when $EDITOR is not defined
5
6
 
6
7
  2.1.29
data/README.md CHANGED
@@ -264,4 +264,11 @@ end
264
264
 
265
265
  Note that if you do this, and you need uncolored output to pipe somewhere, you'll need to use `command cat FILE` to revert to the built-in `cat`. Otherwise your text will be full of the escape codes that `mdless` uses to colorize the output.
266
266
 
267
+ ## Similar Projects
268
+
269
+ There are a few great options for Markdown viewing in the Terminal. If `mdless` doesn't do it for you, check out:
270
+
271
+ - [Glow](https://github.com/charmbracelet/glow)
272
+ - [Frogmouth](https://github.com/Textualize/frogmouth)
273
+
267
274
  <!--END README-->
@@ -753,7 +753,7 @@ module Redcarpet
753
753
  m = Regexp.last_match
754
754
  MDLess.log.info('Processing YAML header')
755
755
  begin
756
- MDLess.meta = YAML.load(m['content']).map { |k, v| "#{k.downcase}" => v }
756
+ MDLess.meta = YAML.load(m['content']).each_with_object({}) { |(k, v), h| h[k.downcase] = v }
757
757
  rescue Psych::DisallowedClass => e
758
758
  @log.error('Error reading YAML header')
759
759
  @log.error(e)
@@ -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.33'
4
+ VERSION = '2.1.36'
5
5
  end
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: 2.1.33
4
+ version: 2.1.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-15 00:00:00.000000000 Z
11
+ date: 2023-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  requirements: []
161
- rubygems_version: 3.4.0.dev
161
+ rubygems_version: 3.2.16
162
162
  signing_key:
163
163
  specification_version: 4
164
164
  summary: A pager like less, but for Markdown files