diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index 045b924..7259fcd 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -128,13 +128,13 @@ pub fn plain_list_item<'r, 's>( exit_matcher: ChainBehavior::AndParent(Some(&plain_list_item_end)), })); let without_consume_context = context - .with_additional_node(ContextElement::ConsumeTrailingWhitespace(false)) .with_additional_node(ContextElement::ListItem(indent_level)) .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { exit_matcher: ChainBehavior::AndParent(Some(&plain_list_item_end)), })); - let element_matcher = parser_with_context!(element)(&with_consume_context); + let with_consume_matcher = parser_with_context!(element)(&with_consume_context); + let without_consume_matcher = parser_with_context!(element)(&with_consume_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&with_consume_context); let (remaining, bull) = verify(bullet, |bull: &str| bull != "*" || indent_level > 0)(remaining)?; @@ -155,9 +155,12 @@ pub fn plain_list_item<'r, 's>( } Err(_) => { let (remaining, _ws) = space1(remaining)?; - // TODO: The problem is we are not capturing trailing whitespace for elements that are before the last element. - let (remaining, (contents, _exit_contents)) = - many_till(element_matcher, exit_matcher)(remaining)?; + let (remaining, (mut contents, (final_element, _exit_contents))) = + many_till( + with_consume_matcher, + tuple((without_consume_matcher, exit_matcher)), + )(remaining)?; + contents.push(final_element); let source = get_consumed(input, remaining); return Ok(( remaining,