Implement the new fields for plain list item.

This commit is contained in:
Tom Alexander 2023-12-15 15:52:53 -05:00
parent 7b88a2d248
commit 022dda06eb
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 25 additions and 6 deletions

View File

@ -7,6 +7,7 @@ use nom::character::complete::multispace1;
use nom::character::complete::one_of; use nom::character::complete::one_of;
use nom::character::complete::space0; use nom::character::complete::space0;
use nom::character::complete::space1; use nom::character::complete::space1;
use nom::combinator::consumed;
use nom::combinator::eof; use nom::combinator::eof;
use nom::combinator::map; use nom::combinator::map;
use nom::combinator::not; use nom::combinator::not;
@ -265,7 +266,7 @@ fn plain_list_item<'b, 'g, 'r, 's>(
let maybe_contentless_item: Res<OrgSource<'_>, ()> = let maybe_contentless_item: Res<OrgSource<'_>, ()> =
detect_contentless_item_contents(&parser_context, remaining); detect_contentless_item_contents(&parser_context, remaining);
if let Ok((_rem, _ws)) = maybe_contentless_item { if let Ok((_rem, _ws)) = maybe_contentless_item {
let (remaining, _trailing_ws) = if tuple(( let (remaining, post_blank) = if tuple((
blank_line, blank_line,
bind_context!(final_item_whitespace_cutoff, context), bind_context!(final_item_whitespace_cutoff, context),
))(remaining) ))(remaining)
@ -291,6 +292,12 @@ fn plain_list_item<'b, 'g, 'r, 's>(
.unwrap_or(Vec::new()), .unwrap_or(Vec::new()),
pre_blank: 0, pre_blank: 0,
children: Vec::new(), 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') .filter(|b| *b == b'\n')
.count(); .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)), include_input(bind_context!(element(true), &parser_context)),
bind_context!(exit_matcher_parser, &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 // 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)?; maybe_consume_trailing_whitespace_if_not_exiting(&final_whitespace_context, remaining)?;
let source = get_consumed(input, 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) pre_blank: PlainListItemPreBlank::try_from(pre_blank)
.expect("pre-blank cannot be larger than 2."), .expect("pre-blank cannot be larger than 2."),
children: children.into_iter().map(|(_start, item)| item).collect(), 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),
}, },
), ),
)); ));

View File

@ -35,6 +35,8 @@ pub struct PlainListItem<'s> {
pub tag: Vec<Object<'s>>, pub tag: Vec<Object<'s>>,
pub pre_blank: PlainListItemPreBlank, pub pre_blank: PlainListItemPreBlank,
pub children: Vec<Element<'s>>, pub children: Vec<Element<'s>>,
pub contents: Option<&'s str>,
pub post_blank: Option<&'s str>,
} }
pub type PlainListItemCounter = u16; pub type PlainListItemCounter = u16;
@ -154,11 +156,15 @@ impl<'s> StandardProperties<'s> for PlainListItem<'s> {
} }
fn get_contents<'b>(&'b self) -> Option<&'s str> { fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!() self.contents
} }
fn get_post_blank(&self) -> PostBlank { 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.")
} }
} }