Pass context into paragraph from document instead of generating the initial context at paragraph level.

This commit is contained in:
Tom Alexander
2022-07-17 18:40:05 -04:00
parent e5af567981
commit 70688c8d51
3 changed files with 14 additions and 11 deletions

View File

@@ -74,8 +74,14 @@ where
)(i)
}
pub fn paragraph(input: &str) -> Res<&str, (Vec<TextElement>, &str)> {
let initial_context = NomContext::new(&paragraph_end);
let text_element_parser = parser_with_context!(flat_text_element)(initial_context);
many_till(text_element_parser, paragraph_end)(input)
pub fn paragraph<'a, F>(
i: &'a str,
context: &mut NomContext<F>,
) -> Res<&'a str, (Vec<TextElement<'a>>, &'a str)>
where
F: for<'b> FnMut(&'b str) -> IResult<&'b str, &'b str, VerboseError<&'b str>>,
F: Clone,
{
let text_element_parser = parser_with_context!(flat_text_element)(context.clone());
many_till(text_element_parser, paragraph_end)(i)
}