diff --git a/src/parser/paragraph.rs b/src/parser/paragraph.rs index dd933f9..ea97408 100644 --- a/src/parser/paragraph.rs +++ b/src/parser/paragraph.rs @@ -1,5 +1,6 @@ use nom::branch::alt; use nom::combinator::eof; +use nom::combinator::opt; use nom::combinator::recognize; use nom::combinator::verify; use nom::multi::many1; @@ -11,6 +12,7 @@ use crate::parser::parser_context::ChainBehavior; use crate::parser::parser_context::ContextElement; use crate::parser::parser_context::ExitMatcherNode; use crate::parser::parser_with_context::parser_with_context; +use crate::parser::util::element_trailing_whitespace; use crate::parser::util::exit_matcher_parser; use crate::parser::util::start_of_line; @@ -35,6 +37,17 @@ pub fn paragraph<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s st |(children, _exit_contents)| !children.is_empty(), )(input)?; + // Check if a parent exit matcher is causing the exit + exit_matcher_parser(context, remaining)?; + + let (remaining, _trailing_ws) = if context.should_consume_trailing_whitespace() { + opt(parser_with_context!(element_trailing_whitespace)( + &parser_context, + ))(remaining)? + } else { + (remaining, None) + }; + let source = get_consumed(input, remaining); Ok((remaining, Paragraph { source, children }))