Fix post-blank for headlines containing only whitespace.

This commit is contained in:
Tom Alexander
2023-12-15 17:59:47 -05:00
parent 9690545901
commit c28d8ccea4
2 changed files with 16 additions and 2 deletions

View File

@@ -67,6 +67,7 @@ fn _heading<'b, 'g, 'r, 's>(
let section_matcher = bind_context!(section, context);
let heading_matcher = bind_context!(heading(pre_headline.star_count), context);
let (contents_begin, _) = opt(many0(blank_line))(remaining)?;
let maybe_post_blank = get_consumed(remaining, contents_begin);
let (remaining, maybe_section) =
opt(map(section_matcher, DocumentElement::Section))(remaining)?;
let (remaining, _ws) = opt(tuple((start_of_line, many0(blank_line))))(remaining)?;
@@ -83,7 +84,8 @@ fn _heading<'b, 'g, 'r, 's>(
}
children.insert(0, section);
}
let remaining = if children.is_empty() {
let has_children = !children.is_empty();
let remaining = if !has_children {
// Support empty headings
let (remain, _ws) = many0(blank_line)(remaining)?;
remain
@@ -119,6 +121,11 @@ fn _heading<'b, 'g, 'r, 's>(
} else {
None
},
post_blank: if has_children {
None
} else {
Some(Into::<&str>::into(maybe_post_blank))
},
},
))
}