Giter Site home page Giter Site logo

Comments (9)

treefrogman avatar treefrogman commented on July 20, 2024 1

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.

from mdless.

ttscoff avatar ttscoff commented on July 20, 2024

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?

from mdless.

ttscoff avatar ttscoff commented on July 20, 2024

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

from mdless.

treefrogman avatar treefrogman commented on July 20, 2024

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?

from mdless.

ernstki avatar ernstki commented on July 20, 2024

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

from mdless.

eliten00b avatar eliten00b commented on July 20, 2024

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.

from mdless.

akhoury6 avatar akhoury6 commented on July 20, 2024

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

from mdless.

ackratos avatar ackratos commented on July 20, 2024

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!

from mdless.

digininja avatar digininja commented on July 20, 2024

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.

from mdless.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.