From 950baa9d5dee5cf47aa80564f619ca9b6d0aca5a Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 29 Aug 2023 16:03:13 -0400 Subject: [PATCH] Only allow a single section under a heading. --- build.rs | 1 - src/parser/document.rs | 12 ++++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/build.rs b/build.rs index 284d86d..c8b3c1d 100644 --- a/build.rs +++ b/build.rs @@ -75,7 +75,6 @@ fn is_expect_fail(name: &str) -> Option<&str> { "autogen_greater_element_drawer_drawer_with_headline_inside" => Some("Apparently lines with :end: become their own paragraph. This odd behavior needs to be investigated more."), "autogen_element_container_priority_footnote_definition_dynamic_block" => Some("Apparently broken begin lines become their own paragraph."), "autogen_lesser_element_paragraphs_paragraph_with_backslash_line_breaks" => Some("The text we're getting out of the parse tree is already processed to remove line breaks, so our comparison needs to take that into account."), - "autogen_sections_and_headings_empty_section" => Some("We are not yet handling empty sections properly."), _ => None, } } diff --git a/src/parser/document.rs b/src/parser/document.rs index efb85d5..814d0b4 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -283,10 +283,14 @@ fn _heading<'r, 's>( headline(context, input, parent_stars)?; let section_matcher = parser_with_context!(section)(context); let heading_matcher = parser_with_context!(heading(star_count))(context); - let (remaining, children) = many0(alt(( - map(heading_matcher, DocumentElement::Heading), - map(section_matcher, DocumentElement::Section), - )))(remaining)?; + let (remaining, maybe_section) = + opt(map(section_matcher, DocumentElement::Section))(remaining)?; + let (remaining, mut children) = + many0(map(heading_matcher, DocumentElement::Heading))(remaining)?; + if let Some(section) = maybe_section { + children.insert(0, section); + } + let source = get_consumed(input, remaining); Ok(( remaining,