Fix handling of whitespace at the end of paragraphs and mandatory whitespace in list items.
This commit is contained in:
@@ -16,8 +16,10 @@ 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::character::complete::space1;
|
||||
use nom::combinator::eof;
|
||||
use nom::combinator::recognize;
|
||||
use nom::combinator::verify;
|
||||
@@ -57,24 +59,42 @@ pub fn plain_list_item<'r, 's>(
|
||||
|
||||
let element_matcher = parser_with_context!(element)(&parser_context);
|
||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
||||
let (remaining, (bull, _ws)) = tuple((bullet, space0))(remaining)?;
|
||||
let (remaining, (contents, _exit_contents)) =
|
||||
many_till(element_matcher, exit_matcher)(remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
|
||||
Ok((
|
||||
remaining,
|
||||
PlainListItem {
|
||||
source,
|
||||
indentation: indent_level,
|
||||
bullet: bull,
|
||||
contents,
|
||||
},
|
||||
))
|
||||
let (remaining, bull) = bullet(remaining)?;
|
||||
let maybe_contentless_item: Res<&str, &str> = alt((eof, line_ending))(remaining);
|
||||
match maybe_contentless_item {
|
||||
Ok((rem, _ws)) => {
|
||||
let source = get_consumed(input, rem);
|
||||
return Ok((
|
||||
rem,
|
||||
PlainListItem {
|
||||
source,
|
||||
indentation: indent_level,
|
||||
bullet: bull,
|
||||
contents: Vec::new(),
|
||||
},
|
||||
));
|
||||
}
|
||||
Err(_) => {
|
||||
let (remaining, _ws) = space1(remaining)?;
|
||||
let (remaining, (contents, _exit_contents)) =
|
||||
many_till(element_matcher, exit_matcher)(remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
return Ok((
|
||||
remaining,
|
||||
PlainListItem {
|
||||
source,
|
||||
indentation: indent_level,
|
||||
bullet: bull,
|
||||
contents,
|
||||
},
|
||||
));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
fn bullet<'s>(i: &'s str) -> Res<&'s str, &'s str> {
|
||||
// TODO: If asterisk, it cannot be at start of line or it would be a headline
|
||||
alt((
|
||||
tag("*"),
|
||||
tag("-"),
|
||||
|
||||
Reference in New Issue
Block a user