Fix simple citations by making prefixes and suffixes optional.
This commit is contained in:
parent
4ad297f58a
commit
1a8bf01fba
@ -29,13 +29,14 @@ use crate::parser::Object;
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn citation<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, 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, _) = tag(":")(remaining)?;
|
||||
let (remaining, _prefix) = parser_with_context!(global_prefix)(context)(remaining)?;
|
||||
let (remaining, _prefix) = opt(parser_with_context!(global_prefix)(context))(remaining)?;
|
||||
let (remaining, _references) =
|
||||
many0(parser_with_context!(citation_reference)(context))(remaining)?;
|
||||
let (remaining, _suffix) = parser_with_context!(global_suffix)(context)(remaining)?;
|
||||
let (remaining, _suffix) = opt(parser_with_context!(global_suffix)(context))(remaining)?;
|
||||
let (remaining, _) = tag("]")(remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((remaining, Citation { source }))
|
||||
|
@ -2,6 +2,7 @@ use nom::branch::alt;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::character::complete::anychar;
|
||||
use nom::combinator::not;
|
||||
use nom::combinator::opt;
|
||||
use nom::combinator::recognize;
|
||||
use nom::combinator::verify;
|
||||
use nom::multi::many1;
|
||||
@ -29,9 +30,9 @@ pub fn citation_reference<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, CitationReference<'s>> {
|
||||
let (remaining, _prefix) = parser_with_context!(key_prefix)(context)(input)?;
|
||||
let (remaining, _prefix) = opt(parser_with_context!(key_prefix)(context))(input)?;
|
||||
let (remaining, _key) = parser_with_context!(citation_reference_key)(context)(remaining)?;
|
||||
let (remaining, _suffix) = parser_with_context!(key_suffix)(context)(remaining)?;
|
||||
let (remaining, _suffix) = opt(parser_with_context!(key_suffix)(context))(remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
|
||||
Ok((remaining, CitationReference { source }))
|
||||
|
@ -8,6 +8,7 @@ use super::regular_link::regular_link;
|
||||
use super::Context;
|
||||
use crate::error::Res;
|
||||
use crate::parser::angle_link::angle_link;
|
||||
use crate::parser::citation::citation;
|
||||
use crate::parser::entity::entity;
|
||||
use crate::parser::export_snippet::export_snippet;
|
||||
use crate::parser::footnote_reference::footnote_reference;
|
||||
@ -28,6 +29,10 @@ pub fn standard_set_object<'r, 's>(
|
||||
not(|i| context.check_exit_matcher(i))(input)?;
|
||||
|
||||
alt((
|
||||
map(
|
||||
parser_with_context!(citation)(context),
|
||||
Object::Citation,
|
||||
),
|
||||
map(
|
||||
parser_with_context!(footnote_reference)(context),
|
||||
Object::FootnoteReference,
|
||||
|
Loading…
Reference in New Issue
Block a user