X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpleroma%2Fweb%2Fcommon_api%2Futils.ex;h=ed1fe1ad9dda979d1ba9098eb128c6b4c805239f;hb=784b3a615d57e7b77b1ec2cafe27ae59281cbc6b;hp=f6960bf4146fa5267b90fcb7be9a682bc3b162dc;hpb=f9d13558c8198bf2a25035dfb3c112aaa2be4cbf;p=akkoma
diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex
index f6960bf41..ed1fe1ad9 100644
--- a/lib/pleroma/web/common_api/utils.ex
+++ b/lib/pleroma/web/common_api/utils.ex
@@ -2,6 +2,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
alias Pleroma.{Repo, Object, Formatter, Activity}
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.Endpoint
+ alias Pleroma.Web.MediaProxy
alias Pleroma.User
alias Calendar.Strftime
alias Comeonin.Pbkdf2
@@ -63,10 +64,16 @@ defmodule Pleroma.Web.CommonAPI.Utils do
end
end
- def make_content_html(status, mentions, attachments, tags, no_attachment_links \\ false) do
+ def make_content_html(
+ status,
+ mentions,
+ attachments,
+ tags,
+ content_type,
+ no_attachment_links \\ false
+ ) do
status
- |> String.replace("\r", "")
- |> format_input(mentions, tags)
+ |> format_input(mentions, tags, content_type)
|> maybe_add_attachments(attachments, no_attachment_links)
end
@@ -84,6 +91,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
Enum.map(attachments, fn
%{"url" => [%{"href" => href} | _]} ->
name = URI.decode(Path.basename(href))
+ href = MediaProxy.url(href)
"#{shortname(name)}"
_ ->
@@ -93,10 +101,10 @@ defmodule Pleroma.Web.CommonAPI.Utils do
Enum.join([text | attachment_text], "
")
end
- def format_input(text, mentions, tags) do
+ def format_input(text, mentions, tags, "text/plain") do
text
- |> Formatter.html_escape()
- |> String.replace("\n", "
")
+ |> Formatter.html_escape("text/plain")
+ |> String.replace(~r/\r?\n/, "
")
|> (&{[], &1}).()
|> Formatter.add_links()
|> Formatter.add_user_links(mentions)
@@ -104,13 +112,33 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|> Formatter.finalize()
end
+ def format_input(text, mentions, tags, "text/html") do
+ text
+ |> Formatter.html_escape("text/html")
+ |> String.replace(~r/\r?\n/, "
")
+ |> (&{[], &1}).()
+ |> Formatter.add_user_links(mentions)
+ |> Formatter.finalize()
+ end
+
+ def format_input(text, mentions, tags, "text/markdown") do
+ text
+ |> Earmark.as_html!()
+ |> Formatter.html_escape("text/html")
+ |> String.replace(~r/\r?\n/, "")
+ |> (&{[], &1}).()
+ |> Formatter.add_user_links(mentions)
+ |> Formatter.add_hashtag_links(tags)
+ |> Formatter.finalize()
+ end
+
def add_tag_links(text, tags) do
tags =
tags
|> Enum.sort_by(fn {tag, _} -> -String.length(tag) end)
Enum.reduce(tags, text, fn {full, tag}, text ->
- url = "##{tag}"
+ url = "##{tag}"
String.replace(text, full, url)
end)
end
@@ -203,7 +231,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|> Enum.map(fn {shortcode, url} ->
%{
"type" => "Emoji",
- "icon" => %{"url" => "#{Endpoint.url()}#{url}"},
+ "icon" => %{"type" => "Image", "url" => "#{Endpoint.url()}#{url}"},
"name" => ":#{shortcode}:"
}
end)