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;
};
let max_len = match numbering {
Decimal => 19,
AlphaLower | AlphaUpper | RomanLower | RomanUpper => 13,
};
let chars_num = chars.clone();
let len_num = 1 + chars_num
.clone()
.take(max_len - 1)
.take_while(|c| match numbering {
Decimal => c.is_ascii_digit(),
AlphaLower => c.is_ascii_lowercase(),

View file

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