diff --git a/src/parser/document.rs b/src/parser/document.rs index 77ed1a0..ddaa283 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -127,28 +127,26 @@ fn zeroth_section<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s s let element_matcher = parser_with_context!(element)(&parser_context); let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); - let (remaining, (comment_element, property_drawer_element)) = tuple(( + let (remaining, comment_and_property_drawer_element) = opt(tuple(( opt(parser_with_context!(comment)( &without_consuming_whitespace_context, )), - opt(parser_with_context!(property_drawer)( - &without_consuming_whitespace_context, - )), - ))(input)?; + parser_with_context!(property_drawer)(&without_consuming_whitespace_context), + )))(input)?; let (remaining, (mut children, _exit_contents)) = verify( many_till(element_matcher, exit_matcher), |(children, _exit_contents)| { - !children.is_empty() || property_drawer_element.is_some() || comment_element.is_some() + !children.is_empty() || comment_and_property_drawer_element.is_some() }, )(remaining)?; - property_drawer_element - .map(Element::PropertyDrawer) - .map(|ele| children.insert(0, ele)); - comment_element - .map(Element::Comment) - .map(|ele| children.insert(0, ele)); - // children.insert(0, item) + + comment_and_property_drawer_element.map(|(comment, property_drawer)| { + children.insert(0, Element::PropertyDrawer(property_drawer)); + comment + .map(Element::Comment) + .map(|ele| children.insert(0, ele)); + }); let (remaining, _trailing_ws) = maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?; diff --git a/src/parser/drawer.rs b/src/parser/drawer.rs index d8f2f87..e79cdeb 100644 --- a/src/parser/drawer.rs +++ b/src/parser/drawer.rs @@ -1,5 +1,6 @@ use nom::branch::alt; use nom::bytes::complete::tag; +use nom::bytes::complete::tag_no_case; use nom::bytes::complete::take_while; use nom::character::complete::line_ending; use nom::character::complete::space0; @@ -92,7 +93,7 @@ fn drawer_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, start_of_line(context, input)?; recognize(tuple(( space0, - tag(":end:"), + tag_no_case(":end:"), space0, alt((line_ending, eof)), )))(input)