fixup! block: parse list item
This commit is contained in:
parent
a9ce70aae3
commit
c4a9a3e0b0
1 changed files with 73 additions and 63 deletions
34
src/block.rs
34
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))),
|
Block::Container(ListItem(Ordered(num, style))),
|
||||||
Span::by_len(start, len),
|
Span::by_len(start, len),
|
||||||
|
@ -426,7 +426,16 @@ impl BlockParser {
|
||||||
Block::Leaf(Paragraph | Heading | Table) => !line.trim().is_empty(),
|
Block::Leaf(Paragraph | Heading | Table) => !line.trim().is_empty(),
|
||||||
Block::Leaf(LinkDefinition) => line.starts_with(' ') && !line.trim().is_empty(),
|
Block::Leaf(LinkDefinition) => line.starts_with(' ') && !line.trim().is_empty(),
|
||||||
Block::Container(Blockquote) => line.trim().starts_with('>'),
|
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();
|
let spaces = line.chars().take_while(|c| c.is_whitespace()).count();
|
||||||
empty || spaces > self.indent
|
empty || spaces > self.indent
|
||||||
}
|
}
|
||||||
|
@ -439,12 +448,19 @@ impl BlockParser {
|
||||||
Block::Container(List(..)) => panic!(),
|
Block::Container(List(..)) => panic!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn maybe_ordered_list_item(
|
fn maybe_ordered_list_item(
|
||||||
mut first: char,
|
mut first: char,
|
||||||
chars: &mut std::str::Chars,
|
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 == '(';
|
let start_paren = first == '(';
|
||||||
if start_paren {
|
if start_paren {
|
||||||
first = chars.next().unwrap_or(EOF);
|
first = chars.next().unwrap_or(EOF);
|
||||||
|
@ -493,8 +509,9 @@ fn maybe_ordered_list_item(
|
||||||
let len_style = usize::from(start_paren) + 1;
|
let len_style = usize::from(start_paren) + 1;
|
||||||
|
|
||||||
let chars_num = std::iter::once(first).chain(chars_num.take(len_num - 1));
|
let chars_num = std::iter::once(first).chain(chars_num.take(len_num - 1));
|
||||||
let numbering =
|
let numbering = if matches!(numbering, AlphaLower)
|
||||||
if matches!(numbering, AlphaLower) && chars_num.clone().all(is_roman_lower_digit) {
|
&& chars_num.clone().all(is_roman_lower_digit)
|
||||||
|
{
|
||||||
RomanLower
|
RomanLower
|
||||||
} else if matches!(numbering, AlphaUpper) && chars_num.clone().all(is_roman_upper_digit) {
|
} else if matches!(numbering, AlphaUpper) && chars_num.clone().all(is_roman_upper_digit) {
|
||||||
RomanUpper
|
RomanUpper
|
||||||
|
@ -508,13 +525,6 @@ fn maybe_ordered_list_item(
|
||||||
None
|
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 {
|
impl std::fmt::Display for Block {
|
||||||
|
|
Loading…
Reference in a new issue