Skip to content

Commit

Permalink
remove pager output
Browse files Browse the repository at this point in the history
- FIXED: errant pager output
  • Loading branch information
ttscoff committed Aug 2, 2022
1 parent a3fcfd4 commit 2c8e4f8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
53 changes: 27 additions & 26 deletions lib/mdless/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,8 @@ def convert_markdown(input)
end

# misc html
line.gsub!(/<br\/?>/, "\n")
line.gsub!(/(?i-m)((<\/?)(\w+[\s\S]*?)(>))/) do |tag|
line.gsub!(%r{<br/?>}, "\n")
line.gsub!(%r{(?i-m)((</?)(\w+[\s\S]*?)(>))}) do
match = Regexp.last_match
last = find_color(match.pre_match)
[
Expand All @@ -822,12 +822,12 @@ def convert_markdown(input)
match[3],
color('html brackets'),
match[4],
last ? last : xc
last || xc
].join
end

# inline code spans
line.gsub!(/`(.*?)`/) do |m|
line.gsub!(/`(.*?)`/) do
match = Regexp.last_match
last = find_color(match.pre_match, true)
[
Expand All @@ -837,7 +837,7 @@ def convert_markdown(input)
match[1],
color('code_span marker'),
'`',
last ? last : xc
last || xc
].join
end
end
Expand All @@ -853,7 +853,7 @@ def convert_markdown(input)
input = lines.join("\n")

# images
input.gsub!(/^(.*?)!\[(.*)?\]\((.*?\.(?:png|gif|jpg))( +.*)?\)/) do |m|
input.gsub!(/^(.*?)!\[(.*)?\]\((.*?\.(?:png|gif|jpg))( +.*)?\)/) do
match = Regexp.last_match
if match[1].uncolor =~ /^( {4,}|\t)+/
match[0]
Expand Down Expand Up @@ -893,23 +893,23 @@ def convert_markdown(input)
@log.error(e)
end
else
@log.warn("No viewer for remote images")
@log.warn('No viewer for remote images')
end
end
else
if img_path =~ /^[~\/]/
if img_path =~ %r{^[~/]}
img_path = File.expand_path(img_path)
elsif @file
base = File.expand_path(File.dirname(@file))
img_path = File.join(base,img_path)
img_path = File.join(base, img_path)
end
if File.exists?(img_path)
pre = match[2].size > 0 ? " #{c(%i[d blue])}[#{match[2].strip}]\n" : ''
post = tail.size > 0 ? "\n #{c(%i[b blue])}-- #{tail} --" : ''
if File.exist?(img_path)
pre = !match[2].empty? ? " #{c(%i[d blue])}[#{match[2].strip}]\n" : ''
post = !tail.empty? ? "\n #{c(%i[b blue])}-- #{tail} --" : ''
if exec_available('chafa')
img = %x{chafa "#{img_path}"}
img = `chafa "#{img_path}"`
elsif exec_available('imgcat')
img = %x{imgcat "#{img_path}"}
img = `imgcat "#{img_path}"`
end
result = pre + img + post
end
Expand All @@ -924,32 +924,31 @@ def convert_markdown(input)
end
end

@footnotes.each {|t, v|
@footnotes.each do |t, v|
input += [
"\n\n",
color('footnote brackets'),
"[",
'[',
color('footnote caret'),
"^",
'^',
color('footnote title'),
t,
color('footnote brackets'),
"]: ",
']: ',
color('footnote note'),
v,
xc
].join
}
end

@output += input

end

def exec_available(cli)
if File.exists?(File.expand_path(cli))
if File.exist?(File.expand_path(cli))
File.executable?(File.expand_path(cli))
else
system "which #{cli}", :out => File::NULL, :err => File::NULL
system "which #{cli}", out: File::NULL, err: File::NULL
end
end

Expand All @@ -967,7 +966,7 @@ def page(text, &callback)
IO.select [input]

pager = which_pager
@log.info(%{Using #{pager} as pager})
@log.info("Using #{pager} as pager")
begin
exec(pager.join(' '))
rescue SystemCallError => e
Expand All @@ -980,7 +979,7 @@ def page(text, &callback)
read_io.close
write_io.write(text)
write_io.close
rescue SystemCallError => e
rescue SystemCallError
exit 1
end

Expand Down Expand Up @@ -1010,12 +1009,12 @@ def printout
if @options[:pager]
page(out)
else
$stdout.puts (out)
$stdout.print (out.rstrip)
end
end

def which_pager
pagers = [ENV['GIT_PAGER'], ENV['PAGER']]
pagers = [ENV['PAGER'], ENV['GIT_PAGER']]

if exec_available('git')
git_pager = `git config --get-all core.pager || true`.split.first
Expand All @@ -1041,6 +1040,8 @@ def which_pager

pg = pagers.first
args = case pg
when 'delta'
' --pager="less -Xr"'
when 'more'
' -r'
when 'less'
Expand Down
2 changes: 1 addition & 1 deletion lib/mdless/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module CLIMarkdown
VERSION = '1.0.27'
VERSION = '1.0.29'
end

0 comments on commit 2c8e4f8

Please sign in to comment.