From 7ce9dafd96c2c6de14f8a82b3ca0d4f2ad9c5b8f Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 21 Jul 2023 18:52:02 -0400 Subject: [PATCH] Fix parsing citations inside paragraphs. --- org_mode_samples/citation/simple.org | 2 ++ src/parser/citation.rs | 2 ++ src/parser/object_parser.rs | 6 ++---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/org_mode_samples/citation/simple.org b/org_mode_samples/citation/simple.org index a48b60c..9af9473 100644 --- a/org_mode_samples/citation/simple.org +++ b/org_mode_samples/citation/simple.org @@ -1,3 +1,5 @@ [cite:@foo] [cite/a/b-_/foo:globalprefix;keyprefix @foo keysuffix;globalsuffix] + +text before [cite:@bar] text after diff --git a/src/parser/citation.rs b/src/parser/citation.rs index 19510f1..fa8a5ee 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::character::complete::space0; use nom::combinator::opt; use nom::combinator::recognize; use nom::combinator::verify; @@ -41,6 +42,7 @@ pub fn citation<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str parser_with_context!(global_suffix)(context), )))(remaining)?; let (remaining, _) = tag("]")(remaining)?; + let (remaining, _) = space0(remaining)?; let source = get_consumed(input, remaining); Ok((remaining, Citation { source })) } diff --git a/src/parser/object_parser.rs b/src/parser/object_parser.rs index 2eeebaf..4693ac6 100644 --- a/src/parser/object_parser.rs +++ b/src/parser/object_parser.rs @@ -29,10 +29,7 @@ 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!(citation)(context), Object::Citation), map( parser_with_context!(footnote_reference)(context), Object::FootnoteReference, @@ -89,6 +86,7 @@ pub fn any_object_except_plain_text<'r, 's>( ) -> Res<&'s str, Object<'s>> { // Used for exit matchers so this does not check exit matcher condition. alt(( + map(parser_with_context!(citation)(context), Object::Citation), map( parser_with_context!(footnote_reference)(context), Object::FootnoteReference,