Move handling of contentless item to handle contentless description item.

This commit is contained in:
Tom Alexander 2023-08-31 17:25:42 -04:00
parent bfc9e7f58d
commit 0fcb3f73f9
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -144,29 +144,32 @@ pub fn plain_list_item<'r, 's>(
Into::<&str>::into(bull) != "*" || indent_level > 0 Into::<&str>::into(bull) != "*" || indent_level > 0
})(remaining)?; })(remaining)?;
let maybe_contentless_item: Res<OrgSource<'_>, OrgSource<'_>> = eof(remaining); let (remaining, maybe_tag) = opt(tuple((
space1,
parser_with_context!(item_tag)(context),
tag(" ::"),
)))(remaining)?;
let maybe_contentless_item: Res<OrgSource<'_>, OrgSource<'_>> =
peek(recognize(tuple((many0(blank_line), eof))))(remaining);
match maybe_contentless_item { match maybe_contentless_item {
Ok((rem, _ws)) => { Ok((_rem, _ws)) => {
let source = get_consumed(input, rem); let (remaining, _trailing_ws) = opt(blank_line)(remaining)?;
let source = get_consumed(input, remaining);
return Ok(( return Ok((
rem, remaining,
PlainListItem { PlainListItem {
source: source.into(), source: source.into(),
indentation: indent_level, indentation: indent_level,
bullet: bull.into(), bullet: bull.into(),
tag: Vec::new(), tag: maybe_tag
.map(|(_ws, item_tag, _divider)| item_tag)
.unwrap_or(Vec::new()),
children: Vec::new(), children: Vec::new(),
}, },
)); ));
} }
Err(_) => {} 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 (remaining, _ws) = item_tag_post_gap(context, remaining)?;
let exit_matcher = plain_list_item_end(indent_level); let exit_matcher = plain_list_item_end(indent_level);
let parser_context = context let parser_context = context
@ -184,11 +187,12 @@ pub fn plain_list_item<'r, 's>(
if !children.is_empty() && !context.should_consume_trailing_whitespace() { if !children.is_empty() && !context.should_consume_trailing_whitespace() {
let final_item_context = let final_item_context =
parser_context.with_additional_node(ContextElement::ConsumeTrailingWhitespace(false)); 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 (final_child_start, _original_final_child) = children
let (remain, reparsed_final_element) = .pop()
include_input(parser_with_context!(element(true))(&final_item_context))( .expect("if-statement already checked that children was non-empty.");
final_child_start, let (remain, reparsed_final_element) = include_input(parser_with_context!(element(true))(
)?; &final_item_context,
))(final_child_start)?;
remaining = remain; remaining = remain;
children.push(reparsed_final_element); children.push(reparsed_final_element);
} }