Fix handling of whitespace at the end of paragraphs and mandatory whitespace in list items.

This commit is contained in:
Tom Alexander
2023-04-03 16:29:47 -04:00
parent 0e070f2d4c
commit b5b335b9b0
3 changed files with 59 additions and 21 deletions

View File

@@ -1,5 +1,4 @@
use nom::branch::alt;
use nom::character::complete::line_ending;
use nom::combinator::eof;
use nom::combinator::peek;
use nom::combinator::recognize;
@@ -14,6 +13,7 @@ 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 crate::parser::util::start_of_line;
use super::element::non_paragraph_element;
use super::error::Res;
@@ -32,14 +32,10 @@ pub fn paragraph<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s st
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
let (remaining, (children, _exit_contents)) = verify(
many_till(
standard_set_object_matcher,
peek(alt((eof, recognize(tuple((line_ending, exit_matcher)))))),
),
many_till(standard_set_object_matcher, peek(recognize(exit_matcher))),
|(children, _exit_contents)| !children.is_empty(),
)(input)?;
let (remaining, _linebreak) = alt((eof, line_ending))(remaining)?;
let source = get_consumed(input, remaining);
Ok((remaining, Paragraph { source, children }))
@@ -48,8 +44,9 @@ pub fn paragraph<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s st
#[tracing::instrument(ret, level = "debug")]
fn paragraph_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
let non_paragraph_element_matcher = parser_with_context!(non_paragraph_element)(context);
let start_of_line_matcher = parser_with_context!(start_of_line)(&context);
alt((
recognize(many1(blank_line)),
recognize(tuple((start_of_line_matcher, many1(blank_line)))),
recognize(non_paragraph_element_matcher),
eof,
))(input)