From 7a4dc20dc9d03d68f2646c67f509d2d4aa09ccfb Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 15 Dec 2023 15:55:36 -0500 Subject: [PATCH] Implement the new fields for plain list. --- src/parser/plain_list.rs | 6 +++++- src/types/greater_element.rs | 10 ++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index 192647d5..cf1eae1f 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -153,6 +153,7 @@ where let mut children = Vec::new(); let mut first_item_indentation: Option = None; let mut first_item_list_type: Option = None; + let contents_begin = remaining; let mut remaining = remaining; // The final list item does not consume trailing blank lines (which instead get consumed by the list). We have three options here: @@ -196,7 +197,8 @@ where ))); } - let (remaining, _trailing_ws) = + let contents = get_consumed(contents_begin, remaining); + let (remaining, post_blank) = maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?; let source = get_consumed(input, remaining); Ok(( @@ -209,6 +211,8 @@ where ), list_type: first_item_list_type.expect("Plain lists require at least one element."), children: children.into_iter().map(|(_start, item)| item).collect(), + contents: Some(Into::<&str>::into(contents)), + post_blank: post_blank.map(Into::<&str>::into), }, )) } diff --git a/src/types/greater_element.rs b/src/types/greater_element.rs index ae6f7df8..f43cf13a 100644 --- a/src/types/greater_element.rs +++ b/src/types/greater_element.rs @@ -13,6 +13,8 @@ pub struct PlainList<'s> { pub affiliated_keywords: AffiliatedKeywords<'s>, pub list_type: PlainListType, pub children: Vec>, + pub contents: Option<&'s str>, // TODO: Can contents ever be None? + pub post_blank: Option<&'s str>, } #[derive(Debug, Copy, Clone)] @@ -142,11 +144,15 @@ impl<'s> StandardProperties<'s> for PlainList<'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.") } }