//! 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::NomContext; 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 NomContext) -> Res<&'s str, TextElement<'s>> { context.not_matching_fail(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 NomContext) -> Res<&'s str, TextElement<'s>> { let new_context = context.without_bold(Rc::new(RefCell::new(recognize(bold_end)))); todo!() } pub fn paragraph<'s, 'r>( i: &'s str, context: &'r NomContext, ) -> 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) }