fixup! block: parse list item
This commit is contained in:
parent
a9ce70aae3
commit
c4a9a3e0b0
1 changed files with 73 additions and 63 deletions
40
src/block.rs
40
src/block.rs
|
@ -388,7 +388,7 @@ impl BlockParser {
|
|||
)
|
||||
})
|
||||
}
|
||||
c => maybe_ordered_list_item(c, &mut chars).map(|(num, style, len)| {
|
||||
c => Self::maybe_ordered_list_item(c, &mut chars).map(|(num, style, len)| {
|
||||
(
|
||||
Block::Container(ListItem(Ordered(num, style))),
|
||||
Span::by_len(start, len),
|
||||
|
@ -426,7 +426,16 @@ impl BlockParser {
|
|||
Block::Leaf(Paragraph | Heading | Table) => !line.trim().is_empty(),
|
||||
Block::Leaf(LinkDefinition) => line.starts_with(' ') && !line.trim().is_empty(),
|
||||
Block::Container(Blockquote) => line.trim().starts_with('>'),
|
||||
Block::Container(Footnote | ListItem(..)) => {
|
||||
Block::Container(ListItem(..)) => {
|
||||
let spaces = line.chars().take_while(|c| c.is_whitespace()).count();
|
||||
empty
|
||||
|| spaces > self.indent
|
||||
|| matches!(
|
||||
Self::parse(std::iter::once(line)),
|
||||
Some((_, Block::Leaf(Leaf::Paragraph), _, _)),
|
||||
)
|
||||
}
|
||||
Block::Container(Footnote) => {
|
||||
let spaces = line.chars().take_while(|c| c.is_whitespace()).count();
|
||||
empty || spaces > self.indent
|
||||
}
|
||||
|
@ -439,12 +448,19 @@ impl BlockParser {
|
|||
Block::Container(List(..)) => panic!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn maybe_ordered_list_item(
|
||||
fn maybe_ordered_list_item(
|
||||
mut first: char,
|
||||
chars: &mut std::str::Chars,
|
||||
) -> Option<(crate::OrderedListNumbering, crate::OrderedListStyle, usize)> {
|
||||
) -> Option<(crate::OrderedListNumbering, crate::OrderedListStyle, usize)> {
|
||||
fn is_roman_lower_digit(c: char) -> bool {
|
||||
matches!(c, 'i' | 'v' | 'x' | 'l' | 'c' | 'd' | 'm')
|
||||
}
|
||||
|
||||
fn is_roman_upper_digit(c: char) -> bool {
|
||||
matches!(c, 'I' | 'V' | 'X' | 'L' | 'C' | 'D' | 'M')
|
||||
}
|
||||
|
||||
let start_paren = first == '(';
|
||||
if start_paren {
|
||||
first = chars.next().unwrap_or(EOF);
|
||||
|
@ -493,8 +509,9 @@ fn maybe_ordered_list_item(
|
|||
let len_style = usize::from(start_paren) + 1;
|
||||
|
||||
let chars_num = std::iter::once(first).chain(chars_num.take(len_num - 1));
|
||||
let numbering =
|
||||
if matches!(numbering, AlphaLower) && chars_num.clone().all(is_roman_lower_digit) {
|
||||
let numbering = if matches!(numbering, AlphaLower)
|
||||
&& chars_num.clone().all(is_roman_lower_digit)
|
||||
{
|
||||
RomanLower
|
||||
} else if matches!(numbering, AlphaUpper) && chars_num.clone().all(is_roman_upper_digit) {
|
||||
RomanUpper
|
||||
|
@ -507,14 +524,7 @@ fn maybe_ordered_list_item(
|
|||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn is_roman_lower_digit(c: char) -> bool {
|
||||
matches!(c, 'i' | 'v' | 'x' | 'l' | 'c' | 'd' | 'm')
|
||||
}
|
||||
|
||||
fn is_roman_upper_digit(c: char) -> bool {
|
||||
matches!(c, 'I' | 'V' | 'X' | 'L' | 'C' | 'D' | 'M')
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Block {
|
||||
|
|
Loading…
Reference in a new issue