Fixing bug about outputting "undefined" bullets #192
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To be honest I'm not a JavaScript guy but I think that I may have fixed the problem seen in #42, #131 and #168.
The actual output of "undefined" was made here
Basically some elements had their
lvl
negative and so the bullet was "undefined".I think that the source of the problem lies in two different places.
Unindenting (1) just because the first H1 needs to be stripped doesn't work well in a document which has others H1s down the line.
The second problem lies here:
Computing the highest (2) heading and THEN stripping out the first h1 means that we are computing about old data. Furthermore (3) we are assuming that the first H1 will be the first in the array but that is not always the case, think about this input:
So I propose to move up the stripping of the first H1 and actually searching for an H1 only. And then get rid of the unindent step.
Feel free to correct my JS or to tell me if there are some edge cases that I didn't think about (btw all tests are successful)