diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index ed7a310c..453ba2ce 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -14,6 +14,7 @@ use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::util::regurgitate; use crate::parser::util::start_of_line; +use crate::parser::util::trailing_whitespace; use nom::branch::alt; use nom::bytes::complete::tag; use nom::character::complete::digit1; @@ -38,6 +39,7 @@ pub fn plain_list<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s s }), exit_matcher, )(remaining)?; + let (remaining, _trailing_whitespace) = trailing_whitespace(remaining)?; let source = get_consumed(input, remaining); children.insert(0, first_item); Ok((remaining, PlainList { source, children })) @@ -61,8 +63,10 @@ pub fn plain_list_item<'r, 's>( let element_matcher = parser_with_context!(element)(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); let (remaining, (bull, _ws)) = tuple((bullet, space0))(remaining)?; - let (remaining, (contents, _exit_contents)) = - many_till(element_matcher, exit_matcher)(remaining)?; + let (remaining, (contents, _exit_contents)) = many_till(element_matcher, |i| { + let with_whitespace_added_back = regurgitate(input, i); + exit_matcher(with_whitespace_added_back) + })(remaining)?; let remaining = regurgitate(input, remaining); let source = get_consumed(input, remaining); diff --git a/src/parser/util.rs b/src/parser/util.rs index 9804b13d..ecd08444 100644 --- a/src/parser/util.rs +++ b/src/parser/util.rs @@ -130,6 +130,7 @@ pub fn always_fail<'r, 's>(_context: Context<'r, 's>, input: &'s str) -> Res<&'s /// Walk backwards unconsuming blank lines and line endings. /// /// List items are a special case where the trailing blank lines do not belong to it, unlike all other elements. Rather than write that special logic into each child parser, this just walks backwards through the consumed input to unconsume trailing blank lines and line breaks. +#[tracing::instrument(ret, level = "debug")] pub fn regurgitate<'s>(input: &'s str, remaining: &'s str) -> &'s str { assert!(is_slice_of(input, remaining)); let mut offset = remaining.as_ptr() as usize - input.as_ptr() as usize;