Implement the new fields for paragraph.

This commit is contained in:
Tom Alexander 2023-10-31 23:06:43 -04:00
parent 92d15c3d91
commit 281c35677b
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 22 additions and 11 deletions

View File

@ -74,7 +74,7 @@ fn anonymous_footnote<'b, 'g, 'r, 's>(
let (remaining, _) = tag("]")(remaining)?;
let (remaining, _trailing_whitespace) =
let (remaining, post_blank) =
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
let source = get_consumed(input, remaining);
Ok((
@ -82,7 +82,7 @@ fn anonymous_footnote<'b, 'g, 'r, 's>(
FootnoteReference {
source: source.into(),
contents: Some(contents.into()),
post_blank: _trailing_whitespace.map(Into::<&str>::into),
post_blank: post_blank.map(Into::<&str>::into),
label: None,
definition: children,
},
@ -123,7 +123,7 @@ fn inline_footnote<'b, 'g, 'r, 's>(
let (remaining, _) = tag("]")(remaining)?;
let (remaining, _trailing_whitespace) =
let (remaining, post_blank) =
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
let source = get_consumed(input, remaining);
Ok((
@ -131,7 +131,7 @@ fn inline_footnote<'b, 'g, 'r, 's>(
FootnoteReference {
source: source.into(),
contents: Some(contents.into()),
post_blank: _trailing_whitespace.map(Into::<&str>::into),
post_blank: post_blank.map(Into::<&str>::into),
label: Some(label_contents.into()),
definition: children,
},
@ -149,7 +149,7 @@ fn footnote_reference_only<'b, 'g, 'r, 's>(
let (remaining, _) = tag_no_case("[fn:")(input)?;
let (remaining, label_contents) = label(remaining)?;
let (remaining, _) = tag("]")(remaining)?;
let (remaining, _trailing_whitespace) =
let (remaining, post_blank) =
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
let source = get_consumed(input, remaining);
Ok((
@ -157,7 +157,7 @@ fn footnote_reference_only<'b, 'g, 'r, 's>(
FootnoteReference {
source: source.into(),
contents: None,
post_blank: _trailing_whitespace.map(Into::<&str>::into),
post_blank: post_blank.map(Into::<&str>::into),
label: Some(label_contents.into()),
definition: Vec::with_capacity(0),
},

View File

@ -1,4 +1,5 @@
use nom::branch::alt;
use nom::combinator::consumed;
use nom::combinator::eof;
use nom::combinator::recognize;
use nom::combinator::verify;
@ -45,14 +46,14 @@ where
let standard_set_object_matcher = parser_with_context!(standard_set_object)(&parser_context);
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
let (remaining, (children, _exit_contents)) = verify(
let (remaining, (contents, (children, _exit_contents))) = consumed(verify(
many_till(standard_set_object_matcher, exit_matcher),
|(children, _exit_contents)| !children.is_empty(),
)(remaining)?;
))(remaining)?;
// Not checking parent exit matcher because if there are any children matched then we have a valid paragraph.
let (remaining, _trailing_ws) =
let (remaining, post_blank) =
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
let source = get_consumed(input, remaining);
@ -60,6 +61,8 @@ where
remaining,
Paragraph {
source: source.into(),
contents: Some(contents.into()),
post_blank: post_blank.map(Into::<&str>::into),
affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,

View File

@ -25,6 +25,8 @@ use crate::error::Res;
#[derive(Debug)]
pub struct Paragraph<'s> {
pub source: &'s str,
pub contents: Option<&'s str>,
pub post_blank: Option<&'s str>,
pub affiliated_keywords: AffiliatedKeywords<'s>,
pub children: Vec<Object<'s>>,
}
@ -189,6 +191,8 @@ impl<'s> Paragraph<'s> {
pub(crate) fn of_text(source: &'s str, body: &'s str) -> Self {
Paragraph {
source,
contents: None, // TODO
post_blank: None, // TODO
affiliated_keywords: AffiliatedKeywords::default(),
children: vec![Object::PlainText(PlainText { source: body })],
}
@ -201,11 +205,15 @@ impl<'s> StandardProperties<'s> for Paragraph<'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.")
}
}