notion_api_client/models/
text.rs1use crate::models::properties::DateValue;
2use crate::models::users::User;
3use crate::{Database, Page};
4use serde::{Deserialize, Serialize};
5
6#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Copy, Clone)]
7#[serde(rename_all = "snake_case")]
8pub enum TextColor {
9 Default,
10 Gray,
11 Brown,
12 Orange,
13 Yellow,
14 Green,
15 Blue,
16 Purple,
17 Pink,
18 Red,
19 GrayBackground,
20 BrownBackground,
21 OrangeBackground,
22 YellowBackground,
23 GreenBackground,
24 BlueBackground,
25 PurpleBackground,
26 PinkBackground,
27 RedBackground,
28}
29
30#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
33pub struct Annotations {
34 pub bold: Option<bool>,
35 pub code: Option<bool>,
36 pub color: Option<TextColor>,
37 pub italic: Option<bool>,
38 pub strikethrough: Option<bool>,
39 pub underline: Option<bool>,
40}
41
42#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
45pub struct RichTextCommon {
46 pub plain_text: String,
47 #[serde(skip_serializing_if = "Option::is_none")]
48 pub href: Option<String>,
49 #[serde(skip_serializing_if = "Option::is_none")]
50 pub annotations: Option<Annotations>,
51}
52
53#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
54pub struct Link {
55 pub url: String,
56}
57
58#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
59pub struct Text {
60 pub content: String,
61 pub link: Option<Link>,
62}
63
64#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
66#[serde(tag = "type")]
67#[serde(rename_all = "snake_case")]
68pub enum MentionObject {
69 User {
70 user: User,
71 },
72 Page {
74 page: Page,
75 },
76 Database {
78 database: Database,
79 },
80 Date {
81 date: DateValue,
82 },
83 #[serde(other)]
88 Unknown,
89}
90
91#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
96#[serde(tag = "type")]
97#[serde(rename_all = "snake_case")]
98pub enum RichText {
99 Text {
101 #[serde(flatten)]
102 rich_text: RichTextCommon,
103 text: Text,
104 },
105 Mention {
107 #[serde(flatten)]
108 rich_text: RichTextCommon,
109 mention: MentionObject,
110 },
111 Equation {
113 #[serde(flatten)]
114 rich_text: RichTextCommon,
115 },
116}
117
118impl RichText {
119 pub fn plain_text(&self) -> &str {
120 use RichText::*;
121 match self {
122 Text { rich_text, .. } | Mention { rich_text, .. } | Equation { rich_text, .. } => {
123 &rich_text.plain_text
124 }
125 }
126 }
127}