MMM: More forgiving math parsing

This commit is contained in:
Natty 2023-12-30 20:02:25 +01:00
parent 9c8489ced7
commit ce8cb5aad0
Signed by: natty
GPG Key ID: BF6CB659ADEE60EC
1 changed files with 11 additions and 7 deletions

View File

@ -986,14 +986,13 @@ impl Context {
let (input, _) = start(input)?; let (input, _) = start(input)?;
let (input, _) = opt(line_ending)(input)?; let (input, _) = opt(line_ending)(input)?;
let (input, _) = opt(space1_unicode)(input)?;
let (input, math_span) = recognize(many1_count(tuple(( let (input, math_span) = map(
not(tuple((opt(line_ending), end))), many_till(anychar, tuple((opt(space1_unicode), opt(line_ending), end))),
not_line_ending, |v| v.0,
))))(input)?; )(input)?;
let (input, _) = opt(line_ending)(input)?;
let (input, _) = end(input)?;
// Trailing whitespace after the closing delim // Trailing whitespace after the closing delim
let (input, _) = opt(space1_unicode)(input)?; let (input, _) = opt(space1_unicode)(input)?;
// If we got this far, the next character should be a line ending // If we got this far, the next character should be a line ending
@ -1002,7 +1001,7 @@ impl Context {
Ok(( Ok((
input, input,
Token::BlockMath(math_span.into_fragment().to_string()), Token::BlockMath(math_span.into_iter().collect::<String>()),
)) ))
} }
@ -1926,6 +1925,11 @@ a^2 + b^2 = c^2
Token::BlockMath("a^2 + b^2 = c^2".to_string()) 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!( assert_eq!(
parse_full( parse_full(
r#"<center>centered r#"<center>centered