From c6fd04e9ce0cef1519af77dec6c0f2b0c168fdb8 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 19 Apr 2023 14:30:02 -0400 Subject: [PATCH] Fix footnote definition end matcher detecting the next footnote definition. --- src/parser/footnote_definition.rs | 16 +++++++++++++--- toy_language.txt | 13 ++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/parser/footnote_definition.rs b/src/parser/footnote_definition.rs index 6f4fa12..ab07ab6 100644 --- a/src/parser/footnote_definition.rs +++ b/src/parser/footnote_definition.rs @@ -83,10 +83,18 @@ fn footnote_definition_end<'r, 's>( input: &'s str, ) -> Res<&'s str, &'s str> { let start_of_line_matcher = parser_with_context!(start_of_line)(context); - let footnote_definition_matcher = parser_with_context!(footnote_definition)(context); + let allow_nesting_context = + context.with_additional_node(ContextElement::Context("allow nesting footnotes")); + let footnote_definition_matcher = parser_with_context!(footnote_definition)( + if immediate_in_section(context, "footnote definition") { + &allow_nesting_context + } else { + context + }, + ); let maybe_consume_trailing_whitespace_matcher = parser_with_context!(maybe_consume_trailing_whitespace)(context); - alt(( + let (remaining, source) = alt(( recognize(tuple(( maybe_consume_trailing_whitespace_matcher, footnote_definition_matcher, @@ -95,7 +103,9 @@ fn footnote_definition_end<'r, 's>( start_of_line_matcher, verify(many1(blank_line), |lines: &Vec<&str>| lines.len() >= 2), ))), - ))(input) + ))(input)?; + + Ok((remaining, source)) } #[cfg(test)] diff --git a/toy_language.txt b/toy_language.txt index 8b8048b..0c7d856 100644 --- a/toy_language.txt +++ b/toy_language.txt @@ -1,5 +1,8 @@ -:firstdrawer: -:seconddrawer: -foo -:end: -:end: +[fn:1] A footnote. + +[fn:2] A multi- + +line footnote. + + +not in the footnote.