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

Math flow parsed inline in the syntax tree #68

Closed
rambip opened this issue May 12, 2023 · 6 comments
Closed

Math flow parsed inline in the syntax tree #68

rambip opened this issue May 12, 2023 · 6 comments

Comments

@rambip
Copy link

rambip commented May 12, 2023

Here is a small reproducible example:

use markdown::{to_mdast, ParseOptions, Constructs};

fn main() {
    let options = ParseOptions {
              constructs: Constructs {
                math_text: true,
                ..Constructs::default()
              },
              ..ParseOptions::default()
            };
    let ast = to_mdast("$$math$$", &options).unwrap();
    println!("{:?}", ast);
}

I get

Root { children: [Paragraph { children: [InlineMath { value: "math", position: Some(1:1-1:9 (0-8)) }], position: Some(1:1-1:9 (0-8)) }], position: Some(1:1-1:9 (0-8)) }

This was not what I was expecting

After a few tests, It seems that math is parsed "Inline" when there is no newline between the $$ and the content, but I think it is almost never the expected behavior: a math equation between $$ on a single line should not be rendered "inline"

Does it add complexity to the implementation or was it a deliberate decision ?

@rambip rambip changed the title Math flow is parsed inline in the syntax tree Math flow parsed inline in the syntax tree May 12, 2023
@wooorm
Copy link
Owner

wooorm commented May 12, 2023

This is intended, code works the same way. ``code``

@rambip
Copy link
Author

rambip commented May 13, 2023

ok

I just tried it on stackedit, and $$x$$ is not displayed inline.
On ovearleaf (the online latex editor) same thing
And even with github: $$x$$ see ?

Do you consider changing (or a least adding an option to change) that behavior ?

@wooorm
Copy link
Owner

wooorm commented May 13, 2023

No. There is no spec for math in markdown, so everyone is going to do their own thing.
It's best IMO, if there is no spec, to stick with how the spec works in similar cases

@rambip
Copy link
Author

rambip commented May 13, 2023

ok I somewhat agree
So I guess I will preprocess my markdown to add line breaks whenever there is $$

@rambip
Copy link
Author

rambip commented May 14, 2023

Ho no, I just realized that I needed the Positons on the syntax tree relative to the original source, so this solution does not work at all for me 😞

@ChristianMurphy
Copy link
Collaborator

@rambip similar to #62, I don't see this as something that would be a part of core markdown-rs.
But, a plugin could look at the positions of content, and convert inline math to math blocks based on your desired (though non-standard) rules. (depends on #32)
This could be done directly from rust with #32
Or in a more round about way working on the mdast tree (already supported in the API https://github.com/wooorm/markdown-rs#api)

Efforts towards supporting a plugin API, or enhancing the APIs around mdast handling like #64 are welcome!

@ChristianMurphy ChristianMurphy closed this as not planned Won't fix, can't repro, duplicate, stale Jul 28, 2023
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

3 participants