Numerous fixes to property drawers.

This commit is contained in:
Tom Alexander
2023-04-19 19:03:51 -04:00
parent b557b9ca5d
commit 603cc131a0
4 changed files with 37 additions and 19 deletions

View File

@@ -121,20 +121,33 @@ fn zeroth_section<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s s
class: ExitClass::Document,
exit_matcher: &section_end,
}));
let without_consuming_whitespace_context =
parser_context.with_additional_node(ContextElement::ConsumeTrailingWhitespace(false));
let element_matcher = parser_with_context!(element)(&parser_context);
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
let (remaining, (comment_element, property_drawer_element)) = tuple((
opt(parser_with_context!(comment)(&parser_context)),
opt(parser_with_context!(property_drawer)(&parser_context)),
opt(parser_with_context!(comment)(
&without_consuming_whitespace_context,
)),
opt(parser_with_context!(property_drawer)(
&without_consuming_whitespace_context,
)),
))(input)?;
let (remaining, (mut children, _exit_contents)) = verify(
many_till(element_matcher, exit_matcher),
|(children, _exit_contents)| !children.is_empty(),
|(children, _exit_contents)| {
!children.is_empty() || property_drawer_element.is_some() || comment_element.is_some()
},
)(remaining)?;
property_drawer_element.map(Element::PropertyDrawer).map(|ele| children.insert(0, ele));
comment_element.map(Element::Comment).map(|ele| children.insert(0, ele));
property_drawer_element
.map(Element::PropertyDrawer)
.map(|ele| children.insert(0, ele));
comment_element
.map(Element::Comment)
.map(|ele| children.insert(0, ele));
// children.insert(0, item)
let (remaining, _trailing_ws) =
@@ -156,10 +169,15 @@ 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, (children, _exit_contents)) = verify(
let (remaining, property_drawer_element) =
opt(parser_with_context!(property_drawer)(&parser_context))(input)?;
let (remaining, (mut children, _exit_contents)) = verify(
many_till(element_matcher, exit_matcher),
|(children, _exit_contents)| !children.is_empty(),
)(input)?;
|(children, _exit_contents)| !children.is_empty() || property_drawer_element.is_some(),
)(remaining)?;
property_drawer_element
.map(Element::PropertyDrawer)
.map(|ele| children.insert(0, ele));
let (remaining, _trailing_ws) =
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;