wooorm / markdown-rs

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

to_mdast Math parsing error #83

Closed 8LWXpg closed 9 months ago

8LWXpg commented 9 months ago

the parser threat $$something$$ as inline math

#[test]
fn math_test() {
    println!(
        "{:?}",
        to_mdast(
            "$$\nnot inline\n$$\n$$not inline$$\n$inline$",
            &ParseOptions {
                constructs: Constructs {
                    math_flow: true,
                    math_text: true,
                    ..Constructs::gfm()
                },
                ..Default::default()
            }
        )
    )
}

output:

Ok(Root { children: [Math { value: "not inline", position: Some(1:1-3:3 (0-16)), meta: None }, Paragraph { children: [InlineMath { value: "not inline", position: Some(4:1-4:15 (17-31)) }, Text { value: "\n", position: Some(4:15-5:1 (31-32)) }, InlineMath { value: "inline", position: Some(5:1-5:9 (32-40)) }], position: Some(4:1-5:9 (17-40)) }], position: Some(1:1-5:9 (0-40)) })
wooorm commented 9 months ago

Intended. Math works like code.

``inline``

block


$$inline$$

$$
block
$$
8LWXpg commented 9 months ago

There's some website that render $$something$$ as block math, like GitHub or Stack Exchange. I hope there's an option or something to do so.

wooorm commented 9 months ago

The problem is that math is unspecified. If I do something here, it won't ever work like all other projects. The solution is to get this specified!

8LWXpg commented 9 months ago

maybe add this inside ParseOptions with force enabling math_text_single_dollar. That way, double dollar is always threated as block math while single dollar will be treated as inline. I think most markdown math is rendered that way (at least for those I familiar with).

wooorm commented 9 months ago

maybe add this inside

add what? what is this? You asked about matching how GH works and matching how Stack Exchange work. That’s two complex things that are unspecified and take a lot of time, with little benefit. To reiterate, I think: “The solution is to get [math in markdown] specified!”

8LWXpg commented 9 months ago

I think math in markdown is double dollar for block math and single dollar for inline in most cases, regardless of newline

wooorm commented 9 months ago

There is no specification for that. Every tool is different.

This is based on CM and is exactly the same as the sister projects in JS.