//! A single element of text. use std::cell::RefCell; use std::rc::Rc; use crate::parser::parser_with_context::parser_with_context; use crate::parser::text::paragraph_end; use super::nom_context::OrgModeContext; use super::nom_context::OrgModeContextTree; use super::text::bold_end; use super::text::bold_start; use super::text::line_break; use super::text::space; use super::text::span; use super::text::symbol; use super::text::Bold; use super::text::Res; use super::text::TextElement; use nom::branch::alt; use nom::combinator::map; use nom::combinator::not; use nom::combinator::recognize; use nom::error::VerboseError; use nom::multi::many_till; use nom::sequence::tuple; use nom::IResult; fn flat_text_element<'s, 'r>( i: &'s str, context: &'r OrgModeContext<'r>, ) -> Res<&'s str, TextElement<'s>> { not(|i| context.match_fail(i))(i)?; alt(( map(span, TextElement::Span), map(symbol("*"), TextElement::Symbol), map(symbol("["), TextElement::Symbol), map(symbol("]"), TextElement::Symbol), map(space, TextElement::Space), map(line_break, TextElement::LineBreak), ))(i) } 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!() } pub fn paragraph<'s, 'r>( i: &'s str, context: &'r OrgModeContext<'r>, ) -> Res<&'s str, (Vec>, &'s str)> { let text_element_parser = parser_with_context!(flat_text_element)(context); many_till(text_element_parser, paragraph_end)(i) }