Only drop trailing whitespace when there isn't a property drawer.

This commit is contained in:
Tom Alexander 2023-04-19 19:39:56 -04:00
parent d0410391cc
commit 87bdedf2e6
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 11 additions and 7 deletions

View File

@ -157,7 +157,7 @@ fn zeroth_section<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s s
}
#[tracing::instrument(ret, level = "debug")]
fn section<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Section<'s>> {
fn section<'r, 's>(context: Context<'r, 's>, mut input: &'s str) -> Res<&'s str, Section<'s>> {
// TODO: The zeroth section is specialized so it probably needs its own parser
let parser_context = context
.with_additional_node(ContextElement::ConsumeTrailingWhitespace(true))
@ -168,8 +168,13 @@ fn section<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Sec
}));
let element_matcher = parser_with_context!(element)(&parser_context);
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
let (remaining, property_drawer_element) =
let (mut remaining, property_drawer_element) =
opt(parser_with_context!(property_drawer)(&parser_context))(input)?;
if property_drawer_element.is_none() {
let (remain, _ws) = many0(blank_line)(remaining)?;
remaining = remain;
input = remain;
}
let (remaining, (mut children, _exit_contents)) = verify(
many_till(element_matcher, exit_matcher),
|(children, _exit_contents)| !children.is_empty() || property_drawer_element.is_some(),
@ -194,7 +199,7 @@ fn section_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str,
#[tracing::instrument(ret, level = "debug")]
fn heading<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Heading<'s>> {
not(|i| context.check_exit_matcher(i))(input)?;
let (remaining, (star_count, _ws, title, _ws2)) = headline(context, input)?;
let (remaining, (star_count, _ws, title)) = headline(context, input)?;
let section_matcher = parser_with_context!(section)(context);
let heading_matcher = parser_with_context!(heading)(context);
let (remaining, children) = many0(alt((
@ -220,7 +225,7 @@ fn heading<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Hea
fn headline<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, (usize, &'s str, Vec<Object<'s>>, &'s str)> {
) -> Res<&'s str, (usize, &'s str, Vec<Object<'s>>)> {
let parser_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Document,
@ -229,14 +234,13 @@ fn headline<'r, 's>(
let standard_set_object_matcher = parser_with_context!(standard_set_object)(&parser_context);
let start_of_line_matcher = parser_with_context!(start_of_line)(&parser_context);
let (remaining, (_sol, star_count, ws, title, ws2)) = tuple((
let (remaining, (_sol, star_count, ws, title)) = tuple((
start_of_line_matcher,
many1_count(tag("*")),
space1,
many1(standard_set_object_matcher),
trailing_whitespace,
))(input)?;
Ok((remaining, (star_count, ws, title, ws2)))
Ok((remaining, (star_count, ws, title)))
}
#[tracing::instrument(ret, level = "debug")]