diff --git a/crates/adapters/activitypub-base/src/service.rs b/crates/adapters/activitypub-base/src/service.rs index f03e351..0b11eff 100644 --- a/crates/adapters/activitypub-base/src/service.rs +++ b/crates/adapters/activitypub-base/src/service.rs @@ -28,6 +28,24 @@ use crate::{ webfinger::webfinger_handler, }; +fn content_to_html(text: &str) -> String { + let escaped = text + .replace('&', "&") + .replace('<', "<") + .replace('>', ">") + .replace('"', """); + let paragraphs: Vec<&str> = escaped.split('\n').filter(|s| !s.is_empty()).collect(); + if paragraphs.is_empty() { + format!("

{}

", escaped) + } else { + paragraphs + .iter() + .map(|p| format!("

{}

", p)) + .collect::>() + .join("") + } +} + fn thought_note_json( thought: &domain::models::thought::Thought, local_actor: &crate::actors::DbActor, @@ -56,7 +74,7 @@ fn thought_note_json( "id": ap_id.to_string(), "url": ap_id.to_string(), "attributedTo": local_actor.ap_id.to_string(), - "content": thought.content.as_str(), + "content": content_to_html(thought.content.as_str()), "published": thought.created_at.to_rfc3339(), "to": to, "cc": cc,