rubensworks / ScholarMarkdown

A framework for writing markdown-based scholarly articles.
MIT License
42 stars 8 forks source link

Crashes on improper nesting #31

Open RubenVerborgh opened 2 years ago

RubenVerborgh commented 2 years ago

I accidentally had a structure

## h2
### h3

### h4

where the h3 was not being picked up because of a missing newline before.

It crashed as follows:


NoMethodError: undefined method `[]' for nil:NilClass

    sections_index[@reference_counts[document_sections[0]] - 1][:children][@reference_counts[document_sections[1]] - 1][:children][@reference_counts[document_sections[2]] - 1] = { :name => name, :id => id, :children => [] }
                                                                                                                       ^^^^^^^^^^^

Current item: /index.md.erb (:default representation)

  0. /Users/ruben/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/scholarmarkdown-3.0.0/lib/scholarmarkdown/filter/labelify.rb:98:in `number_for'
  1. ```