New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix location with nested lists #131

Closed
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
2 participants
@mivok

mivok commented Jun 7, 2014

When parsing nested lists, the reported location of the sub lists is off by one. I believe I've tracked it down to the following: when a nested list is detected, an EOB marker is inserted, causing the line numbers for everything parsed afterward to be increased by 1. This PR corrects for this by decreasing the line number once an EOB marker is detected.

I'm not sure this is the best way to fix the issue (I had to make Kramdown::Utils::StringScanner.start_line_number writable), and you might want to implement it differently.

Test case is included, but to illustrate the issue in a standalone file:

#!/usr/bin/env ruby
require 'kramdown'
text = <<EOF
* line 1
  * line 2
  * line 3
EOF

doc = Kramdown::Document.new(text).root
puts doc.children.inspect

mivok added some commits Jun 7, 2014

Fix location with nested lists
When a nested list is detected, an EOB marker is inserted, causing the line
numbers for everything parsed afterward to be increased by 1. This patch
corrects for this by decreasing the line number once an EOB marker is
detected.
Add some more tests for nested lists and EOB marks
The first added test includes an explicit EOB mark separating two lists to
ensure that the fix for nested lists doesn't affect EOB marks that are part of
the normal markdown document.

The second added test ensures this works with multiple levels of nested lists
and going up levels.
@mivok

This comment has been minimized.

mivok commented Jun 7, 2014

I spotted that EOB marks are explicit kramdown syntax and not an internal-only thing, and realized that the fix probably messes up location values for documents with explicit EOB marks in. However, when I tested this, it doesn't seem to be an issue. I added another commit to add tests for this, as well as a slightly more complex nested list.

@gettalong

This comment has been minimized.

Owner

gettalong commented Jun 8, 2014

Decrementing in #parse_eob_marker won't work correctly...

@gettalong gettalong closed this in 5472cdd Jun 8, 2014

@mivok

This comment has been minimized.

mivok commented Jun 8, 2014

Again, thanks for such a quick response and fix. I thought it odd when my manually entered EOB mark didn't cause the test to fail in the second test case, but you found a case where it didn't and fixed the right way.

@mbest mbest referenced this pull request Aug 16, 2014

Closed

May/June/July v3.2 planning #1418

2 of 5 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment