InlineQuotePolicy: don't add line breaks to markdown posts
This commit is contained in:
parent
74e0a4555f
commit
bee7e41959
@ -6,8 +6,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.InlineQuotePolicy do
|
|||||||
@moduledoc "Force a quote line into the message content."
|
@moduledoc "Force a quote line into the message content."
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
defp build_inline_quote(prefix, url) do
|
defp build_inline_quote(prefix, url, br) do
|
||||||
"<span class=\"quote-inline\"><br><br>#{prefix}: <a href=\"#{url}\">#{url}</a></span>"
|
"<span class=\"quote-inline\">#{String.duplicate("<br>", br)}#{prefix}: <a href=\"#{url}\">#{url}</a></span>"
|
||||||
end
|
end
|
||||||
|
|
||||||
defp filter_object(%{"quoteUrl" => quote_url} = object) do
|
defp filter_object(%{"quoteUrl" => quote_url} = object) do
|
||||||
@ -17,7 +17,13 @@ defmodule Pleroma.Web.ActivityPub.MRF.InlineQuotePolicy do
|
|||||||
object
|
object
|
||||||
else
|
else
|
||||||
prefix = Pleroma.Config.get([:mrf_inline_quote, :prefix])
|
prefix = Pleroma.Config.get([:mrf_inline_quote, :prefix])
|
||||||
content = content <> build_inline_quote(prefix, quote_url)
|
|
||||||
|
inline_quote =
|
||||||
|
if String.ends_with?(content, "</p>"),
|
||||||
|
do: build_inline_quote(prefix, quote_url, 0),
|
||||||
|
else: build_inline_quote(prefix, quote_url, 2)
|
||||||
|
|
||||||
|
content = content <> inline_quote
|
||||||
Map.put(object, "content", content)
|
Map.put(object, "content", content)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -9,6 +9,25 @@ defmodule Pleroma.Web.ActivityPub.MRF.InlineQuotePolicyTest do
|
|||||||
test "adds quote URL to post content" do
|
test "adds quote URL to post content" do
|
||||||
quote_url = "https://gleasonator.com/objects/1234"
|
quote_url = "https://gleasonator.com/objects/1234"
|
||||||
|
|
||||||
|
activity = %{
|
||||||
|
"type" => "Create",
|
||||||
|
"actor" => "https://gleasonator.com/users/alex",
|
||||||
|
"object" => %{
|
||||||
|
"type" => "Note",
|
||||||
|
"content" => "Nice post",
|
||||||
|
"quoteUrl" => quote_url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{:ok, %{"object" => %{"content" => filtered}}} = InlineQuotePolicy.filter(activity)
|
||||||
|
|
||||||
|
assert filtered ==
|
||||||
|
"Nice post<span class=\"quote-inline\"><br><br>RT: <a href=\"https://gleasonator.com/objects/1234\">https://gleasonator.com/objects/1234</a></span>"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "doesn't add line breaks to markdown posts" do
|
||||||
|
quote_url = "https://gleasonator.com/objects/1234"
|
||||||
|
|
||||||
activity = %{
|
activity = %{
|
||||||
"type" => "Create",
|
"type" => "Create",
|
||||||
"actor" => "https://gleasonator.com/users/alex",
|
"actor" => "https://gleasonator.com/users/alex",
|
||||||
@ -22,7 +41,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.InlineQuotePolicyTest do
|
|||||||
{:ok, %{"object" => %{"content" => filtered}}} = InlineQuotePolicy.filter(activity)
|
{:ok, %{"object" => %{"content" => filtered}}} = InlineQuotePolicy.filter(activity)
|
||||||
|
|
||||||
assert filtered ==
|
assert filtered ==
|
||||||
"<p>Nice post</p><span class=\"quote-inline\"><br><br>RT: <a href=\"https://gleasonator.com/objects/1234\">https://gleasonator.com/objects/1234</a></span>"
|
"<p>Nice post</p><span class=\"quote-inline\">RT: <a href=\"https://gleasonator.com/objects/1234\">https://gleasonator.com/objects/1234</a></span>"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "ignores Misskey quote posts" do
|
test "ignores Misskey quote posts" do
|
||||||
|
Loading…
Reference in New Issue
Block a user