diff --git a/lib/mdless/console.rb b/lib/mdless/console.rb index eb5138c..5be2d70 100644 --- a/lib/mdless/console.rb +++ b/lib/mdless/console.rb @@ -349,9 +349,9 @@ def image(link, title, alt_text) end elsif exec_available('chafa') @log.info('Using chafa for image rendering') - term = '-f sixels' - term = ENV['TERMINAL_PROGRAM'] =~ /iterm/i ? '-f iterm' : term - term = ENV['TERMINAL_PROGRAM'] =~ /kitty/i ? '-f kitty' : term + term = '' + term = ENV['TERM_PROGRAM'] =~ /iterm/i ? '-f iterm' : term + term = ENV['TERM_PROGRAM'] =~ /kitty/i ? '-f kitty' : term FileUtils.rm_r '.mdless_tmp', force: true if File.directory?('.mdless_tmp') Dir.mkdir('.mdless_tmp') Dir.chdir('.mdless_tmp') @@ -377,11 +377,13 @@ def image(link, title, alt_text) pre = !alt_text.nil? ? " #{c(%i[d blue])}[#{alt_text.strip}]\n" : '' post = !title.nil? ? "\n #{c(%i[b blue])}-- #{title} --" : '' if exec_available('imgcat') - img = `imgcat "#{img_path}"` + img = `imgcat -p "#{img_path}"` + @log.info("Rendering image with `imgcat -p #{img_path}`") elsif exec_available('chafa') - term = '-f sixels' - term = ENV['TERMINAL_PROGRAM'] =~ /iterm/i ? '-f iterm' : term - term = ENV['TERMINAL_PROGRAM'] =~ /kitty/i ? '-f kitty' : term + term = '' + term = ENV['TERM_PROGRAM'] =~ /iterm/i ? '-f iterm' : term + term = ENV['TERM_PROGRAM'] =~ /kitty/i ? '-f kitty' : term + @log.info("Rendering image with `chafa #{term} #{img_path}`") img = `chafa #{term} "#{img_path}"` end result = pre + img + post @@ -572,7 +574,8 @@ def get_headers(input) def preprocess(input) in_yaml = false - if input.split("\n")[0] =~ /(?i-m)^---[ \t]*?(\n|$)/ + first_line = input.split("\n").first + if first_line =~ /(?i-m)^---[ \t]*?$/ @log.info('Found YAML') # YAML in_yaml = true @@ -596,7 +599,6 @@ def preprocess(input) end end - first_line = input.split("\n").first if !in_yaml && first_line =~ /(?i-m)^[\w ]+:\s+\S+/ @log.info('Found MMD Headers') input.sub!(/(?i-m)^([\S ]+:[\s\S]*?)+(?=\n\n)/) do |mmd| diff --git a/lib/mdless/converter.rb b/lib/mdless/converter.rb index e4f2c7a..46fd5ae 100644 --- a/lib/mdless/converter.rb +++ b/lib/mdless/converter.rb @@ -47,11 +47,15 @@ def initialize(args) opts.on('-i', '--images=TYPE', 'Include [local|remote (both)] images in output (requires chafa or imgcat, default NONE).') do |type| if exec_available('imgcat') || exec_available('chafa') - if type =~ /^(r|b|a)/i + case type + when /^(r|b|a)/i @options[:local_images] = true @options[:remote_images] = true - elsif type =~ /^l/i + when /^l/i @options[:local_images] = true + when /^n/ + @options[:local_images] = false + @options[:remote_images] = false end else @log.warn('images turned on but imgcat/chafa not found')