Make EasyMark numbered lists allow more than 2 digits
@@ -101,27 +101,13 @@ impl<'a> Parser<'a> {
/// `1. `, `42. ` etc.
fn numbered_list(&mut self) -> Option<Item<'a>> {
- let bytes = self.s.as_bytes();
- // 1. numbered bullet
- if bytes.len() >= 3 && bytes[0].is_ascii_digit() && bytes[1] == b'.' && bytes[2] == b' ' {
- let number = &self.s[0..1];
- self.s = &self.s[3..];
+ let n_digits = self.s.chars().take_while(|c| c.is_ascii_digit()).count();
+ if n_digits > 0 && self.s.chars().skip(n_digits).take(2).eq(". ".chars()) {
+ let number = &self.s[..n_digits];
+ self.s = &self.s[(n_digits + 2)..];
self.start_of_line = false;
return Some(Item::NumberedPoint(number));
}
- // 42. double-digit numbered bullet
- if bytes.len() >= 4
- && bytes[0].is_ascii_digit()
- && bytes[1].is_ascii_digit()
- && bytes[2] == b'.'
- && bytes[3] == b' '
- {
- let number = &self.s[0..2];
- self.s = &self.s[4..];
- self.start_of_line = false;
- return Some(Item::NumberedPoint(number));
- }
- // There is no triple-digit numbered bullet. Please don't make numbered lists that long.
None
}
