asciidoctor / kramdown-asciidoc

A kramdown extension for converting Markdown documents to AsciiDoc.
Other
207 stars 19 forks source link

undefined method `start_with?' for nil:NilClass #93

Closed xicesky closed 2 years ago

xicesky commented 3 years ago

Hello maintainers, thanks for your hard work!

On certain files i get the following error:

Traceback (most recent call last):
        15: from /usr/local/bundle/bin/kramdoc:23:in `<main>'
        14: from /usr/local/bundle/bin/kramdoc:23:in `load'
        13: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/bin/kramdoc:13:in `<top (required)>'
        12: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/cli.rb:120:in `run'
        11: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/api.rb:107:in `convert_file'
        10: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/api.rb:55:in `convert'
         9: from /usr/local/bundle/gems/kramdown-2.3.1/lib/kramdown/document.rb:116:in `method_missing'
         8: from /usr/local/bundle/gems/kramdown-2.3.1/lib/kramdown/converter/base.rb:107:in `convert'
         7: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/converter.rb:102:in `convert'
         6: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/converter.rb:108:in `convert_root'
         5: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/converter.rb:667:in `traverse'
         4: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/converter.rb:667:in `each_with_index'
         3: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/converter.rb:667:in `each'
         2: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/converter.rb:668:in `block in traverse'
         1: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/converter.rb:102:in `convert'
/usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/converter.rb:235:in `convert_codeblock': undefined method `start_with?' for nil:NilClass
 (NoMethodError)

I have no experience in ruby, thus i'm not trying to submit a pull request, but i fixed it locally by patching kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/converter.rb, line 235:

elsif (lines.length > 0) && (prompt = lines[0].start_with? '$ ')
mojavelinux commented 3 years ago

The best thing you can do to help is to identify which file, and specifically which Markdown, triggers this error. Then we can make a test for it. Thanks!

mojavelinux commented 2 years ago

I've determined that this happens if the fenced code block is empty and does not specific a language. In other words:

```
```

The code is assuming there is at least one line.