Implement the new fields for bold, italic, underline, and strike-through.

This commit is contained in:
Tom Alexander
2023-12-08 15:51:38 -05:00
parent 3fb7cb82cd
commit 8fd9ff3848
4 changed files with 86 additions and 30 deletions

View File

@@ -43,24 +43,32 @@ pub enum Object<'s> {
#[derive(Debug)]
pub struct Bold<'s> {
pub source: &'s str,
pub contents: &'s str,
pub post_blank: Option<&'s str>,
pub children: Vec<Object<'s>>,
}
#[derive(Debug)]
pub struct Italic<'s> {
pub source: &'s str,
pub contents: &'s str,
pub post_blank: Option<&'s str>,
pub children: Vec<Object<'s>>,
}
#[derive(Debug)]
pub struct Underline<'s> {
pub source: &'s str,
pub contents: &'s str,
pub post_blank: Option<&'s str>,
pub children: Vec<Object<'s>>,
}
#[derive(Debug)]
pub struct StrikeThrough<'s> {
pub source: &'s str,
pub contents: &'s str,
pub post_blank: Option<&'s str>,
pub children: Vec<Object<'s>>,
}
@@ -523,11 +531,15 @@ impl<'s> StandardProperties<'s> for Bold<'s> {
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
Some(self.contents)
}
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.")
}
}
@@ -537,11 +549,15 @@ impl<'s> StandardProperties<'s> for Italic<'s> {
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
Some(self.contents)
}
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.")
}
}
@@ -551,11 +567,15 @@ impl<'s> StandardProperties<'s> for Underline<'s> {
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
Some(self.contents)
}
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.")
}
}
@@ -565,11 +585,15 @@ impl<'s> StandardProperties<'s> for StrikeThrough<'s> {
}
fn get_contents<'b>(&'b self) -> Option<&'s str> {
todo!()
Some(self.contents)
}
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.")
}
}