From 0fcb3f73f9d9326115af262bb63f715640f94e05 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 31 Aug 2023 17:25:42 -0400 Subject: [PATCH] Move handling of contentless item to handle contentless description item. --- src/parser/plain_list.rs | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index ea4d54f..a2cc7c2 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -144,29 +144,32 @@ pub fn plain_list_item<'r, 's>( Into::<&str>::into(bull) != "*" || indent_level > 0 })(remaining)?; - let maybe_contentless_item: Res, OrgSource<'_>> = eof(remaining); + let (remaining, maybe_tag) = opt(tuple(( + space1, + parser_with_context!(item_tag)(context), + tag(" ::"), + )))(remaining)?; + let maybe_contentless_item: Res, OrgSource<'_>> = + peek(recognize(tuple((many0(blank_line), eof))))(remaining); match maybe_contentless_item { - Ok((rem, _ws)) => { - let source = get_consumed(input, rem); + Ok((_rem, _ws)) => { + let (remaining, _trailing_ws) = opt(blank_line)(remaining)?; + let source = get_consumed(input, remaining); return Ok(( - rem, + remaining, PlainListItem { source: source.into(), indentation: indent_level, bullet: bull.into(), - tag: Vec::new(), + tag: maybe_tag + .map(|(_ws, item_tag, _divider)| item_tag) + .unwrap_or(Vec::new()), children: Vec::new(), }, )); } Err(_) => {} }; - - let (remaining, maybe_tag) = opt(tuple(( - space1, - parser_with_context!(item_tag)(context), - tag(" ::"), - )))(remaining)?; let (remaining, _ws) = item_tag_post_gap(context, remaining)?; let exit_matcher = plain_list_item_end(indent_level); let parser_context = context @@ -184,11 +187,12 @@ pub fn plain_list_item<'r, 's>( if !children.is_empty() && !context.should_consume_trailing_whitespace() { let final_item_context = parser_context.with_additional_node(ContextElement::ConsumeTrailingWhitespace(false)); - let (final_child_start, _original_final_child) = children.pop().expect("if-statement already checked that children was non-empty."); - let (remain, reparsed_final_element) = - include_input(parser_with_context!(element(true))(&final_item_context))( - final_child_start, - )?; + let (final_child_start, _original_final_child) = children + .pop() + .expect("if-statement already checked that children was non-empty."); + let (remain, reparsed_final_element) = include_input(parser_with_context!(element(true))( + &final_item_context, + ))(final_child_start)?; remaining = remain; children.push(reparsed_final_element); }