block: limit ordered list number width

use 64-bit to not let limit be too low, 32-bit allows for only 6 alpha
digits, "zzzzzz".
This commit is contained in:
Noah Hellman 2023-01-31 19:58:00 +01:00
parent 4b52fb0832
commit dc38076f50
2 changed files with 11 additions and 5 deletions

View file

@ -734,9 +734,15 @@ impl IdentifiedBlock {
return None; return None;
}; };
let max_len = match numbering {
Decimal => 19,
AlphaLower | AlphaUpper | RomanLower | RomanUpper => 13,
};
let chars_num = chars.clone(); let chars_num = chars.clone();
let len_num = 1 + chars_num let len_num = 1 + chars_num
.clone() .clone()
.take(max_len - 1)
.take_while(|c| match numbering { .take_while(|c| match numbering {
Decimal => c.is_ascii_digit(), Decimal => c.is_ascii_digit(),
AlphaLower => c.is_ascii_lowercase(), AlphaLower => c.is_ascii_lowercase(),

View file

@ -203,7 +203,7 @@ pub enum ListKind {
Ordered { Ordered {
numbering: OrderedListNumbering, numbering: OrderedListNumbering,
style: OrderedListStyle, style: OrderedListStyle,
start: u32, start: u64,
}, },
Task, Task,
} }
@ -265,11 +265,11 @@ pub enum Atom<'s> {
} }
impl OrderedListNumbering { impl OrderedListNumbering {
fn parse_number(self, n: &str) -> u32 { fn parse_number(self, n: &str) -> u64 {
match self { match self {
Self::Decimal => n.parse().unwrap(), Self::Decimal => n.parse().unwrap(),
Self::AlphaLower | Self::AlphaUpper => { Self::AlphaLower | Self::AlphaUpper => {
let d0 = u32::from(if matches!(self, Self::AlphaLower) { let d0 = u64::from(if matches!(self, Self::AlphaLower) {
b'a' b'a'
} else { } else {
b'A' b'A'
@ -283,13 +283,13 @@ impl OrderedListNumbering {
.iter() .iter()
.rev() .rev()
.copied() .copied()
.map(u32::from) .map(u64::from)
.zip(weights) .zip(weights)
.map(|(d, w)| w * (d - d0 + 1)) .map(|(d, w)| w * (d - d0 + 1))
.sum() .sum()
} }
Self::RomanLower | Self::RomanUpper => { Self::RomanLower | Self::RomanUpper => {
fn value(d: char) -> u32 { fn value(d: char) -> u64 {
match d { match d {
'i' | 'I' => 1, 'i' | 'I' => 1,
'v' | 'V' => 5, 'v' | 'V' => 5,