From bb472b63cc4ffc99d03a64b01b8f6da3aa43345c Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 15 Dec 2023 13:03:42 -0500 Subject: [PATCH] Implement the new fields for property drawer. --- src/parser/property_drawer.rs | 27 +++++++++++++++++++++------ src/types/greater_element.rs | 10 ++++++++-- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/parser/property_drawer.rs b/src/parser/property_drawer.rs index 5cf4d02a..40197f43 100644 --- a/src/parser/property_drawer.rs +++ b/src/parser/property_drawer.rs @@ -6,6 +6,7 @@ use nom::character::complete::anychar; use nom::character::complete::line_ending; use nom::character::complete::space0; use nom::character::complete::space1; +use nom::combinator::consumed; use nom::combinator::eof; use nom::combinator::opt; use nom::combinator::recognize; @@ -64,14 +65,11 @@ pub(crate) fn property_drawer<'b, 'g, 'r, 's>( let parser_context = context.with_additional_node(&contexts[0]); let parser_context = parser_context.with_additional_node(&contexts[1]); let parser_context = parser_context.with_additional_node(&contexts[2]); - - let node_property_matcher = parser_with_context!(node_property)(&parser_context); - let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); - let (remaining, (children, _exit_contents)) = - many_till(node_property_matcher, exit_matcher)(remaining)?; + let (remaining, (contents, children)) = + consumed(parser_with_context!(children)(&parser_context))(remaining)?; let (remaining, _end) = property_drawer_end(&parser_context, remaining)?; - let (remaining, _trailing_ws) = + let (remaining, post_blank) = maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?; let source = get_consumed(input, remaining); @@ -80,10 +78,27 @@ pub(crate) fn property_drawer<'b, 'g, 'r, 's>( PropertyDrawer { source: source.into(), children, + contents: Some(contents.into()), + post_blank: post_blank.map(Into::<&str>::into), }, )) } +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] +fn children<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, + input: OrgSource<'s>, +) -> Res, Vec>> { + let node_property_matcher = parser_with_context!(node_property)(context); + let exit_matcher = parser_with_context!(exit_matcher_parser)(context); + let (remaining, (children, _exit_contents)) = + many_till(node_property_matcher, exit_matcher)(input)?; + Ok((remaining, children)) +} + #[cfg_attr( feature = "tracing", tracing::instrument(ret, level = "debug", skip(_context)) diff --git a/src/types/greater_element.rs b/src/types/greater_element.rs index 05606ccd..6c8ba105 100644 --- a/src/types/greater_element.rs +++ b/src/types/greater_element.rs @@ -103,6 +103,8 @@ pub struct Drawer<'s> { pub struct PropertyDrawer<'s> { pub source: &'s str, pub children: Vec>, + pub contents: Option<&'s str>, + pub post_blank: Option<&'s str>, } #[derive(Debug)] @@ -258,11 +260,15 @@ impl<'s> StandardProperties<'s> for PropertyDrawer<'s> { } fn get_contents<'b>(&'b self) -> Option<&'s str> { - todo!() + self.contents } fn get_post_blank(&self) -> PostBlank { - todo!() + self.post_blank + .map(|text| text.lines().count()) + .unwrap_or(0) + .try_into() + .expect("Too much post-blank to fit into a PostBlank.") } }