From 6aa656127e791aa47a38a2813d4864133e0d86c1 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 25 Nov 2022 13:55:09 -0500 Subject: [PATCH] Structurally this should be working but bold is not being captured. --- src/parser/text_element_parser.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/parser/text_element_parser.rs b/src/parser/text_element_parser.rs index 0e1004d6..54f1e96b 100644 --- a/src/parser/text_element_parser.rs +++ b/src/parser/text_element_parser.rs @@ -31,7 +31,10 @@ fn flat_text_element<'s, 'r>( ) -> Res<&'s str, TextElement<'s>> { not(|i| context.match_fail(i))(i)?; + let bold_matcher = parser_with_context!(flat_bold)(context); + alt(( + bold_matcher, map(span, TextElement::Span), map(symbol("*"), TextElement::Symbol), map(symbol("["), TextElement::Symbol), @@ -41,13 +44,22 @@ fn flat_text_element<'s, 'r>( ))(i) } +fn recognize_bold_end(input: &str) -> Res<&str, &str> { + recognize(bold_end)(input) +} + fn flat_bold<'s, 'r>(i: &'s str, context: &'r OrgModeContext<'r>) -> Res<&'s str, TextElement<'s>> { - // let fail_matcher = recognize(bold_end); - // let new_context = context.with_additional_fail_matcher(Rc::new(RefCell::new(paragraph_end))); - // let new_context = - // context.with_additional_fail_matcher(Rc::new(RefCell::new(recognize(bold_end)))); - // let new_context = context.without_bold(Rc::new(RefCell::new(recognize(bold_end)))); - todo!() + let new_context = context.with_additional_fail_matcher(&recognize_bold_end); + let text_element_parser = parser_with_context!(flat_text_element)(&new_context); + let (remaining, captured) = recognize(tuple(( + bold_start, + many_till(text_element_parser, bold_end), + bold_end + )))(i)?; + let ret = TextElement::Bold(Bold { + contents: captured + }); + Ok((remaining, ret)) } pub fn paragraph<'s, 'r>(