Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nagative aurument in converter.rb:417 #12

Closed
fish1928 opened this issue Aug 30, 2017 · 9 comments
Closed

nagative aurument in converter.rb:417 #12

fish1928 opened this issue Aug 30, 2017 · 9 comments

Comments

@fish1928
Copy link

jinyuj-m01:cloudml-dist-mnist-example jinyuj$ mdless /Users/jinyuj/Workspace/tensorflow/cloudml-dist-mnist-example/README.md
/Users/jinyuj/.rvm/gems/ruby-2.3.0/gems/mdless-0.0.9/lib/mdless/converter.rb:417:in *': negative argument (ArgumentError) from /Users/jinyuj/.rvm/gems/ruby-2.3.0/gems/mdless-0.0.9/lib/mdless/converter.rb:417:in block (2 levels) in convert_markdown'
from /Users/jinyuj/.rvm/gems/ruby-2.3.0/gems/mdless-0.0.9/lib/mdless/converter.rb:413:in map' from /Users/jinyuj/.rvm/gems/ruby-2.3.0/gems/mdless-0.0.9/lib/mdless/converter.rb:413:in block in convert_markdown'
from /Users/jinyuj/.rvm/gems/ruby-2.3.0/gems/mdless-0.0.9/lib/mdless/converter.rb:393:in gsub!' from /Users/jinyuj/.rvm/gems/ruby-2.3.0/gems/mdless-0.0.9/lib/mdless/converter.rb:393:in convert_markdown'
from /Users/jinyuj/.rvm/gems/ruby-2.3.0/gems/mdless-0.0.9/lib/mdless/converter.rb:117:in block in initialize' from /Users/jinyuj/.rvm/gems/ruby-2.3.0/gems/mdless-0.0.9/lib/mdless/converter.rb:105:in each'
from /Users/jinyuj/.rvm/gems/ruby-2.3.0/gems/mdless-0.0.9/lib/mdless/converter.rb:105:in initialize' from /Users/jinyuj/.rvm/gems/ruby-2.3.0/gems/mdless-0.0.9/bin/mdless:17:in new'
from /Users/jinyuj/.rvm/gems/ruby-2.3.0/gems/mdless-0.0.9/bin/mdless:17:in <top (required)>' from /Users/jinyuj/.rvm/gems/ruby-2.3.0/bin/mdless:23:in load'
from /Users/jinyuj/.rvm/gems/ruby-2.3.0/bin/mdless:23:in <main>' from /Users/jinyuj/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in eval'
from /Users/jinyuj/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `

'

So, the problem is that in line 417, the code use a nagative number * a string, commonly, "ha"*3 means we will get "hahaha" as the result. But if the number is a nagetive number, there will be an error of it. The problem is that in line 417, the (@cols - orig_length) get an nagetive number when I am using this. please help to figure this out : )
README.md.txt

@treefrogman
Copy link

I get this too, @fish1928. I can reproduce the error with your README.md file. The line has moved to 428 at this point, but the error is the same. I can make it run successfully (though not good looking because of wrapping lines) with mdless -w 244 README.md. This sets the width to 244, the minimum width for your file.

This file (README-gson.md.txt) requires a minimum screen width of 75.

@ttscoff
Copy link
Owner

ttscoff commented Feb 27, 2018

I need more info on this. Both test files listed are working for me at any width screen.

  1. Are you using mdless 0.10?
  2. What's your $TERM (echo $TERM)
  3. What's your $COLUMNS (echo $COLUMNS)
  4. Can you post the most recent error output you're seeing?

@ttscoff
Copy link
Owner

ttscoff commented Feb 27, 2018

Also, if the error is on line 428, I'm assuming you don't have pygments (pygmentize) installed?

@treefrogman
Copy link

Not as a solution (because it truncates every line), but as insight into the problem: while read line; do echo -e "$(echo $line | head -c $(($(tput cols) - 3)))"; done < README.md | mdless should never throw that error, and indeed in my testing does not.

Essentially it takes the screen width, subtracts 3, and truncates every line to that length before piping the output to mdless.

Why does this prevent the error? Codeblocks (lines between pairs of ​```​) don't wrap, and if any lines inside the codeblock are longer than the screen width minus three, the error is thrown. This is not an issue for code snippets (text between pairs of ​`​), as these are not supported by mdless, and if properly supported should wrap anyway.

Codeblocks are a special challenge in mdless because they're not supposed to wrap nor truncate, but scroll horizontally. Does less support horizontal scrolling? Or even separate scrolling panels?

@ernstki
Copy link

ernstki commented Mar 1, 2018

Immediately upon installing mdless 0.0.10, I got this error, but only when I attempted to use the -w option:

