From 7ac0cee223580a668dc84d71b9f22b4295342c62 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 19 Apr 2023 15:00:02 -0400 Subject: [PATCH] Support nesting greater blocks of different names. --- src/parser/greater_block.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/parser/greater_block.rs b/src/parser/greater_block.rs index 73a7deb..f13c644 100644 --- a/src/parser/greater_block.rs +++ b/src/parser/greater_block.rs @@ -35,11 +35,6 @@ pub fn greater_block<'r, 's>( input: &'s str, ) -> Res<&'s str, GreaterBlock<'s>> { // TODO: Do I need to differentiate between different greater block types. - if immediate_in_section(context, "greater block") { - return Err(nom::Err::Error(CustomError::MyError(MyError( - "Cannot nest objects of the same element", - )))); - } start_of_line(context, input)?; let (remaining, _leading_whitespace) = space0(input)?; // TODO: Not handling indentation before start of block @@ -50,11 +45,21 @@ pub fn greater_block<'r, 's>( _ => true, }), ))(remaining)?; + let context_name = match name.to_lowercase().as_str() { + "center" => "center block", + "quote" => "quote block", + _ => "greater block", + }; + if immediate_in_section(context, context_name) { + return Err(nom::Err::Error(CustomError::MyError(MyError( + "Cannot nest objects of the same element", + )))); + } let (remaining, parameters) = opt(tuple((space1, parameters)))(remaining)?; let (remaining, _nl) = line_ending(remaining)?; let parser_context = context .with_additional_node(ContextElement::ConsumeTrailingWhitespace(true)) - .with_additional_node(ContextElement::Context("greater block")) + .with_additional_node(ContextElement::Context(context_name)) .with_additional_node(ContextElement::GreaterBlock(name)) .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Alpha,