Math flow parsed inline in the syntax tree
rambip opened this issue · comments
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 ?
This is intended, code works the same way. ``code``
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:
Do you consider changing (or a least adding an option to change) that behavior ?
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
ok I somewhat agree
So I guess I will preprocess my markdown to add line breaks whenever there is $$
Ho no, I just realized that I needed the Positon
s on the syntax tree relative to the original source, so this solution does not work at all for me 😞
@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!