From a276ba70e07c03936f2808956c09945aa07145f0 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 17 Oct 2023 15:56:02 -0400 Subject: [PATCH] Fix empty content items with final item whitespace cut-off before headlines. --- src/parser/plain_list.rs | 15 +++++++++++---- src/parser/util.rs | 4 ++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index e47f2979..91aeceb7 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -113,7 +113,9 @@ pub(crate) fn detect_not_plain_list_item_indent<'b, 'g, 'r, 's>( alt((space1, line_ending, eof)), )), )), - |(_, (depth, bullet), (_, _))| *depth == 0 && Into::<&str>::into(bullet).starts_with('*'), + |(_, (depth, _), ((_, bullet), _))| { + *depth == 0 && Into::<&str>::into(bullet).starts_with('*') + }, )(input) { return Ok((input, indent)); @@ -263,10 +265,15 @@ fn plain_list_item<'b, 'g, 'r, 's>( let maybe_contentless_item: Res, ()> = detect_contentless_item_contents(&parser_context, remaining); if let Ok((_rem, _ws)) = maybe_contentless_item { - let (remaining, _trailing_ws) = if context.should_consume_trailing_whitespace() { - recognize(alt((recognize(many1(blank_line)), eof)))(remaining)? - } else { + let (remaining, _trailing_ws) = if tuple(( + blank_line, + bind_context!(final_item_whitespace_cutoff, context), + ))(remaining) + .is_ok() + { recognize(alt((blank_line, eof)))(remaining)? + } else { + recognize(alt((recognize(many1(blank_line)), eof)))(remaining)? }; let source = get_consumed(input, remaining); return Ok(( diff --git a/src/parser/util.rs b/src/parser/util.rs index 538f2b9f..82f12506 100644 --- a/src/parser/util.rs +++ b/src/parser/util.rs @@ -243,6 +243,10 @@ pub(crate) fn org_line_ending(input: OrgSource<'_>) -> Res, OrgSou } /// Match the whitespace at the beginning of a line and give it an indentation level. +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn indentation_level<'s>( context: RefContext<'_, '_, '_, 's>, input: OrgSource<'s>,