MMM: More forgiving math parsing
This commit is contained in:
parent
9c8489ced7
commit
ce8cb5aad0
|
@ -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::<String>()),
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -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#"<center>centered
|
||||
|
|
Loading…
Reference in New Issue