diff --git a/src/parser/greater_block.rs b/src/parser/greater_block.rs index 20f0a73..f83d041 100644 --- a/src/parser/greater_block.rs +++ b/src/parser/greater_block.rs @@ -1,23 +1,29 @@ use super::error::Res; +use super::object::TextMarkup; use super::Context; use crate::parser::element::element; use crate::parser::error::CustomError; use crate::parser::error::MyError; use crate::parser::exiting::ExitClass; use crate::parser::greater_element::GreaterBlock; +use crate::parser::object::Object; use crate::parser::parser_context::ContextElement; use crate::parser::parser_context::ExitMatcherNode; use crate::parser::parser_with_context::parser_with_context; +use crate::parser::util::blank_line; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting; use crate::parser::util::start_of_line; +use crate::parser::Element; +use crate::parser::Paragraph; use nom::branch::alt; use nom::bytes::complete::is_not; use nom::bytes::complete::tag_no_case; use nom::character::complete::line_ending; use nom::character::complete::space0; use nom::character::complete::space1; +use nom::combinator::consumed; use nom::combinator::eof; use nom::combinator::opt; use nom::combinator::verify; @@ -48,12 +54,26 @@ pub fn greater_block<'r, 's>( class: ExitClass::Alpha, exit_matcher: &greater_block_end, })); + let parameters = match parameters { + Some((_ws, parameters)) => Some(parameters), + None => None, + }; let element_matcher = parser_with_context!(element)(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); // TODO: Not handling nested greater blocks - let (remaining, (children, _exit_contents)) = - many_till(element_matcher, exit_matcher)(remaining)?; + // Check for a completely empty block + let (remaining, children) = match consumed(many_till(blank_line, exit_matcher))(remaining) { + Ok((remaining, (whitespace, (children, _exit_contents)))) => ( + remaining, + vec![Element::Paragraph(Paragraph::of_text(whitespace))], + ), + Err(_) => { + let (remaining, (children, _exit_contents)) = + many_till(element_matcher, exit_matcher)(remaining)?; + (remaining, children) + } + }; let (remaining, _end) = greater_block_end(&parser_context, remaining)?; // Not checking if parent exit matcher is causing exit because the greater_block_end matcher asserts we matched a full greater block @@ -61,10 +81,6 @@ pub fn greater_block<'r, 's>( let (remaining, _trailing_ws) = maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?; - let parameters = match parameters { - Some((_ws, parameters)) => Some(parameters), - None => None, - }; let source = get_consumed(input, remaining); Ok(( remaining, diff --git a/src/parser/lesser_element.rs b/src/parser/lesser_element.rs index 110e647..6d041b4 100644 --- a/src/parser/lesser_element.rs +++ b/src/parser/lesser_element.rs @@ -1,4 +1,4 @@ -use super::object::Object; +use super::object::{Object, TextMarkup}; #[derive(Debug)] pub struct Paragraph<'s> { @@ -10,3 +10,14 @@ pub struct Paragraph<'s> { pub struct Comment<'s> { pub source: &'s str, } + +impl<'s> Paragraph<'s> { + pub fn of_text(input: &'s str) -> Self { + let mut objects = Vec::with_capacity(1); + objects.push(Object::TextMarkup(TextMarkup { source: input })); + Paragraph { + source: input, + children: objects, + } + } +}