diff --git a/org_mode_samples/greater_element/greater_block/deeply_nested.org b/org_mode_samples/greater_element/greater_block/deeply_nested.org new file mode 100644 index 00000000..48204742 --- /dev/null +++ b/org_mode_samples/greater_element/greater_block/deeply_nested.org @@ -0,0 +1,18 @@ +#+begin_defun +foo +#+begin_lorem +,#+begin_center +bar +,#+end_center +ipsum +#+end_lorem +baz +#+end_defun + +#+begin_center +#+begin_quote +#+begin_center +lorem +#+end_center +#+end_quote +#+end_center diff --git a/org_mode_samples/greater_element/greater_block/nested_special_block.org b/org_mode_samples/greater_element/greater_block/nested_special_block.org new file mode 100644 index 00000000..b96dbee7 --- /dev/null +++ b/org_mode_samples/greater_element/greater_block/nested_special_block.org @@ -0,0 +1,12 @@ +#+begin_defun +foo +#+begin_lorem +ipsum +#+end_lorem +bar +#+begin_center +#+begin_quote +baz +#+end_quote +#+end_center +#+end_defun diff --git a/org_mode_samples/greater_element/greater_block/special_block.org b/org_mode_samples/greater_element/greater_block/special_block.org new file mode 100644 index 00000000..d3b6df10 --- /dev/null +++ b/org_mode_samples/greater_element/greater_block/special_block.org @@ -0,0 +1,5 @@ +#+begin_defun +foo + +{{{bar(baz)}}} +#+end_defun diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 6e1386df..a633be8b 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -737,7 +737,7 @@ fn compare_greater_block<'s>( let emacs_name = match rust.name.to_lowercase().as_str() { "center" => "center-block", "quote" => "quote-block", - _ => todo!(), + _ => "special-block", }; if assert_name(emacs, emacs_name).is_err() { this_status = DiffStatus::Bad; diff --git a/src/parser/greater_block.rs b/src/parser/greater_block.rs index 85dc7e35..99ff8504 100644 --- a/src/parser/greater_block.rs +++ b/src/parser/greater_block.rs @@ -12,6 +12,7 @@ use nom::multi::many_till; use nom::sequence::tuple; use super::org_source::OrgSource; +use super::util::in_section; use super::Context; use crate::error::CustomError; use crate::error::MyError; @@ -26,7 +27,6 @@ use crate::parser::source::SetSource; use crate::parser::util::blank_line; use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; -use crate::parser::util::immediate_in_section; use crate::parser::util::start_of_line; use crate::parser::Element; use crate::parser::Paragraph; @@ -49,11 +49,11 @@ pub fn greater_block<'r, 's>( }), ))(remaining)?; let context_name = match Into::<&str>::into(name).to_lowercase().as_str() { - "center" => "center block", - "quote" => "quote block", - _ => "greater block", + "center" => "center block".to_owned(), + "quote" => "quote block".to_owned(), + name @ _ => format!("special block {}", name), }; - if immediate_in_section(context, context_name) { + if in_section(context, context_name.as_str()) { return Err(nom::Err::Error(CustomError::MyError(MyError( "Cannot nest objects of the same element".into(), )))); @@ -63,7 +63,7 @@ pub fn greater_block<'r, 's>( let (remaining, _nl) = line_ending(remaining)?; let parser_context = context .with_additional_node(ContextElement::ConsumeTrailingWhitespace(true)) - .with_additional_node(ContextElement::Context(context_name)) + .with_additional_node(ContextElement::Context(context_name.as_str())) .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { class: ExitClass::Alpha, exit_matcher: &exit_with_name,