From 1a41cfc6c79eade0d10b89536c62059a88922b90 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 21 Sep 2023 20:08:04 -0400 Subject: [PATCH] Support detecting line indentation when checking for contentless plain list items. --- .../plain_list/description_list.org | 3 +++ src/parser/plain_list.rs | 25 ++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/org_mode_samples/greater_element/plain_list/description_list.org b/org_mode_samples/greater_element/plain_list/description_list.org index 5bbcedf..1bf7854 100644 --- a/org_mode_samples/greater_element/plain_list/description_list.org +++ b/org_mode_samples/greater_element/plain_list/description_list.org @@ -9,3 +9,6 @@ - big gap :: stuff +- empty value with blank :: + +stuff diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index 1ee06ae..3fbf643 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -168,9 +168,20 @@ fn plain_list_item<'b, 'g, 'r, 's>( let (remaining, maybe_tag) = opt(tuple((space1, parser_with_context!(item_tag)(context))))(remaining)?; + let exit_matcher = plain_list_item_end(indent_level); + let contexts = [ + ContextElement::ConsumeTrailingWhitespace(true), + ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Beta, + exit_matcher: &exit_matcher, + }), + ]; + let parser_context = context.with_additional_node(&contexts[0]); + let parser_context = parser_context.with_additional_node(&contexts[1]); + let maybe_contentless_item: Res, ()> = peek(parser_with_context!( detect_contentless_item_contents - )(context))(remaining); + )(&parser_context))(remaining); match maybe_contentless_item { Ok((_rem, _ws)) => { let (remaining, _trailing_ws) = opt(blank_line)(remaining)?; @@ -191,17 +202,7 @@ fn plain_list_item<'b, 'g, 'r, 's>( } Err(_) => {} }; - let (remaining, _ws) = item_tag_post_gap(context, remaining)?; - let exit_matcher = plain_list_item_end(indent_level); - let contexts = [ - ContextElement::ConsumeTrailingWhitespace(true), - ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Beta, - exit_matcher: &exit_matcher, - }), - ]; - let parser_context = context.with_additional_node(&contexts[0]); - let parser_context = parser_context.with_additional_node(&contexts[1]); + let (remaining, _ws) = item_tag_post_gap(&parser_context, remaining)?; let (mut remaining, (mut children, _exit_contents)) = many_till( include_input(parser_with_context!(element(true))(&parser_context)),