Skip to content
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

Some headlines return wrong offsets #404

Open
terhechte opened this issue Sep 16, 2019 · 1 comment · May be fixed by #405

Comments

@terhechte
Copy link

commented Sep 16, 2019

In some situations, headlines are reported with an invalid offset. Here is an example.

Code:

use pulldown_cmark::*;

fn main() {
    let markdown = "

# Test

Text.

---
#
``` C
#include <stdio.h>
```";

    let mut options = Options::empty();
    let parser = Parser::new_ext(markdown, options);
    let iter = parser.into_offset_iter();

    for (element, offset) in iter {
        println!("{:?}: {:?}", &element, &offset);
    }
}

The second headline will be reported as having an offset of 21..0 which is wrong, the correct offset should be 21..22.

Here is the output:

Start(Heading(1)): 2..9
Text(Borrowed("Test")): 4..8
End(Heading(1)): 2..9
Start(Paragraph): 10..16
Text(Borrowed("Text.")): 10..15
End(Paragraph): 10..16
Rule: 17..21
Start(Heading(1)): 21..0
End(Heading(1)): 21..0
Start(CodeBlock(Borrowed("C"))): 23..51
Text(Borrowed("#include <stdio.h>\n")): 29..48
End(CodeBlock(Borrowed("C"))): 23..51

I've also seen this happen if a headline is opened at the very bottom of a document.

@marcusklaas marcusklaas added the bug label Sep 16, 2019
@marcusklaas

This comment has been minimized.

Copy link
Collaborator

commented Sep 16, 2019

Woops, that does look like a bug. Thanks for reporting this. We'll look into it.

@marcusklaas marcusklaas referenced a pull request that will close this issue Sep 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.