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

Numbered list items start at 2 #38

Closed
andrewbaxter opened this issue Dec 19, 2022 · 4 comments
Closed

Numbered list items start at 2 #38

andrewbaxter opened this issue Dec 19, 2022 · 4 comments

Comments

@andrewbaxter
Copy link

I don't have a minimal reproduction, but I have this code

        let ast = markdown::to_mdast(source, &markdown::ParseOptions {
            constructs: markdown::Constructs { ..Default::default() },
            ..Default::default()
        }).map_err(|e| anyhow!("{}", e))?;

and

        Node::List(x) => {
            match &x.start {
                Some(i) => {
                    for (j, child) in x.children.iter().enumerate() {
                        println!("numbered list, i {} j {}", i, j);
                        if j > 0 {
                            line.write_newline(state, out);
                        }
                        recurse_write(
                            state,
                            out,
                            line.clone_indent(Some(format!("{}. ", *i as usize + j)), "   ".into(), false),
                            child,
                        );
                    }
                },
                None => {
                    for (i, child) in x.children.iter().enumerate() {
                        if i > 0 {
                            line.write_newline(state, out);
                        }
                        recurse_write(state, out, line.clone_indent(Some("* ".into()), "   ".into(), false), child);
                    }
                },
            };
        },

Which produces this output:

formatting md:
 1. list item one
 2. list item 2
numbered list, i 2 j 0
numbered list, i 2 j 1

You can see x.start is 2 rather than the expected 1

@andrewbaxter
Copy link
Author

I just tested a bit more, it looks like it's using the last number from the list. So the above with 1., 2., 3. uses 3 instead.

@wooorm wooorm closed this as completed in af202d3 Dec 19, 2022
@wooorm
Copy link
Owner

wooorm commented Dec 19, 2022

Thanks. This was pretty easy, but for the next time: can you please provide the input you have?

@andrewbaxter
Copy link
Author

Ah yes, sorry, that could have been more clear. The input was included in the output above, per the snippet:

 1. list item one
 2. list item 2

@andrewbaxter
Copy link
Author

Thanks for fixing this!

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

No branches or pull requests

2 participants