diff --git a/src/parser/text.rs b/src/parser/text.rs index aca9229b..09fc5423 100644 --- a/src/parser/text.rs +++ b/src/parser/text.rs @@ -66,7 +66,7 @@ pub struct Symbol<'a> { #[derive(Debug)] pub struct BlankLine<'a> { - contents: Vec>, + contents: &'a str, } #[derive(Debug)] @@ -105,16 +105,11 @@ pub fn symbol(symbol_tag: &'static str) -> impl for<'a> Fn(&'a str) -> Res<&'a s /// It is up to the caller to ensure this is called at the start of a line. fn blank_line(input: &str) -> Res<&str, BlankLine> { map( - many_till( + recognize(many_till( map(space, TextElement::Space), map(line_break, TextElement::LineBreak), - ), - |(mut whitespace, end_of_line)| { - whitespace.push(end_of_line); - BlankLine { - contents: whitespace, - } - }, + )), + |contents| BlankLine { contents }, )(input) } diff --git a/src/parser/text_element_parser.rs b/src/parser/text_element_parser.rs index 31e92940..f874e78a 100644 --- a/src/parser/text_element_parser.rs +++ b/src/parser/text_element_parser.rs @@ -39,8 +39,8 @@ fn flat_text_element<'s, 'r>( let link_matcher = parser_with_context!(flat_link)(context); alt(( - bold_matcher, - link_matcher, + map(bold_matcher, TextElement::Bold), + map(link_matcher, TextElement::Link), map(span, TextElement::Span), map(symbol("*"), TextElement::Symbol), map(symbol("["), TextElement::Symbol), @@ -54,14 +54,14 @@ 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>> { +fn flat_bold<'s, 'r>(i: &'s str, context: &'r OrgModeContext<'r>) -> Res<&'s str, Bold<'s>> { 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), )))(i)?; - let ret = TextElement::Bold(Bold { contents: captured }); + let ret = Bold { contents: captured }; Ok((remaining, ret)) } @@ -69,14 +69,14 @@ fn recognize_link_end(input: &str) -> Res<&str, &str> { recognize(link_end)(input) } -fn flat_link<'s, 'r>(i: &'s str, context: &'r OrgModeContext<'r>) -> Res<&'s str, TextElement<'s>> { +fn flat_link<'s, 'r>(i: &'s str, context: &'r OrgModeContext<'r>) -> Res<&'s str, Link<'s>> { let new_context = context.with_additional_fail_matcher(&recognize_link_end); let text_element_parser = parser_with_context!(flat_text_element)(&new_context); let (remaining, captured) = recognize(tuple(( link_start, many_till(text_element_parser, link_end), )))(i)?; - let ret = TextElement::Link(Link { contents: captured }); + let ret = Link { contents: captured }; Ok((remaining, ret)) }