ttscoff / mdless

MIT License
853 stars 39 forks source link

Problem with codeblocks following lists #100

Open javipolo opened 7 months ago

javipolo commented 7 months ago

If I add a list (it does not mind if it is numbered or not) and a code block just in the line after it, codeblock is not processed as such

version: mdless 2.1.42

Example file

- something
```
hello
```

As a bonus, if the code block contains an empty line at some point, mdless crashes:

Example files with empty line

- something
```

```

or

- something
```
hello

there
```

Example crash

#<Thread:0x00007f09490f2428 /home/myuser/.local/share/gem/ruby/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:308 run> terminated with exception (report_on_exception is true):
/home/myuser/.local/share/gem/ruby/gems/mdless-2.1.42/lib/mdless/array.rb:5:in `longest_element': undefined method `last' for nil:NilClass (NoMethodError)

    group_by(&:size).max.last[0]
                        ^^^^^
        from /home/myuser/.local/share/gem/ruby/gems/mdless-2.1.42/lib/mdless/console.rb:69:in `hilite_code'
        from /home/myuser/.local/share/gem/ruby/gems/mdless-2.1.42/lib/mdless/console.rb:198:in `block_code'
        from /home/myuser/.local/share/gem/ruby/gems/mdless-2.1.42/lib/mdless/converter.rb:346:in `render'
        from /home/myuser/.local/share/gem/ruby/gems/mdless-2.1.42/lib/mdless/converter.rb:346:in `block (2 levels) in initialize'
        from /home/myuser/.local/share/gem/ruby/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:225:in `execute_job'
        from /home/myuser/.local/share/gem/ruby/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:308:in `block in run'
/home/myuser/.local/share/gem/ruby/gems/mdless-2.1.42/lib/mdless/array.rb:5:in `longest_element': undefined method `last' for nil:NilClass (NoMethodError)

    group_by(&:size).max.last[0]
                        ^^^^^
        from /home/myuser/.local/share/gem/ruby/gems/mdless-2.1.42/lib/mdless/console.rb:69:in `hilite_code'
        from /home/myuser/.local/share/gem/ruby/gems/mdless-2.1.42/lib/mdless/console.rb:198:in `block_code'
        from /home/myuser/.local/share/gem/ruby/gems/mdless-2.1.42/lib/mdless/converter.rb:346:in `render'
        from /home/myuser/.local/share/gem/ruby/gems/mdless-2.1.42/lib/mdless/converter.rb:346:in `block (2 levels) in initialize'
        from /home/myuser/.local/share/gem/ruby/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:225:in `execute_job'
        from /home/myuser/.local/share/gem/ruby/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:308:in `block in run'
ttscoff commented 7 months ago

It's standard Markdown to expect a blank line between a list and any other item. Same with code blocks. Don't be afraid of whitespace, it makes it more readable even when it's not rendered.

On 12 Mar 2024, at 11:49, Javi Polo wrote:

If I add a list (it does not mind if it is numbered or not) and a code block just in the line after it, codeblock is not processed as such

Example file

- something
```
hello
```

As a bonus, if the code block contains an empty line at some point, mdless crashes:

Example files with empty line

- something
```

```

or

- something
```
hello

there
```

Example crash

#<Thread:0x00007f09490f2428 
/home/myuser/.local/share/gem/ruby/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:308 
run> terminated with exception (report_on_exception is true):
/home/myuser/.local/share/gem/ruby/gems/mdless-2.1.42/lib/mdless/array.rb:5:in 
`longest_element': undefined method `last' for nil:NilClass 
(NoMethodError)

    group_by(&:size).max.last[0]
                        ^^^^^
        from 
/home/myuser/.local/share/gem/ruby/gems/mdless-2.1.42/lib/mdless/console.rb:69:in 
`hilite_code'
        from 
/home/myuser/.local/share/gem/ruby/gems/mdless-2.1.42/lib/mdless/console.rb:198:in 
`block_code'
        from 
/home/myuser/.local/share/gem/ruby/gems/mdless-2.1.42/lib/mdless/converter.rb:346:in 
`render'
        from 
/home/myuser/.local/share/gem/ruby/gems/mdless-2.1.42/lib/mdless/converter.rb:346:in 
`block (2 levels) in initialize'
        from 
/home/myuser/.local/share/gem/ruby/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:225:in 
`execute_job'
        from 
/home/myuser/.local/share/gem/ruby/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:308:in 
`block in run'
/home/myuser/.local/share/gem/ruby/gems/mdless-2.1.42/lib/mdless/array.rb:5:in 
`longest_element': undefined method `last' for nil:NilClass 
(NoMethodError)

    group_by(&:size).max.last[0]
                        ^^^^^
        from 
