diff options
| author | winter | 2025-02-14 17:56:45 +0000 |
|---|---|---|
| committer | winter | 2025-02-14 17:56:58 +0000 |
| commit | 45ac20c7a4d632bbb23aaba50c2d79ac5ebac465 (patch) | |
| tree | eb72692648bdf6c6e78d0334d96342dc79ce728d /routes/note_fragment.php | |
| parent | 42e38069e28f84af921b4ea877dc84b4de02c3fe (diff) | |
implement formatted note contents (html and commonmark)
Diffstat (limited to 'routes/note_fragment.php')
| -rw-r--r-- | routes/note_fragment.php | 19 |
1 files changed, 15 insertions, 4 deletions
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 @@ <?php +use Digitigrade\FormattingProvider\CommonMark; use Digitigrade\HttpResponseStatus\BadRequest; use Digitigrade\HttpResponseStatus\Forbidden; use Digitigrade\Model\Actor; @@ -71,13 +72,18 @@ Router::getInstance()->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); } |
