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

format_commonmark panics on a single list item #485

Closed
silverpill opened this issue Nov 11, 2024 · 2 comments · Fixed by #486
Closed

format_commonmark panics on a single list item #485

silverpill opened this issue Nov 11, 2024 · 2 comments · Fixed by #486

Comments

@silverpill
Copy link

Panic occurs when format_commonmark input contains a single NodeValue::Item:

https://github.com/kivikakk/comrak/blob/v0.29.0/src/cm.rs#L468

It didn't panic before version 0.25.0 (unwrap was introduced in #429).

@kivikakk
Copy link
Owner

That's an interesting/unexpected use case! I suppose we can revert to the previous behaviour if the stack is indeed unexpectedly empty:

let list_number = if let Some(last_stack) = self.ol_stack.last_mut() {
    let ln = *last_stack;
    if entering {
        *last_stack += 1;
    }
    ln
} else {
    match node.data.borrow().value {
        NodeValue::Item(ref ni) => ni.start,
        NodeValue::TaskItem(_) => parent.start,
        _ => unreachable!(),
    }
};

What do you think? Please feel free to open a PR; it'd also be great to have a test with your use case in mind so it doesn't regress!

@silverpill
Copy link
Author

That solution works. I'll submit a PR shortly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants