From 34df958af048358ae1d8e30be106399601f1a6e7 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 2 May 2024 16:29:01 +0200 Subject: [PATCH] feat: parse markdown when posting can't be toggled off for now :shrug: --- Cargo.lock | 1 + Cargo.toml | 1 + src/server/outbox.rs | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 6dce0fc6..f49060fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4412,6 +4412,7 @@ dependencies = [ "futures", "jrd", "mastodon-async-entities", + "mdhtml", "nodeinfo", "openssl", "rand", diff --git a/Cargo.toml b/Cargo.toml index 2d5f0b34..d7c4b875 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ chrono = { version = "0.4", features = ["serde"] } uuid = { version = "1.8", features = ["v4"] } serde = { version = "1", features = ["derive"] } serde_json = "1" +mdhtml = { path = "mdhtml", features = ["markdown"] } jrd = "0.1" tracing = "0.1" tracing-subscriber = "0.3" diff --git a/src/server/outbox.rs b/src/server/outbox.rs index 2db6088a..f3b46f8e 100644 --- a/src/server/outbox.rs +++ b/src/server/outbox.rs @@ -23,6 +23,9 @@ impl apb::server::Outbox for Context { .set_attributed_to(Node::link(uid.clone())) .set_published(Some(chrono::Utc::now())) )?; + if let Some(content) = object_model.content { + object_model.content = Some(mdhtml::safe_markdown(&content)); + } match (&object_model.in_reply_to, &object_model.context) { (Some(reply_id), None) => // get context from replied object object_model.context = self.fetch_object(reply_id).await?.context, @@ -84,6 +87,9 @@ impl apb::server::Outbox for Context { object_model.bto = activity_model.bto.clone(); object_model.cc = activity_model.cc.clone(); object_model.bcc = activity_model.bcc.clone(); + if let Some(content) = object_model.content { + object_model.content = Some(mdhtml::safe_markdown(&content)); + } match (&object_model.in_reply_to, &object_model.context) { (Some(reply_id), None) => // get context from replied object object_model.context = self.fetch_object(reply_id).await?.context,