Skip to content

Commit f33f70d

Browse files
committed
Stop at first suitable $ at inline math
1 parent 28d9fac commit f33f70d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/parser/inlines.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,16 @@ impl<'a, 'r, 'o, 'd, 'i, 'c> Subject<'a, 'r, 'o, 'd, 'i, 'c> {
647647
self.pos - start_pos
648648
}
649649

650+
pub fn take_while_with_limit(&mut self, c: u8, limit: usize) -> usize {
651+
let start_pos = self.pos;
652+
let mut count = 0;
653+
while count < limit && self.peek_char() == Some(&c) {
654+
self.pos += 1;
655+
count += 1;
656+
}
657+
self.pos - start_pos
658+
}
659+
650660
pub fn scan_to_closing_backtick(&mut self, openticklength: usize) -> Option<usize> {
651661
if openticklength > MAXBACKTICKS {
652662
return None;
@@ -733,7 +743,7 @@ impl<'a, 'r, 'o, 'd, 'i, 'c> Subject<'a, 'r, 'o, 'd, 'i, 'c> {
733743
continue;
734744
}
735745

736-
let numdollars = self.take_while(b'$');
746+
let numdollars = self.take_while_with_limit(b'$', opendollarlength);
737747

738748
// ending $ can't be followed by a digit
739749
if opendollarlength == 1 && self.peek_char().map_or(false, |&c| isdigit(c)) {

src/tests/math.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use super::*;
22
use ntest::test_case;
33

44
#[test_case("$2+2$", "<p><math>2+2</math></p>\n")]
5+
#[test_case("$\\alpha$$\\beta$", "<p><math>\\alpha</math><math>\\beta</math></p>\n")]
6+
#[test_case("$2+2$$2+2$", "<p><math>2+2</math><math>2+2</math></p>\n")]
57
#[test_case("$22 and $2+2$", "<p>$22 and <math>2+2</math></p>\n")]
68
#[test_case("$a!$", "<p><math>a!</math></p>\n")]
79
#[test_case("$x$", "<p><math>x</math></p>\n")]

0 commit comments

Comments
 (0)