From 4fb2251221e9c023905a25c49fc9058b29952d13 Mon Sep 17 00:00:00 2001 From: FloatingGhost Date: Tue, 14 Jun 2022 15:56:12 +0100 Subject: [PATCH] Allow authoring MFM --- config/config.exs | 3 ++- lib/pleroma/emoji.ex | 2 +- lib/pleroma/web/common_api/activity_draft.ex | 7 ++++--- lib/pleroma/web/common_api/utils.ex | 9 +++++++++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/config/config.exs b/config/config.exs index 417f298d7..ad7096669 100644 --- a/config/config.exs +++ b/config/config.exs @@ -222,7 +222,8 @@ config :pleroma, :instance, "text/plain", "text/html", "text/markdown", - "text/bbcode" + "text/bbcode", + "text/x.misskeymarkdown" ], staff_transparency: [], autofollowed_nicknames: [], diff --git a/lib/pleroma/emoji.ex b/lib/pleroma/emoji.ex index f4043ac80..9e1858ae7 100644 --- a/lib/pleroma/emoji.ex +++ b/lib/pleroma/emoji.ex @@ -165,7 +165,7 @@ defmodule Pleroma.Emoji do def maybe_quote(name), do: name - def emoji_url(%{"type" => "EmojiReact", "content" => emoji, "tag" => []}), do: nil + def emoji_url(%{"type" => "EmojiReact", "content" => _, "tag" => []}), do: nil def emoji_url(%{"type" => "EmojiReact", "content" => emoji, "tag" => tags}) do tag = diff --git a/lib/pleroma/web/common_api/activity_draft.ex b/lib/pleroma/web/common_api/activity_draft.ex index b4e3e37ae..08e704ed4 100644 --- a/lib/pleroma/web/common_api/activity_draft.ex +++ b/lib/pleroma/web/common_api/activity_draft.ex @@ -213,13 +213,14 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do end emoji = Map.merge(emoji, summary_emoji) - {:ok, note_data, _meta} = Builder.note(draft) - object = note_data |> Map.put("emoji", emoji) - |> Map.put("source", draft.status) + |> Map.put("source", %{ + "content" => draft.status, + "mediaType" => draft.params[:content_type] + }) |> Map.put("generator", draft.params[:generator]) %__MODULE__{draft | object: object} diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index b6feaf32a..8fde9ae15 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -291,6 +291,15 @@ defmodule Pleroma.Web.CommonAPI.Utils do |> Formatter.html_escape("text/html") end + def format_input(text, "text/x.misskeymarkdown", options) do + text + |> Formatter.html_escape("text/plain") + |> Formatter.linkify(options) + |> (fn {text, mentions, tags} -> + {String.replace(text, ~r/\r?\n/, "
"), mentions, tags} + end).() + end + def format_naive_asctime(date) do date |> DateTime.from_naive!("Etc/UTC") |> format_asctime end