feat: added support for links in RichText and Embeds

This commit is contained in:
Bram Dingelstad 2024-04-14 17:21:04 +02:00
parent 15e2c510ee
commit 03c3b887b1

View file

@ -9,7 +9,10 @@ use notion::BlockType;
pub fn convert_rich_text(text: &notion::RichText) -> String {
match text {
notion::RichText::Text {
text, annotations, ..
text,
annotations,
href,
..
} => {
let mut string = text.content.to_owned();
@ -25,6 +28,10 @@ pub fn convert_rich_text(text: &notion::RichText) -> String {
string = format!("`{string}`");
}
if let Some(url) = href {
string = format!("[{string}]({url})");
}
string
}
_ => "".to_string(),
@ -214,6 +221,13 @@ pub async fn convert_blocks(
}
}
BlockType::Embed { embed } => {
let url = &embed.url;
Some(format!(
r#"<iframe width="100%" height="420px" src="{url}"></iframe>"#
))
}
BlockType::Column { .. }
| BlockType::Table
| BlockType::Bookmark { .. }
@ -226,7 +240,6 @@ pub async fn convert_blocks(
| BlockType::Template
| BlockType::Toggle
| BlockType::Breadcrumb
| BlockType::Embed { .. }
| BlockType::Equation { .. }
| BlockType::LinkPreview { .. }
| BlockType::TableRow