$ mdless --width=80 README.md
/Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/lib/mdless/converter.rb:428:in `*': negative argument (ArgumentError)
	from /Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/lib/mdless/converter.rb:428:in `block (2 levels) in convert_markdown'
	from /Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/lib/mdless/converter.rb:424:in `map'
	from /Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/lib/mdless/converter.rb:424:in `block in convert_markdown'
	from /Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/lib/mdless/converter.rb:404:in `gsub!'
	from /Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/lib/mdless/converter.rb:404:in `convert_markdown'
	from /Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/lib/mdless/converter.rb:118:in `block in initialize'
	from /Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/lib/mdless/converter.rb:106:in `each'
	from /Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/lib/mdless/converter.rb:106:in `initialize'
	from /Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/bin/mdless:17:in `new'
	from /Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/bin/mdless:17:in `<top (required)>'
	from /Users/username/.gem/ruby/2.3.0/bin/mdless:23:in `load'
	from /Users/username/.gem/ruby/2.3.0/bin/mdless:23:in `<main>'

@ttscoff I can confirm that gem install --user pygmentize fixed this problem for me. Perhaps that should be a hard dependency for the gem? The README.md was the one from the saxon-lint project, if that helps in any way.

Version / terminal config

$ mdless --version; ruby --version; echo -e "TERM=$TERM\nCOLUMNS=$COLUMNS";
mdless 0.0.10
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
TERM=xterm-256color
COLUMNS=123

@eliten00b
Copy link
Contributor

eliten00b commented May 16, 2018

I got a workaround by modifying that line:

"#{c([:x,:black])}~ #{c([:x,:white,:on_black])} " + new_code_line + c([:x,:white,:on_black]) + " "*(@cols - orig_length) + xc

to

"#{c([:x,:black])}~ #{c([:x,:white,:on_black])} " + new_code_line + c([:x,:white,:on_black]) + xc

I think it is not necessary to fill each line with spaces.

@akhoury6
Copy link

I'm having the same issue, and can confirm that the above workaround works for me.

@ackratos
Copy link

ackratos commented Oct 7, 2018

I got a workaround by modifying that line:

"#{c([:x,:black])}~ #{c([:x,:white,:on_black])} " + new_code_line + c([:x,:white,:on_black]) + " "*(@cols - orig_length) + xc

to

"#{c([:x,:black])}~ #{c([:x,:white,:on_black])} " + new_code_line + c([:x,:white,:on_black]) + xc

I think it is not necessary to fill each line with spaces.

works for me as well. thanks a lot!

@digininja
Copy link

It is still there, I can reproduce it by putting a string of 253 characters into a code block. Anything up to 253 works fine, the 253rd character tips it over.

Traceback (most recent call last):
        15: from /home/robin/.rvm/gems/ruby-2.5.3/bin/ruby_executable_hooks:24:in `<main>'
        14: from /home/robin/.rvm/gems/ruby-2.5.3/bin/ruby_executable_hooks:24:in `eval'
        13: from /home/robin/.rvm/gems/ruby-2.5.3/bin/mdless:23:in `<main>'
        12: from /home/robin/.rvm/gems/ruby-2.5.3/bin/mdless:23:in `load'
        11: from /home/robin/.rvm/gems/ruby-2.5.3/gems/mdless-0.0.10/bin/mdless:17:in `<top (required)>'
        10: from /home/robin/.rvm/gems/ruby-2.5.3/gems/mdless-0.0.10/bin/mdless:17:in `new'
         9: from /home/robin/.rvm/gems/ruby-2.5.3/gems/mdless-0.0.10/lib/mdless/converter.rb:106:in `initialize'
         8: from /home/robin/.rvm/gems/ruby-2.5.3/gems/mdless-0.0.10/lib/mdless/converter.rb:106:in `each'
         7: from /home/robin/.rvm/gems/ruby-2.5.3/gems/mdless-0.0.10/lib/mdless/converter.rb:118:in `block in initialize'
         6: from /home/robin/.rvm/gems/ruby-2.5.3/gems/mdless-0.0.10/lib/mdless/converter.rb:429:in `convert_markdown'
         5: from /home/robin/.rvm/gems/ruby-2.5.3/gems/mdless-0.0.10/lib/mdless/converter.rb:429:in `gsub!'
         4: from /home/robin/.rvm/gems/ruby-2.5.3/gems/mdless-0.0.10/lib/mdless/converter.rb:445:in `block in convert_markdown'
         3: from /home/robin/.rvm/gems/ruby-2.5.3/gems/mdless-0.0.10/lib/mdless/converter.rb:324:in `hiliteCode'
         2: from /home/robin/.rvm/gems/ruby-2.5.3/gems/mdless-0.0.10/lib/mdless/converter.rb:324:in `map'
         1: from /home/robin/.rvm/gems/ruby-2.5.3/gems/mdless-0.0.10/lib/mdless/converter.rb:328:in `block in hiliteCode'
/home/robin/.rvm/gems/ruby-2.5.3/gems/mdless-0.0.10/lib/mdless/converter.rb:328:in `*': negative argument (ArgumentError)

The problem is caused by orig_lengthbecoming larger than @cols so you get a negative multiplication on the string. The fix suggested by @eliten00b works for me, it could also be done by checking if the orig_length is larger and not doing the subtraction if it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants