From 3643f91bac8fd80622f095e99e8d2fa2eaad3a6a Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 27 Mar 2023 18:50:25 -0400 Subject: [PATCH] The current problem is whitespace at the end of a list item should not be consumed. --- src/parser/paragraph.rs | 9 ++++++++- src/parser/plain_list.rs | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/parser/paragraph.rs b/src/parser/paragraph.rs index 0c916a4..b0e6d2f 100644 --- a/src/parser/paragraph.rs +++ b/src/parser/paragraph.rs @@ -2,7 +2,9 @@ use nom::branch::alt; use nom::character::complete::line_ending; use nom::combinator::eof; use nom::combinator::recognize; +use nom::combinator::verify; use nom::multi::many1; +use nom::multi::many_till; use nom::sequence::tuple; use crate::parser::object::standard_set_object; @@ -10,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::exit_matcher_parser; use super::element::non_paragraph_element; use super::error::Res; @@ -26,8 +29,12 @@ pub fn paragraph<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s st exit_matcher: ChainBehavior::AndParent(Some(¶graph_end)), })); let standard_set_object_matcher = parser_with_context!(standard_set_object)(&parser_context); + let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); - let (remaining, children) = many1(standard_set_object_matcher)(input)?; + let (remaining, (children, _exit_contents)) = verify( + many_till(standard_set_object_matcher, exit_matcher), + |(children, _exit_contents)| !children.is_empty(), + )(input)?; let (remaining, _trailing_whitespace) = trailing_whitespace(remaining)?; diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index 9e46121..9743fd6 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -16,6 +16,7 @@ use crate::parser::util::start_of_line; use nom::branch::alt; use nom::bytes::complete::tag; use nom::character::complete::digit1; +use nom::character::complete::line_ending; use nom::character::complete::one_of; use nom::character::complete::space0; use nom::combinator::eof; @@ -94,8 +95,8 @@ fn plain_list_item_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res< let plain_list_item_matcher = parser_with_context!(plain_list_item)(context); let line_indented_lte_matcher = parser_with_context!(line_indented_lte)(context); alt(( - recognize(plain_list_item_matcher), - line_indented_lte_matcher, + recognize(tuple((line_ending, plain_list_item_matcher))), + recognize(tuple((line_ending, line_indented_lte_matcher))), eof, ))(input) }