diff --git a/magnetar_mmm_parser/src/lib.rs b/magnetar_mmm_parser/src/lib.rs index 215c439..a862acc 100644 --- a/magnetar_mmm_parser/src/lib.rs +++ b/magnetar_mmm_parser/src/lib.rs @@ -986,14 +986,13 @@ impl Context { let (input, _) = start(input)?; let (input, _) = opt(line_ending)(input)?; + let (input, _) = opt(space1_unicode)(input)?; - let (input, math_span) = recognize(many1_count(tuple(( - not(tuple((opt(line_ending), end))), - not_line_ending, - ))))(input)?; + let (input, math_span) = map( + many_till(anychar, tuple((opt(space1_unicode), opt(line_ending), end))), + |v| v.0, + )(input)?; - let (input, _) = opt(line_ending)(input)?; - let (input, _) = end(input)?; // Trailing whitespace after the closing delim let (input, _) = opt(space1_unicode)(input)?; // If we got this far, the next character should be a line ending @@ -1002,7 +1001,7 @@ impl Context { Ok(( input, - Token::BlockMath(math_span.into_fragment().to_string()), + Token::BlockMath(math_span.into_iter().collect::()), )) } @@ -1926,6 +1925,11 @@ a^2 + b^2 = c^2 Token::BlockMath("a^2 + b^2 = c^2".to_string()) ); + assert_eq!( + parse_full(r"\[ x^2 + y^2 = z^2 \]"), + Token::BlockMath("x^2 + y^2 = z^2".to_string()) + ); + assert_eq!( parse_full( r#"
centered