Fill citation fields.
This commit is contained in:
parent
ced35e1694
commit
1ecc3ecf9d
@ -2,6 +2,7 @@ use nom::branch::alt;
|
|||||||
use nom::bytes::complete::tag;
|
use nom::bytes::complete::tag;
|
||||||
use nom::bytes::complete::tag_no_case;
|
use nom::bytes::complete::tag_no_case;
|
||||||
use nom::character::complete::anychar;
|
use nom::character::complete::anychar;
|
||||||
|
use nom::combinator::map;
|
||||||
use nom::combinator::opt;
|
use nom::combinator::opt;
|
||||||
use nom::combinator::recognize;
|
use nom::combinator::recognize;
|
||||||
use nom::combinator::verify;
|
use nom::combinator::verify;
|
||||||
@ -37,17 +38,17 @@ pub(crate) fn citation<'b, 'g, 'r, 's>(
|
|||||||
) -> Res<OrgSource<'s>, Citation<'s>> {
|
) -> Res<OrgSource<'s>, 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.
|
// 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, _) = tag_no_case("[cite")(input)?;
|
||||||
let (remaining, _) = opt(citestyle)(remaining)?;
|
let (remaining, style) = opt(citestyle)(remaining)?;
|
||||||
let (remaining, _) = tag(":")(remaining)?;
|
let (remaining, _) = tag(":")(remaining)?;
|
||||||
let (remaining, _prefix) =
|
let (remaining, prefix) =
|
||||||
must_balance_bracket(opt(parser_with_context!(global_prefix)(context)))(remaining)?;
|
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)?;
|
separated_list1(tag(";"), parser_with_context!(citation_reference)(context))(remaining)?;
|
||||||
let (remaining, _suffix) = must_balance_bracket(opt(tuple((
|
let (remaining, suffix) = must_balance_bracket(opt(map(
|
||||||
tag(";"),
|
tuple((tag(";"), parser_with_context!(global_suffix)(context))),
|
||||||
parser_with_context!(global_suffix)(context),
|
|(_, suffix)| suffix,
|
||||||
))))(remaining)?;
|
)))(remaining)?;
|
||||||
let (remaining, _) = tag("]")(remaining)?;
|
let (remaining, _) = tag("]")(remaining)?;
|
||||||
let (remaining, _trailing_whitespace) =
|
let (remaining, _trailing_whitespace) =
|
||||||
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
@ -56,6 +57,10 @@ pub(crate) fn citation<'b, 'g, 'r, 's>(
|
|||||||
remaining,
|
remaining,
|
||||||
Citation {
|
Citation {
|
||||||
source: source.into(),
|
source: source.into(),
|
||||||
|
style: style.map(Into::<&str>::into),
|
||||||
|
prefix: prefix.unwrap_or(Vec::new()),
|
||||||
|
suffix: suffix.unwrap_or(Vec::new()),
|
||||||
|
children: references,
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -200,6 +200,10 @@ pub struct FootnoteReference<'s> {
|
|||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct Citation<'s> {
|
pub struct Citation<'s> {
|
||||||
pub source: &'s str,
|
pub source: &'s str,
|
||||||
|
pub style: Option<&'s str>,
|
||||||
|
pub prefix: Vec<Object<'s>>,
|
||||||
|
pub suffix: Vec<Object<'s>>,
|
||||||
|
pub children: Vec<CitationReference<'s>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
|
Loading…
Reference in New Issue
Block a user