diff --git a/src/parser/element_parser.rs b/src/parser/element_parser.rs index 0be05041..ff9a8c26 100644 --- a/src/parser/element_parser.rs +++ b/src/parser/element_parser.rs @@ -32,6 +32,7 @@ use super::lesser_block::verse_block; use super::org_source::OrgSource; use super::paragraph::paragraph; use super::plain_list::detect_plain_list; +use super::plain_list::new_plain_list; use super::plain_list::plain_list; use super::table::detect_table; use crate::context::parser_with_context; @@ -39,6 +40,7 @@ use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; +use crate::parser::macros::ak_element; use crate::parser::table::org_mode_table; use crate::types::Element; @@ -62,6 +64,17 @@ fn _element<'b, 'g, 'r, 's>( ) -> Res, Element<'s>> { let (post_affiliated_keywords_input, affiliated_keywords) = many0(affiliated_keyword)(input)?; + let mut affiliated_keywords = affiliated_keywords.into_iter(); + + ak_element!( + new_plain_list, + &mut affiliated_keywords, + post_affiliated_keywords_input, + context, + input, + Element::PlainList + ); + let plain_list_matcher = parser_with_context!(plain_list)(context); let greater_block_matcher = parser_with_context!(greater_block)(context); let dynamic_block_matcher = parser_with_context!(dynamic_block)(context); @@ -131,6 +144,8 @@ fn _element<'b, 'g, 'r, 's>( } } + // TODO: These two paragraphs need to be revisited using the affiliated keywords parsed above. + if maybe_element.is_none() && can_be_paragraph { #[cfg(feature = "tracing")] let span = span!( diff --git a/src/parser/macros.rs b/src/parser/macros.rs index 8b137891..86659baf 100644 --- a/src/parser/macros.rs +++ b/src/parser/macros.rs @@ -1 +1,25 @@ +/// Parse an element that has affiliated keywords. +macro_rules! ak_element { + ($parser:ident, $affiliated_keywords:expr, $post_affiliated_keywords_input: expr, $context: expr, $input: expr, $wrapper: expr) => { + if let Ok((remaining, ele)) = $parser( + $affiliated_keywords, + $post_affiliated_keywords_input, + $context, + $input, + ) { + return Ok((remaining, $wrapper(ele))); + } + }; + ($parser:ident, $affiliated_keywords:expr, $post_affiliated_keywords_input: expr, $context: expr, $input: expr) => { + if let Ok((remaining, ele)) = $parser( + $affiliated_keywords, + $post_affiliated_keywords_input, + $context, + $input, + ) { + return Ok((remaining, ele)); + } + }; +} +pub(crate) use ak_element; diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index adb0dc3e..18f1ae76 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -91,7 +91,7 @@ pub(crate) fn new_plain_list<'b, 'g, 'r, 's, AK>( input: OrgSource<'s>, ) -> Res, PlainList<'s>> where - AK: Iterator>, + AK: IntoIterator>, { todo!() }