mdless 2.0.7 → 2.0.8

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: 40b4de5e5f68bf91800f9f7448a8b3620c5f194b2966b786fe4621cd3ccc7ccc
4
- data.tar.gz: ee00c4e594a1c2b6d3526e6c5e1c6a0143c2ad9800577b31e8f73f558df99500
3
+ metadata.gz: ef90f38be64fdcd4e3666782b957ac2a27ec4346103fa79a1760626977051a8f
4
+ data.tar.gz: 856113d17ab7217c28de2f2c2405acd185e99cdc4ca0370fbb73053371babab1
5
5
  SHA512:
6
- metadata.gz: d4ba05b198c6ad16caeab6e0875fc3ef1b86181099e23a8cabf04063f73f4b6f22c2376d6f394c57165c76f7476c784e527918ea6213b978e413de8be4bb0943
7
- data.tar.gz: 76eb9fc848d10f82e557cfe880204252719c5d3aad9d5e6cee70c44c25a6d10ad1fce5493b025a97dc7fd1ddf127a10ff7fc2fd6b04e9bd400dd7f720467b9e4
6
+ metadata.gz: f291d6eef35c904afc13adecc673db8736b002e556fc55f311cae6721685868f709cc285cf2a2906657933a05f385ce5168190e8672f16a672b8dd41f3bb7d1c
7
+ data.tar.gz: 75c67e0498a10ff7c26d2b9f9d43808174826807369650b33918ba0b63342cfaf1ae359530f957db2b9c403026918783d3411a291f92b732e6a2921efccd15b0
@@ -349,9 +349,9 @@ module Redcarpet
349
349
  end
350
350
  elsif exec_available('chafa')
351
351
  @log.info('Using chafa for image rendering')
352
- term = '-f sixels'
353
- term = ENV['TERMINAL_PROGRAM'] =~ /iterm/i ? '-f iterm' : term
354
- term = ENV['TERMINAL_PROGRAM'] =~ /kitty/i ? '-f kitty' : term
352
+ term = ''
353
+ term = ENV['TERM_PROGRAM'] =~ /iterm/i ? '-f iterm' : term
354
+ term = ENV['TERM_PROGRAM'] =~ /kitty/i ? '-f kitty' : term
355
355
  FileUtils.rm_r '.mdless_tmp', force: true if File.directory?('.mdless_tmp')
356
356
  Dir.mkdir('.mdless_tmp')
357
357
  Dir.chdir('.mdless_tmp')
@@ -377,11 +377,13 @@ module Redcarpet
377
377
  pre = !alt_text.nil? ? " #{c(%i[d blue])}[#{alt_text.strip}]\n" : ''
378
378
  post = !title.nil? ? "\n #{c(%i[b blue])}-- #{title} --" : ''
379
379
  if exec_available('imgcat')
380
- img = `imgcat "#{img_path}"`
380
+ img = `imgcat -p "#{img_path}"`
381
+ @log.info("Rendering image with `imgcat -p #{img_path}`")
381
382
  elsif exec_available('chafa')
382
- term = '-f sixels'
383
- term = ENV['TERMINAL_PROGRAM'] =~ /iterm/i ? '-f iterm' : term
384
- term = ENV['TERMINAL_PROGRAM'] =~ /kitty/i ? '-f kitty' : term
383
+ term = ''
384
+ term = ENV['TERM_PROGRAM'] =~ /iterm/i ? '-f iterm' : term
385
+ term = ENV['TERM_PROGRAM'] =~ /kitty/i ? '-f kitty' : term
386
+ @log.info("Rendering image with `chafa #{term} #{img_path}`")
385
387
  img = `chafa #{term} "#{img_path}"`
386
388
  end
387
389
  result = pre + img + post
@@ -572,7 +574,8 @@ module Redcarpet
572
574
 
573
575
  def preprocess(input)
574
576
  in_yaml = false
575
- if input.split("\n")[0] =~ /(?i-m)^---[ \t]*?(\n|$)/
577
+ first_line = input.split("\n").first
578
+ if first_line =~ /(?i-m)^---[ \t]*?$/
576
579
  @log.info('Found YAML')
577
580
  # YAML
578
581
  in_yaml = true
@@ -596,10 +599,12 @@ module Redcarpet
596
599
  end
597
600
  end
598
601
 
599
- if !in_yaml && input.gsub(/\n/, ' ') =~ /(?i-m)^[\w ]+:\s+\S+/
602
+ if !in_yaml && first_line =~ /(?i-m)^[\w ]+:\s+\S+/
600
603
  @log.info('Found MMD Headers')
601
604
  input.sub!(/(?i-m)^([\S ]+:[\s\S]*?)+(?=\n\n)/) do |mmd|
602
605
  lines = mmd.split(/\n/)
606
+ return mmd if lines.count > 20
607
+
603
608
  longest = lines.inject { |memo, word| memo.length > word.length ? memo : word }.length
604
609
  longest = longest < @cols ? longest + 1 : @cols
605
610
  lines.map do |line|
@@ -47,11 +47,15 @@ module CLIMarkdown
47
47
  opts.on('-i', '--images=TYPE',
48
48
  'Include [local|remote (both)] images in output (requires chafa or imgcat, default NONE).') do |type|
49
49
  if exec_available('imgcat') || exec_available('chafa')
50
- if type =~ /^(r|b|a)/i
50
+ case type
51
+ when /^(r|b|a)/i
51
52
  @options[:local_images] = true
52
53
  @options[:remote_images] = true
53
- elsif type =~ /^l/i
54
+ when /^l/i
54
55
  @options[:local_images] = true
56
+ when /^n/
57
+ @options[:local_images] = false
58
+ @options[:remote_images] = false
55
59
  end
56
60
  else
57
61
  @log.warn('images turned on but imgcat/chafa not found')
@@ -1,3 +1,3 @@
1
1
  module CLIMarkdown
2
- VERSION = '2.0.7'
2
+ VERSION = '2.0.8'
3
3
  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.0.7
4
+ version: 2.0.8
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-11-23 00:00:00.000000000 Z
11
+ date: 2023-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet