Implement the new fields for property drawer.

This commit is contained in:
Tom Alexander 2023-12-15 13:03:42 -05:00
parent 57f566a7a1
commit bb472b63cc
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 29 additions and 8 deletions

View File

@ -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<OrgSource<'s>, Vec<NodeProperty<'s>>> {
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))

View File

@ -103,6 +103,8 @@ pub struct Drawer<'s> {
pub struct PropertyDrawer<'s> {
pub source: &'s str,
pub children: Vec<NodeProperty<'s>>,
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.")
}
}