Only allow a single section under a heading.

This commit is contained in:
Tom Alexander
2023-08-29 16:03:13 -04:00
parent 56865c68fc
commit 950baa9d5d
2 changed files with 8 additions and 5 deletions

View File

@@ -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,