fix(ap): wrap outbound Note content in HTML paragraph tags

This commit is contained in:
2026-05-15 05:25:20 +02:00
parent 3455512bbb
commit 82f2a3aaa0

View File

@@ -28,6 +28,24 @@ use crate::{
webfinger::webfinger_handler,
};
fn content_to_html(text: &str) -> String {
let escaped = text
.replace('&', "&")
.replace('<', "&lt;")
.replace('>', "&gt;")
.replace('"', "&quot;");
let paragraphs: Vec<&str> = escaped.split('\n').filter(|s| !s.is_empty()).collect();
if paragraphs.is_empty() {
format!("<p>{}</p>", escaped)
} else {
paragraphs
.iter()
.map(|p| format!("<p>{}</p>", p))
.collect::<Vec<_>>()
.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,