Compare commits
3 Commits
9690545901
...
33ca43ca40
Author | SHA1 | Date | |
---|---|---|---|
![]() |
33ca43ca40 | ||
![]() |
f5280a3090 | ||
![]() |
c28d8ccea4 |
@ -81,7 +81,7 @@ pub(crate) fn broken_end<'b, 'g, 'r, 's>(
|
||||
|
||||
Ok((
|
||||
remaining,
|
||||
Paragraph::of_text_full(
|
||||
Paragraph::of_text(
|
||||
input.get_until(remaining).into(),
|
||||
body,
|
||||
if body.len() > 0 { Some(body) } else { None },
|
||||
@ -124,6 +124,7 @@ pub(crate) fn broken_dynamic_block<'b, 'g, 'r, 's>(
|
||||
match paragraph.children.first_mut() {
|
||||
Some(Object::PlainText(plain_text)) => {
|
||||
plain_text.source = input.get_until_end_of_str(plain_text.source).into();
|
||||
paragraph.contents = Some(input.get_until_end_of_str(plain_text.source).into());
|
||||
}
|
||||
Some(obj) => {
|
||||
panic!("Unhandled first object type inside bullshitium {:?}", obj);
|
||||
@ -134,14 +135,18 @@ pub(crate) fn broken_dynamic_block<'b, 'g, 'r, 's>(
|
||||
};
|
||||
Ok((remaining, paragraph))
|
||||
} else {
|
||||
let (remaining, _trailing_ws) =
|
||||
let (remaining, post_blank) =
|
||||
maybe_consume_trailing_whitespace_if_not_exiting(context, lead_in_remaining)?;
|
||||
|
||||
let body = Into::<&str>::into(input.get_until(lead_in_remaining));
|
||||
|
||||
Ok((
|
||||
remaining,
|
||||
Paragraph::of_text(
|
||||
input.get_until(remaining).into(),
|
||||
input.get_until(lead_in_remaining).into(),
|
||||
body,
|
||||
if body.len() > 0 { Some(body) } else { None },
|
||||
post_blank.map(Into::<&str>::into),
|
||||
),
|
||||
))
|
||||
}
|
||||
|
@ -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))
|
||||
},
|
||||
},
|
||||
))
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ pub(crate) fn empty_paragraph<'b, 'g, 'r, 's>(
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((
|
||||
remaining,
|
||||
Paragraph::of_text_full(
|
||||
Paragraph::of_text(
|
||||
Into::<&str>::into(source),
|
||||
Into::<&str>::into(first_line_with_spaces),
|
||||
Some(Into::<&str>::into(first_line_with_spaces)),
|
||||
@ -116,7 +116,7 @@ pub(crate) fn empty_paragraph<'b, 'g, 'r, 's>(
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((
|
||||
remaining,
|
||||
Paragraph::of_text_full(
|
||||
Paragraph::of_text(
|
||||
Into::<&str>::into(source),
|
||||
Into::<&str>::into(first_line),
|
||||
Some(Into::<&str>::into(first_line)),
|
||||
|
@ -36,6 +36,7 @@ pub struct Heading<'s> {
|
||||
pub deadline: Option<Timestamp<'s>>,
|
||||
pub closed: Option<Timestamp<'s>>,
|
||||
pub contents: Option<&'s str>,
|
||||
pub post_blank: Option<&'s str>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -105,7 +106,13 @@ impl<'s> StandardProperties<'s> for Heading<'s> {
|
||||
self.children
|
||||
.last()
|
||||
.map(|child| child.get_post_blank())
|
||||
.unwrap_or(0)
|
||||
.unwrap_or(
|
||||
self.post_blank
|
||||
.map(|text| text.lines().count())
|
||||
.unwrap_or(0)
|
||||
.try_into()
|
||||
.expect("Too much post-blank to fit into a PostBlank."),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,21 +204,7 @@ impl<'s> Paragraph<'s> {
|
||||
/// Generate a paragraph of the passed in text with no additional properties.
|
||||
///
|
||||
/// This is used for elements that support an "empty" content like greater blocks.
|
||||
pub(crate) fn of_text(source: &'s str, body: &'s str) -> Self {
|
||||
// TODO: This should be replaced with of_text_full.
|
||||
Paragraph {
|
||||
source,
|
||||
contents: None,
|
||||
post_blank: None,
|
||||
affiliated_keywords: AffiliatedKeywords::default(),
|
||||
children: vec![Object::PlainText(PlainText { source: body })],
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate a paragraph of the passed in text with no additional properties.
|
||||
///
|
||||
/// This is used for elements that support an "empty" content like greater blocks.
|
||||
pub(crate) fn of_text_full(
|
||||
pub(crate) fn of_text(
|
||||
source: &'s str,
|
||||
body: &'s str,
|
||||
contents: Option<&'s str>,
|
||||
|
Loading…
x
Reference in New Issue
Block a user