diff --git a/src/parser/headline.rs b/src/parser/headline.rs index 6af4336..a836f3c 100644 --- a/src/parser/headline.rs +++ b/src/parser/headline.rs @@ -67,6 +67,7 @@ fn _heading<'b, 'g, 'r, 's>( let section_matcher = bind_context!(section, context); let heading_matcher = bind_context!(heading(pre_headline.star_count), context); let (contents_begin, _) = opt(many0(blank_line))(remaining)?; + let maybe_post_blank = get_consumed(remaining, contents_begin); let (remaining, maybe_section) = opt(map(section_matcher, DocumentElement::Section))(remaining)?; let (remaining, _ws) = opt(tuple((start_of_line, many0(blank_line))))(remaining)?; @@ -83,7 +84,8 @@ fn _heading<'b, 'g, 'r, 's>( } children.insert(0, section); } - let remaining = if children.is_empty() { + let has_children = !children.is_empty(); + let remaining = if !has_children { // Support empty headings let (remain, _ws) = many0(blank_line)(remaining)?; remain @@ -119,6 +121,11 @@ fn _heading<'b, 'g, 'r, 's>( } else { None }, + post_blank: if has_children { + None + } else { + Some(Into::<&str>::into(maybe_post_blank)) + }, }, )) } diff --git a/src/types/document.rs b/src/types/document.rs index df27ff7..9015adc 100644 --- a/src/types/document.rs +++ b/src/types/document.rs @@ -36,6 +36,7 @@ pub struct Heading<'s> { pub deadline: Option>, pub closed: Option>, pub contents: Option<&'s str>, + pub post_blank: Option<&'s str>, } #[derive(Debug)] @@ -105,7 +106,13 @@ impl<'s> StandardProperties<'s> for Heading<'s> { self.children .last() .map(|child| child.get_post_blank()) - .unwrap_or(0) + .unwrap_or( + self.post_blank + .map(|text| text.lines().count()) + .unwrap_or(0) + .try_into() + .expect("Too much post-blank to fit into a PostBlank."), + ) } }