Compare commits

..

No commits in common. "33ca43ca408844ccc495e5f6a027dd3ebdbea446" and "969054590117200b1de4ceb13ec3df1865f9b26c" have entirely different histories.

5 changed files with 22 additions and 27 deletions

View File

@ -81,7 +81,7 @@ pub(crate) fn broken_end<'b, 'g, 'r, 's>(
Ok(( Ok((
remaining, remaining,
Paragraph::of_text( Paragraph::of_text_full(
input.get_until(remaining).into(), input.get_until(remaining).into(),
body, body,
if body.len() > 0 { Some(body) } else { None }, if body.len() > 0 { Some(body) } else { None },
@ -124,7 +124,6 @@ pub(crate) fn broken_dynamic_block<'b, 'g, 'r, 's>(
match paragraph.children.first_mut() { match paragraph.children.first_mut() {
Some(Object::PlainText(plain_text)) => { Some(Object::PlainText(plain_text)) => {
plain_text.source = input.get_until_end_of_str(plain_text.source).into(); 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) => { Some(obj) => {
panic!("Unhandled first object type inside bullshitium {:?}", obj); panic!("Unhandled first object type inside bullshitium {:?}", obj);
@ -135,18 +134,14 @@ pub(crate) fn broken_dynamic_block<'b, 'g, 'r, 's>(
}; };
Ok((remaining, paragraph)) Ok((remaining, paragraph))
} else { } else {
let (remaining, post_blank) = let (remaining, _trailing_ws) =
maybe_consume_trailing_whitespace_if_not_exiting(context, lead_in_remaining)?; maybe_consume_trailing_whitespace_if_not_exiting(context, lead_in_remaining)?;
let body = Into::<&str>::into(input.get_until(lead_in_remaining));
Ok(( Ok((
remaining, remaining,
Paragraph::of_text( Paragraph::of_text(
input.get_until(remaining).into(), input.get_until(remaining).into(),
body, input.get_until(lead_in_remaining).into(),
if body.len() > 0 { Some(body) } else { None },
post_blank.map(Into::<&str>::into),
), ),
)) ))
} }

View File

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

View File

@ -101,7 +101,7 @@ pub(crate) fn empty_paragraph<'b, 'g, 'r, 's>(
let source = get_consumed(input, remaining); let source = get_consumed(input, remaining);
Ok(( Ok((
remaining, remaining,
Paragraph::of_text( Paragraph::of_text_full(
Into::<&str>::into(source), Into::<&str>::into(source),
Into::<&str>::into(first_line_with_spaces), Into::<&str>::into(first_line_with_spaces),
Some(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); let source = get_consumed(input, remaining);
Ok(( Ok((
remaining, remaining,
Paragraph::of_text( Paragraph::of_text_full(
Into::<&str>::into(source), Into::<&str>::into(source),
Into::<&str>::into(first_line), Into::<&str>::into(first_line),
Some(Into::<&str>::into(first_line)), Some(Into::<&str>::into(first_line)),

View File

@ -36,7 +36,6 @@ pub struct Heading<'s> {
pub deadline: Option<Timestamp<'s>>, pub deadline: Option<Timestamp<'s>>,
pub closed: Option<Timestamp<'s>>, pub closed: Option<Timestamp<'s>>,
pub contents: Option<&'s str>, pub contents: Option<&'s str>,
pub post_blank: Option<&'s str>,
} }
#[derive(Debug)] #[derive(Debug)]
@ -106,13 +105,7 @@ impl<'s> StandardProperties<'s> for Heading<'s> {
self.children self.children
.last() .last()
.map(|child| child.get_post_blank()) .map(|child| child.get_post_blank())
.unwrap_or( .unwrap_or(0)
self.post_blank
.map(|text| text.lines().count())
.unwrap_or(0)
.try_into()
.expect("Too much post-blank to fit into a PostBlank."),
)
} }
} }

View File

@ -204,7 +204,21 @@ impl<'s> Paragraph<'s> {
/// Generate a paragraph of the passed in text with no additional properties. /// 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. /// This is used for elements that support an "empty" content like greater blocks.
pub(crate) fn of_text( 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(
source: &'s str, source: &'s str,
body: &'s str, body: &'s str,
contents: Option<&'s str>, contents: Option<&'s str>,