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, _) = 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
|
||||||
|
|
Loading…
Reference in New Issue