Skip to content

Commit

Permalink
Make EasyMark numbered lists allow more than 2 digits (#1826)
Browse files Browse the repository at this point in the history
Co-authored-by: Ygor Souza <ygor.souza@protonmail.com>
  • Loading branch information
YgorSouza and YgorSouza committed Aug 2, 2022
1 parent 06adb09 commit e39410c
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions egui_demo_lib/src/easy_mark/easy_mark_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit e39410c

Please sign in to comment.