Support nesting greater blocks of different names.

This commit is contained in:
Tom Alexander 2023-04-19 15:00:02 -04:00
parent 2b08b52c16
commit 7ac0cee223
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -35,11 +35,6 @@ pub fn greater_block<'r, 's>(
input: &'s str, input: &'s str,
) -> Res<&'s str, GreaterBlock<'s>> { ) -> Res<&'s str, GreaterBlock<'s>> {
// TODO: Do I need to differentiate between different greater block types. // 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)?; start_of_line(context, input)?;
let (remaining, _leading_whitespace) = space0(input)?; let (remaining, _leading_whitespace) = space0(input)?;
// TODO: Not handling indentation before start of block // TODO: Not handling indentation before start of block
@ -50,11 +45,21 @@ pub fn greater_block<'r, 's>(
_ => true, _ => true,
}), }),
))(remaining)?; ))(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, parameters) = opt(tuple((space1, parameters)))(remaining)?;
let (remaining, _nl) = line_ending(remaining)?; let (remaining, _nl) = line_ending(remaining)?;
let parser_context = context let parser_context = context
.with_additional_node(ContextElement::ConsumeTrailingWhitespace(true)) .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::GreaterBlock(name))
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Alpha, class: ExitClass::Alpha,