diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index b42ce1b..192647d 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -7,6 +7,7 @@ use nom::character::complete::multispace1; use nom::character::complete::one_of; use nom::character::complete::space0; use nom::character::complete::space1; +use nom::combinator::consumed; use nom::combinator::eof; use nom::combinator::map; use nom::combinator::not; @@ -265,7 +266,7 @@ fn plain_list_item<'b, 'g, 'r, 's>( let maybe_contentless_item: Res, ()> = detect_contentless_item_contents(&parser_context, remaining); if let Ok((_rem, _ws)) = maybe_contentless_item { - let (remaining, _trailing_ws) = if tuple(( + let (remaining, post_blank) = if tuple(( blank_line, bind_context!(final_item_whitespace_cutoff, context), ))(remaining) @@ -291,6 +292,12 @@ fn plain_list_item<'b, 'g, 'r, 's>( .unwrap_or(Vec::new()), pre_blank: 0, children: Vec::new(), + contents: None, + post_blank: if post_blank.len() > 0 { + Some(Into::<&str>::into(post_blank)) + } else { + None + }, }, ), )); @@ -301,13 +308,13 @@ fn plain_list_item<'b, 'g, 'r, 's>( .filter(|b| *b == b'\n') .count(); - let (remaining, (children, _exit_contents)) = many_till( + let (remaining, (contents, (children, _exit_contents))) = consumed(many_till( include_input(bind_context!(element(true), &parser_context)), bind_context!(exit_matcher_parser, &parser_context), - )(remaining)?; + ))(remaining)?; // We have to use the parser_context here to include the whitespace cut-off - let (remaining, _trailing_ws) = + let (remaining, post_blank) = maybe_consume_trailing_whitespace_if_not_exiting(&final_whitespace_context, remaining)?; let source = get_consumed(input, remaining); @@ -329,6 +336,12 @@ fn plain_list_item<'b, 'g, 'r, 's>( pre_blank: PlainListItemPreBlank::try_from(pre_blank) .expect("pre-blank cannot be larger than 2."), children: children.into_iter().map(|(_start, item)| item).collect(), + contents: if contents.len() > 0 { + Some(contents.into()) + } else { + None + }, + post_blank: post_blank.map(Into::<&str>::into), }, ), )); diff --git a/src/types/greater_element.rs b/src/types/greater_element.rs index d3e2da1..ae6f7df 100644 --- a/src/types/greater_element.rs +++ b/src/types/greater_element.rs @@ -35,6 +35,8 @@ pub struct PlainListItem<'s> { pub tag: Vec>, pub pre_blank: PlainListItemPreBlank, pub children: Vec>, + pub contents: Option<&'s str>, + pub post_blank: Option<&'s str>, } pub type PlainListItemCounter = u16; @@ -154,11 +156,15 @@ impl<'s> StandardProperties<'s> for PlainListItem<'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.") } }