use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Copy, Clone)] #[serde(rename_all = "snake_case")] pub enum TextColor { Default, Gray, Brown, Orange, Yellow, Green, Blue, Purple, Pink, Red, GrayBackground, BrownBackground, OrangeBackground, YellowBackground, GreenBackground, BlueBackground, PurpleBackground, PinkBackground, RedBackground, } /// Rich text annotations /// See #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)] pub struct Annotations { pub bold: Option, pub code: Option, pub color: Option, pub italic: Option, pub strikethrough: Option, pub underline: Option, } /// Properties common on all rich text objects /// See #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)] pub struct RichTextCommon { pub plain_text: String, pub href: Option, pub annotations: Option, } #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)] pub struct Link { pub url: String, } #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)] pub struct Text { pub content: String, pub link: Option, } /// Rich text objects contain data for displaying formatted text, mentions, and equations. /// A rich text object also contains annotations for style information. /// Arrays of rich text objects are used within property objects and property /// value objects to create what a user sees as a single text value in Notion. #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)] #[serde(tag = "type")] #[serde(rename_all = "snake_case")] pub enum RichText { /// See Text { #[serde(flatten)] rich_text: RichTextCommon, text: Text, }, /// See Mention { #[serde(flatten)] rich_text: RichTextCommon, }, /// See Equation { #[serde(flatten)] rich_text: RichTextCommon, }, } impl RichText { pub fn plain_text(&self) -> &str { use RichText::*; match self { Text { rich_text, .. } | Mention { rich_text, .. } | Equation { rich_text, .. } => { &rich_text.plain_text } } } }