wooorm / markdown-rs

CommonMark compliant markdown parser in Rust with ASTs and extensions
https://docs.rs/markdown/1.0.0-alpha.21/markdown/
MIT License
966 stars 53 forks source link

Incorrect parsing of list + decoration + hard break #129

Closed lucasavila00 closed 2 months ago

lucasavila00 commented 2 months ago
let text = r#"1. **Bold title**// no space after this <--- the comment is not in the input
The content
"#;

&tks = Root {
    children: [
        List {
            children: [
                ListItem {
                    children: [
                        Paragraph {
                            children: [
                                Strong {
                                    children: [
                                        Text {
                                            value: "Bold title",
                                            position: Some(
                                                1:6-1:16 (5-15),
                                            ),
                                        },
                                    ],
                                    position: Some(
                                        1:4-1:18 (3-17),
                                    ),
                                },
                                Text {
                                    value: "\nThe content",
                                    position: Some(
                                        1:18-2:12 (17-29),
                                    ),
                                },
                            ],
                            position: Some(
                                1:4-2:12 (3-29),
                            ),
                        },
                    ],
                    position: Some(
                        1:1-2:12 (0-29),
                    ),
                    spread: false,
                    checked: None,
                },
            ],
            position: Some(
                1:1-2:12 (0-29),
            ),
            ordered: true,
            start: Some(
                1,
            ),
            spread: false,
        },
    ],
    position: Some(
        1:1-3:1 (0-30),
    ),
}

But if the decoration as 2 spaces after it, it works:

let text = r#"1. **Bold title**  //notice the space
The content
"#;

&tks = Root {
    children: [
        List {
            children: [
                ListItem {
                    children: [
                        Paragraph {
                            children: [
                                Strong {
                                    children: [
                                        Text {
                                            value: "Bold title",
                                            position: Some(
                                                1:6-1:16 (5-15),
                                            ),
                                        },
                                    ],
                                    position: Some(
                                        1:4-1:18 (3-17),
                                    ),
                                },
                                Break {
                                    position: Some(
                                        1:18-2:1 (17-20),
                                    ),
                                },
                                Text {
                                    value: "The content",
                                    position: Some(
                                        2:1-2:12 (20-31),
                                    ),
                                },
                            ],
                            position: Some(
                                1:4-2:12 (3-31),
                            ),
                        },
                    ],
                    position: Some(
                        1:1-2:12 (0-31),
                    ),
                    spread: false,
                    checked: None,
                },
            ],
            position: Some(
                1:1-2:12 (0-31),
            ),
            ordered: true,
            start: Some(
                1,
            ),
            spread: false,
        },
    ],
    position: Some(
        1:1-3:1 (0-32),
    ),
}
lucasavila00 commented 2 months ago

This behavior is correct. Sorry for the noise.