mdless 2.0.6 → 2.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2153423a3c896ca8522fd330478ce3125fd68a2bcc6a8a4c52b0efea31033484
4
- data.tar.gz: 4b039579d2315650038408b954d00689929530c322441aacca52c13e77f4065f
3
+ metadata.gz: ef90f38be64fdcd4e3666782b957ac2a27ec4346103fa79a1760626977051a8f
4
+ data.tar.gz: 856113d17ab7217c28de2f2c2405acd185e99cdc4ca0370fbb73053371babab1
5
5
  SHA512:
6
- metadata.gz: 40fbf0a45ede5519964948b6fc83b1f2f7dd6beea06f2faec2be9b8606d1bfe8d1f176597e49a318a205cae66b1ad855afc0951ec29f0e39f6f662d34535c816
7
- data.tar.gz: c2adc031a649dfbc3cfd4254df7acfb990f2b86a31bea7f4d58405a7c2853122431b5057dfe5cd225b6510e206a45b2b999f10a372f00e6128b74cce66cf6978
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.6'
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.6
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