Merge branch 'bugfix/osada-mention' into 'develop'
[akkoma] / lib / pleroma / formatter.ex
index 62f54a3f255e2e74d5e7c6dc7dfa7ff1f83d4e46..21b08a62e29b577031becbfaba24a84612cb7730 100644 (file)
@@ -192,7 +192,11 @@ defmodule Pleroma.Formatter do
   ]
 
   # TODO: make it use something other than @link_regex
-  def html_escape(text) do
+  def html_escape(text, "text/html") do
+    HTML.filter_tags(text)
+  end
+
+  def html_escape(text, "text/plain") do
     Regex.split(@link_regex, text, include_captures: true)
     |> Enum.map_every(2, fn chunk ->
       {:safe, part} = Phoenix.HTML.html_escape(chunk)
@@ -222,13 +226,7 @@ defmodule Pleroma.Formatter do
     subs =
       subs ++
         Enum.map(links, fn {uuid, url} ->
-          {:safe, link} = Phoenix.HTML.Link.link(url, to: url)
-
-          link =
-            link
-            |> IO.iodata_to_binary()
-
-          {uuid, link}
+          {uuid, "<a href=\"#{url}\">#{url}</a>"}
         end)
 
     {subs, uuid_text}
@@ -250,7 +248,12 @@ defmodule Pleroma.Formatter do
     subs =
       subs ++
         Enum.map(mentions, fn {match, %User{ap_id: ap_id, info: info}, uuid} ->
-          ap_id = info["source_data"]["url"] || ap_id
+          ap_id =
+            if is_binary(info["source_data"]["url"]) do
+              info["source_data"]["url"]
+            else
+              ap_id
+            end
 
           short_match = String.split(match, "@") |> tl() |> hd()