/home/myuser/.local/share/gem/ruby/gems/mdless-2.1.42/lib/mdless/console.rb:69:in 
`hilite_code'
        from 
/home/myuser/.local/share/gem/ruby/gems/mdless-2.1.42/lib/mdless/console.rb:198:in 
`block_code'
        from 
/home/myuser/.local/share/gem/ruby/gems/mdless-2.1.42/lib/mdless/converter.rb:346:in 
`render'
        from 
/home/myuser/.local/share/gem/ruby/gems/mdless-2.1.42/lib/mdless/converter.rb:346:in 
`block (2 levels) in initialize'
        from 
/home/myuser/.local/share/gem/ruby/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:225:in 
`execute_job'
        from 
/home/myuser/.local/share/gem/ruby/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:308:in 
`block in run'

-- Reply to this email directly or view it on GitHub: https://github.com/ttscoff/mdless/issues/100 You are receiving this because you are subscribed to this thread.

Message ID: @.***>

javipolo commented 7 months ago

Yeah, I discovered that the hard way :D

Anyway, other markdown tools work with that kind of syntax, which makes mdless not render properly markdown files that are written like that ...

But the scary thing is that mdless crashses on some conditions as explained above :sweat_smile:

Example of that incorrect markdown rendering in github:

ttscoff commented 7 months ago

Mdless uses a specific markdown flavor. Markdown flavors vary pretty widely. But using standardized syntax works everywhere, e.g. adding a newline before and after block elements. That won’t break anywhere.

I can’t make a command line renderer work with every quirk of every Markdown flavor. Using responsible markup that offers the widest range of compatibility should be  the writer’s goal.

Thanks, Brett On Mar 12, 2024 at 12:37 PM -0500, Javi Polo @.***>, wrote:

Yeah, I discovered that the hard way :D Anyway, other markdown tools work with that kind of syntax, which makes mdless not render properly markdown files that are written like that ... But the scary thing is that mdless crashses on some conditions as explained above 😅 Example of that incorrect markdown rendering in github:

• something

some code

• other thing

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

javipolo commented 7 months ago

I understand your point of view, but as a user, I want a tool I can use with files I did not produce. At least for me, it is the main use of mdless :)

However, the big concern is not that something is rendered incorrectly, but that the app crashes, and thus nothing is rendered

ttscoff commented 7 months ago

Assuming you’re using the 2.x series of mdless, the universality of the rendering is the best I can get it using the RedCarpet processor.

Thanks, Brett On Mar 12, 2024 at 1:56 PM -0500, Javi Polo @.***>, wrote:

I understand your point of view, but as a user, I want a tool I can use with files I did not produce. At least for me, it is the main use of mdless :) However, the big concern is not that something is rendered incorrectly, but that the app crashes, and thus nothing is rendered — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

ttscoff commented 7 months ago

I'm not sure what the difference between "crashing" and not rendering anything is. Do you receive an error?

-Brett

On 12 Mar 2024, at 13:56, Javi Polo wrote:

I understand your point of view, but as a user, I want a tool I can use with files I did not produce. At least for me, it is the main use of mdless :)

However, the big concern is not that something is rendered incorrectly, but that the app crashes, and thus nothing is rendered

-- Reply to this email directly or view it on GitHub: https://github.com/ttscoff/mdless/issues/100#issuecomment-1992337815 You are receiving this because you commented.

Message ID: @.***>

javipolo commented 7 months ago

Here is how it looks when it does not render the code block properly, but the file is processed anyway: image

And here is what happens when it crashes: image

cs-shadowbq commented 6 months ago

This is unfortunate as I get the same exact error with very little ability to understand why the parsing is broken.

mdless index.md
[⠋] Processing index.md...#<Thread:0x00000001249961a8 /usr/local/Cellar/mdless/2.1.42_1/libexec/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:308 run> terminated with exception (report_on_exception is true):
[⠙] Processing index.md.../usr/local/Cellar/mdless/2.1.42_1/libexec/gems/mdless-2.1.42/lib/mdless/array.rb:5:in `longest_element': undefined method `last' for nil (NoMethodError)

    group_by(&:size).max.last[0]
                        ^^^^^
    from /usr/local/Cellar/mdless/2.1.42_1/libexec/gems/mdless-2.1.42/lib/mdless/console.rb:69:in `hilite_code'
    from /usr/local/Cellar/mdless/2.1.42_1/libexec/gems/mdless-2.1.42/lib/mdless/console.rb:198:in `block_code'
    from /usr/local/Cellar/mdless/2.1.42_1/libexec/gems/mdless-2.1.42/lib/mdless/converter.rb:346:in `render'
    from /usr/local/Cellar/mdless/2.1.42_1/libexec/gems/mdless-2.1.42/lib/mdless/converter.rb:346:in `block (2 levels) in initialize'
    from /usr/local/Cellar/mdless/2.1.42_1/libexec/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:225:in `execute_job'
    from /usr/local/Cellar/mdless/2.1.42_1/libexec/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:308:in `block in run'
