diff --git a/src/parser/citation.rs b/src/parser/citation.rs index a56beab..59421c9 100644 --- a/src/parser/citation.rs +++ b/src/parser/citation.rs @@ -2,6 +2,7 @@ use nom::branch::alt; use nom::bytes::complete::tag; use nom::bytes::complete::tag_no_case; use nom::character::complete::anychar; +use nom::combinator::map; use nom::combinator::opt; use nom::combinator::recognize; use nom::combinator::verify; @@ -37,17 +38,17 @@ pub(crate) fn citation<'b, 'g, 'r, 's>( ) -> Res, Citation<'s>> { // TODO: Despite being a standard object, citations cannot exist inside the global prefix/suffix for other citations because citations must contain something that matches @key which is forbidden inside the global prefix/suffix. This TODO is to evaluate if its worth putting in an explicit check for this (which can be easily accomplished by checking the output of `get_bracket_depth()`). I suspect its not worth it because I expect, outside of intentionally crafted inputs, this parser will exit immediately inside a citation since it is unlikely to find the "[cite" substring inside a citation global prefix/suffix. let (remaining, _) = tag_no_case("[cite")(input)?; - let (remaining, _) = opt(citestyle)(remaining)?; + let (remaining, style) = opt(citestyle)(remaining)?; let (remaining, _) = tag(":")(remaining)?; - let (remaining, _prefix) = + let (remaining, prefix) = must_balance_bracket(opt(parser_with_context!(global_prefix)(context)))(remaining)?; - let (remaining, _references) = + let (remaining, references) = separated_list1(tag(";"), parser_with_context!(citation_reference)(context))(remaining)?; - let (remaining, _suffix) = must_balance_bracket(opt(tuple(( - tag(";"), - parser_with_context!(global_suffix)(context), - ))))(remaining)?; + let (remaining, suffix) = must_balance_bracket(opt(map( + tuple((tag(";"), parser_with_context!(global_suffix)(context))), + |(_, suffix)| suffix, + )))(remaining)?; let (remaining, _) = tag("]")(remaining)?; let (remaining, _trailing_whitespace) = maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?; @@ -56,6 +57,10 @@ pub(crate) fn citation<'b, 'g, 'r, 's>( remaining, Citation { source: source.into(), + style: style.map(Into::<&str>::into), + prefix: prefix.unwrap_or(Vec::new()), + suffix: suffix.unwrap_or(Vec::new()), + children: references, }, )) } diff --git a/src/types/object.rs b/src/types/object.rs index f8b88d9..7d7e287 100644 --- a/src/types/object.rs +++ b/src/types/object.rs @@ -200,6 +200,10 @@ pub struct FootnoteReference<'s> { #[derive(Debug, PartialEq)] pub struct Citation<'s> { pub source: &'s str, + pub style: Option<&'s str>, + pub prefix: Vec>, + pub suffix: Vec>, + pub children: Vec>, } #[derive(Debug, PartialEq)]