diff --git a/src/parser/text_markup.rs b/src/parser/text_markup.rs index 58662cf..c8195b4 100644 --- a/src/parser/text_markup.rs +++ b/src/parser/text_markup.rs @@ -162,13 +162,14 @@ fn verbatim<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Verbatim<'s>> { - let (remaining, contents) = text_markup_string("=")(context, input)?; + let (remaining, (contents, post_blank)) = text_markup_string("=")(context, input)?; let source = get_consumed(input, remaining); Ok(( remaining, Verbatim { source: source.into(), contents: contents.into(), + post_blank: post_blank.map(Into::<&str>::into), }, )) } @@ -181,13 +182,14 @@ fn code<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Code<'s>> { - let (remaining, contents) = text_markup_string("~")(context, input)?; + let (remaining, (contents, post_blank)) = text_markup_string("~")(context, input)?; let source = get_consumed(input, remaining); Ok(( remaining, Code { source: source.into(), contents: contents.into(), + post_blank: post_blank.map(Into::<&str>::into), }, )) } @@ -262,7 +264,7 @@ fn text_markup_string( ) -> impl for<'b, 'g, 'r, 's> Fn( RefContext<'b, 'g, 'r, 's>, OrgSource<'s>, -) -> Res, OrgSource<'s>> +) -> Res, (OrgSource<'s>, Option>)> + '_ { move |context, input: OrgSource<'_>| _text_markup_string(context, input, marker_symbol) } @@ -275,7 +277,7 @@ fn _text_markup_string<'b, 'g, 'r, 's, 'c>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, marker_symbol: &'c str, -) -> Res, OrgSource<'s>> { +) -> Res, (OrgSource<'s>, Option>)> { let (remaining, _) = pre(context, input)?; let (remaining, open) = tag(marker_symbol)(remaining)?; let (remaining, _peek_not_whitespace) = @@ -308,9 +310,9 @@ fn _text_markup_string<'b, 'g, 'r, 's, 'c>( } let (remaining, _close) = text_markup_end_specialized(context, remaining)?; - let (remaining, _trailing_whitespace) = + let (remaining, post_blank) = maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?; - Ok((remaining, contents)) + Ok((remaining, (contents, post_blank))) } #[cfg_attr( diff --git a/src/types/object.rs b/src/types/object.rs index 40db622..5d79340 100644 --- a/src/types/object.rs +++ b/src/types/object.rs @@ -76,12 +76,14 @@ pub struct StrikeThrough<'s> { pub struct Code<'s> { pub source: &'s str, pub contents: &'s str, + pub post_blank: Option<&'s str>, } #[derive(Debug)] pub struct Verbatim<'s> { pub source: &'s str, pub contents: &'s str, + pub post_blank: Option<&'s str>, } #[derive(Debug)] @@ -603,11 +605,15 @@ impl<'s> StandardProperties<'s> for Code<'s> { } fn get_contents<'b>(&'b self) -> Option<&'s str> { - todo!() + None } fn get_post_blank(&self) -> PostBlank { - todo!() + self.post_blank + .map(|post_blank| post_blank.chars().count()) + .unwrap_or(0) + .try_into() + .expect("Too much post-blank to fit into a PostBlank.") } } @@ -617,11 +623,15 @@ impl<'s> StandardProperties<'s> for Verbatim<'s> { } fn get_contents<'b>(&'b self) -> Option<&'s str> { - todo!() + None } fn get_post_blank(&self) -> PostBlank { - todo!() + self.post_blank + .map(|post_blank| post_blank.chars().count()) + .unwrap_or(0) + .try_into() + .expect("Too much post-blank to fit into a PostBlank.") } }