/usr/local/Cellar/mdless/2.1.42_1/libexec/gems/mdless-2.1.42/lib/mdless/array.rb:5:in `longest_element': undefined method `last' for nil (NoMethodError)

    group_by(&:size).max.last[0]
                        ^^^^^
    from /usr/local/Cellar/mdless/2.1.42_1/libexec/gems/mdless-2.1.42/lib/mdless/console.rb:69:in `hilite_code'
    from /usr/local/Cellar/mdless/2.1.42_1/libexec/gems/mdless-2.1.42/lib/mdless/console.rb:198:in `block_code'
    from /usr/local/Cellar/mdless/2.1.42_1/libexec/gems/mdless-2.1.42/lib/mdless/converter.rb:346:in `render'
    from /usr/local/Cellar/mdless/2.1.42_1/libexec/gems/mdless-2.1.42/lib/mdless/converter.rb:346:in `block (2 levels) in initialize'
    from /usr/local/Cellar/mdless/2.1.42_1/libexec/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:225:in `execute_job'
    from /usr/local/Cellar/mdless/2.1.42_1/libexec/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:308:in `block in run'

The markdown is GHFM.

ttscoff commented 6 months ago

can you attach the index.md file that this is failing on?

On 29 Apr 2024, at 12:10, cs-shadowbq wrote:

This is unfortunate as I get the same exact error with very little ability to understand why the parsing is broken.

mdless index.md
[⠋] Processing index.md...#<Thread:0x00000001249961a8 
/usr/local/Cellar/mdless/2.1.42_1/libexec/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:308 
run> terminated with exception (report_on_exception is true):
[⠙] Processing 
index.md.../usr/local/Cellar/mdless/2.1.42_1/libexec/gems/mdless-2.1.42/lib/mdless/array.rb:5:in 
`longest_element': undefined method `last' for nil (NoMethodError)

    group_by(&:size).max.last[0]
                        ^^^^^
    from 
/usr/local/Cellar/mdless/2.1.42_1/libexec/gems/mdless-2.1.42/lib/mdless/console.rb:69:in 
`hilite_code'
    from 
/usr/local/Cellar/mdless/2.1.42_1/libexec/gems/mdless-2.1.42/lib/mdless/console.rb:198:in 
`block_code'
    from 
/usr/local/Cellar/mdless/2.1.42_1/libexec/gems/mdless-2.1.42/lib/mdless/converter.rb:346:in 
`render'
    from 
/usr/local/Cellar/mdless/2.1.42_1/libexec/gems/mdless-2.1.42/lib/mdless/converter.rb:346:in 
`block (2 levels) in initialize'
    from 
/usr/local/Cellar/mdless/2.1.42_1/libexec/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:225:in 
`execute_job'
    from 
/usr/local/Cellar/mdless/2.1.42_1/libexec/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:308:in 
`block in run'
/usr/local/Cellar/mdless/2.1.42_1/libexec/gems/mdless-2.1.42/lib/mdless/array.rb:5:in 
`longest_element': undefined method `last' for nil (NoMethodError)

    group_by(&:size).max.last[0]
                        ^^^^^
    from 
/usr/local/Cellar/mdless/2.1.42_1/libexec/gems/mdless-2.1.42/lib/mdless/console.rb:69:in 
`hilite_code'
    from 
/usr/local/Cellar/mdless/2.1.42_1/libexec/gems/mdless-2.1.42/lib/mdless/console.rb:198:in 
`block_code'
    from 
/usr/local/Cellar/mdless/2.1.42_1/libexec/gems/mdless-2.1.42/lib/mdless/converter.rb:346:in 
`render'
    from 
/usr/local/Cellar/mdless/2.1.42_1/libexec/gems/mdless-2.1.42/lib/mdless/converter.rb:346:in 
`block (2 levels) in initialize'
    from 
/usr/local/Cellar/mdless/2.1.42_1/libexec/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:225:in 
`execute_job'
    from 
/usr/local/Cellar/mdless/2.1.42_1/libexec/gems/tty-spinner-0.9.3/lib/tty/spinner.rb:308:in 
`block in run'

The markdown is GHFM.

-- Reply to this email directly or view it on GitHub: https://github.com/ttscoff/mdless/issues/100#issuecomment-2083241859 You are receiving this because you commented.

Message ID: @.***>