From 840dc0a7508fcac259f1f7453fde40b077f58b4d Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 9 Oct 2023 14:02:27 -0400 Subject: [PATCH] Support text markup at the start of a regular link description. --- src/context/context.rs | 6 +++--- src/parser/radio_link.rs | 2 +- src/parser/regular_link.rs | 14 +++++++++----- src/parser/text_markup.rs | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/context/context.rs b/src/context/context.rs index 138338f..6787273 100644 --- a/src/context/context.rs +++ b/src/context/context.rs @@ -33,10 +33,10 @@ pub(crate) enum ContextElement<'r, 's> { /// The value stored is the start of the element after the affiliated keywords. In this way, we can ensure that we do not exit an element immediately after the affiliated keyword had been consumed. HasAffiliatedKeyword(HasAffiliatedKeywordInner<'r, 's>), - /// Indicate the position that we started parsing a radio target. + /// Indicate the position that we started parsing a text section. /// - /// This value is stored because "<<<" is not a valid prefix for text markup UNLESS it is starting a radio target. - StartRadioTarget(OrgSource<'s>), + /// This value is stored because "<<<" is not a valid prefix for text markup UNLESS it is starting a radio target. Likewise "[" is not a valid prefix for text markup UNLESS it is the start of a regular link description. + StartTextSection(OrgSource<'s>), /// This is just here to use the 's lifetime until I'm sure we can eliminate it from ContextElement. #[allow(dead_code)] diff --git a/src/parser/radio_link.rs b/src/parser/radio_link.rs index 15eb6cd..c25ec3c 100644 --- a/src/parser/radio_link.rs +++ b/src/parser/radio_link.rs @@ -108,7 +108,7 @@ pub(crate) fn radio_target<'b, 'g, 'r, 's>( class: ExitClass::Gamma, exit_matcher: &radio_target_end, }), - ContextElement::StartRadioTarget(remaining), + ContextElement::StartTextSection(remaining), ]; let parser_context = context.with_additional_node(&contexts[0]); let parser_context = parser_context.with_additional_node(&contexts[1]); diff --git a/src/parser/regular_link.rs b/src/parser/regular_link.rs index 199829c..ce9ce37 100644 --- a/src/parser/regular_link.rs +++ b/src/parser/regular_link.rs @@ -397,11 +397,15 @@ fn description<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { - let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Beta, - exit_matcher: &description_end, - }); - let parser_context = context.with_additional_node(&parser_context); + let contexts = [ + ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Beta, + exit_matcher: &description_end, + }), + ContextElement::StartTextSection(input), + ]; + let parser_context = context.with_additional_node(&contexts[0]); + let parser_context = parser_context.with_additional_node(&contexts[1]); let (remaining, (children, _exit_contents)) = verify( many_till( parser_with_context!(regular_link_description_set_object)(&parser_context), diff --git a/src/parser/text_markup.rs b/src/parser/text_markup.rs index d666633..7bf7bf1 100644 --- a/src/parser/text_markup.rs +++ b/src/parser/text_markup.rs @@ -295,7 +295,7 @@ fn pre<'b, 'g, 'r, 's>( let radio_target_start = context .iter() .find_map(|c| match c { - ContextElement::StartRadioTarget(text) => Some(text), + ContextElement::StartTextSection(text) => Some(text), _ => None, }) .map(|text| text.get_byte_offset());