Move the paragraph context into the paragraph parser.

This commit is contained in:
Tom Alexander 2022-11-26 17:51:07 -05:00
parent c312673f12
commit 185c761a5d
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 9 additions and 5 deletions

View File

@ -130,12 +130,14 @@ pub fn link_end(input: &str) -> Res<&str, TextElement> {
}
pub fn paragraph_end(input: &str) -> Res<&str, &str> {
recognize(tuple((map(line_break, TextElement::LineBreak), blank_line)))(input)
recognize(tuple((
map(line_break, TextElement::LineBreak),
many1(blank_line),
)))(input)
}
pub fn document(input: &str) -> Res<&str, Vec<(Vec<TextElement>, &str)>> {
let initial_context = ContextTree::new();
let paragraph_context = initial_context.with_additional_fail_matcher(&paragraph_end);
let ret = many1(parser_with_context!(paragraph)(&paragraph_context))(input);
let ret = many1(parser_with_context!(paragraph)(&initial_context))(input);
ret
}

View File

@ -84,6 +84,8 @@ pub fn paragraph<'s, 'r>(
i: &'s str,
context: &'r OrgModeContext<'r>,
) -> Res<&'s str, (Vec<TextElement<'s>>, &'s str)> {
let text_element_parser = parser_with_context!(flat_text_element)(context);
many_till(text_element_parser, paragraph_end)(i)
let paragraph_context = context.with_additional_fail_matcher(&paragraph_end);
let text_element_parser = parser_with_context!(flat_text_element)(&paragraph_context);
let ret = many_till(text_element_parser, paragraph_end)(i);
ret
}