Not sure whats going on.

This commit is contained in:
Tom Alexander 2023-03-27 19:19:51 -04:00
parent 9545990b52
commit 775e703ade
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 7 additions and 2 deletions

View File

@ -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);

View File

@ -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;