From 45ac20c7a4d632bbb23aaba50c2d79ac5ebac465 Mon Sep 17 00:00:00 2001 From: winter Date: Fri, 14 Feb 2025 17:56:45 +0000 Subject: implement formatted note contents (html and commonmark) --- routes/note_fragment.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'routes/note_fragment.php') diff --git a/routes/note_fragment.php b/routes/note_fragment.php index 21a5369..b64eb22 100644 --- a/routes/note_fragment.php +++ b/routes/note_fragment.php @@ -1,5 +1,6 @@ mount('/fragment/note/:id/reply', function (array $args) if (isset($_POST['content']) && strlen(trim($_POST['content'])) > 0) { $summary = trim($_POST['summary'] ?? ''); $summary = $summary == '' ? null : $summary; + $content = trim($_POST['content']); $reply = Note::create( $author->actor, - trim($_POST['content']), - 'unk', + CommonMark::getInstance()->renderToPlainText($content), + get_ui_language(), // TODO: actual language selector/detection $summary, NotePrivacyScope::from($_POST['scope']) ); + $reply->formattedContent = [ + 'text/markdown' => $content, + 'text/html' => CommonMark::getInstance()->renderToHtml($content) + ]; $reply->inReplyTo = $note; $reply->threadApex = $note->threadApex ?? $note; foreach (($_POST['mentions'] ?? []) as $uid) { @@ -95,16 +101,21 @@ Router::getInstance()->mount('/fragment/note', function (array $args) { // posting a new note $author = UserAccount::requireByCurrentSession(); if (isset($_POST['content']) && strlen(trim($_POST['content'])) > 0) { - // TODO: post language, other privacy options, etc + // TODO: other privacy options, etc $summary = trim($_POST['summary'] ?? ''); $summary = $summary == '' ? null : $summary; + $content = trim($_POST['content']); $note = Note::create( $author->actor, - trim($_POST['content']), + CommonMark::getInstance()->renderToPlainText($content), get_ui_language(), // TODO: actual language selector/detection $summary, NotePrivacyScope::from($_POST['scope']) ); + $note->formattedContent = [ + 'text/markdown' => $content, + 'text/html' => CommonMark::getInstance()->renderToHtml($content) + ]; foreach (($_POST['mentions'] ?? []) as $uid) { $note->mentions[] = Actor::find($uid); } -- cgit v1.3