From 7b8fa1eb4a77c91be74aa8a6d4566b822a515db3 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 15 Dec 2023 13:21:58 -0500 Subject: [PATCH] Fix get_contents for sections. --- src/parser/section.rs | 11 ++++------- src/types/document.rs | 3 +-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/parser/section.rs b/src/parser/section.rs index d762cda..487281c 100644 --- a/src/parser/section.rs +++ b/src/parser/section.rs @@ -1,4 +1,3 @@ -use nom::combinator::consumed; use nom::combinator::opt; use nom::combinator::recognize; use nom::combinator::verify; @@ -59,12 +58,12 @@ pub(crate) fn zeroth_section<'b, 'g, 'r, 's>( many0(blank_line), )))(input)?; - let (remaining, (contents, (mut children, _exit_contents))) = consumed(verify( + let (remaining, (mut children, _exit_contents)) = verify( many_till(element_matcher, exit_matcher), |(children, _exit_contents)| { !children.is_empty() || comment_and_property_drawer_element.is_some() }, - ))(remaining)?; + )(remaining)?; if let Some((comment, property_drawer, _ws)) = comment_and_property_drawer_element { children.insert(0, Element::PropertyDrawer(property_drawer)); @@ -81,7 +80,6 @@ pub(crate) fn zeroth_section<'b, 'g, 'r, 's>( remaining, Section { source: source.into(), - contents: Some(contents.into()), post_blank: post_blank.map(Into::<&str>::into), children, }, @@ -118,12 +116,12 @@ pub(crate) fn section<'b, 'g, 'r, 's>( remaining = remain; input = remain; } - let (remaining, (contents, (mut children, _exit_contents))) = consumed(verify( + let (remaining, (mut children, _exit_contents)) = verify( many_till(element_matcher, exit_matcher), |(children, _exit_contents)| { !children.is_empty() || property_drawer_element.is_some() || planning_element.is_some() }, - ))(remaining)?; + )(remaining)?; if let Some(ele) = property_drawer_element.map(Element::PropertyDrawer) { children.insert(0, ele); } @@ -139,7 +137,6 @@ pub(crate) fn section<'b, 'g, 'r, 's>( remaining, Section { source: source.into(), - contents: Some(contents.into()), post_blank: post_blank.map(Into::<&str>::into), children, }, diff --git a/src/types/document.rs b/src/types/document.rs index f0bfa74..bfe0083 100644 --- a/src/types/document.rs +++ b/src/types/document.rs @@ -41,7 +41,6 @@ pub struct Heading<'s> { #[derive(Debug)] pub struct Section<'s> { pub source: &'s str, - pub contents: Option<&'s str>, pub post_blank: Option<&'s str>, pub children: Vec>, } @@ -102,7 +101,7 @@ impl<'s> StandardProperties<'s> for Section<'s> { } fn get_contents<'b>(&'b self) -> Option<&'s str> { - self.contents + Some(self.source) } fn get_post_blank(&self) -> PostBlank {