Verified Commit 108997b7 authored by Alex Gleason's avatar Alex Gleason
Browse files

InlineQuotePolicy: improve the way Markdown quotes are displayed by other software

parent b73a53ec
Pipeline #38904 passed with stages
in 11 minutes and 23 seconds
......@@ -6,8 +6,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.InlineQuotePolicy do
@moduledoc "Force a quote line into the message content."
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
defp build_inline_quote(prefix, url, br) do
"<span class=\"quote-inline\">#{String.duplicate("<br>", br)}#{prefix}: <a href=\"#{url}\">#{url}</a></span>"
defp build_inline_quote(prefix, url) do
"<span class=\"quote-inline\"><br/><br/>#{prefix}: <a href=\"#{url}\">#{url}</a></span>"
end
defp filter_object(%{"quoteUrl" => quote_url} = object) do
......@@ -18,12 +18,13 @@ defp filter_object(%{"quoteUrl" => quote_url} = object) do
else
prefix = Pleroma.Config.get([:mrf_inline_quote, :prefix])
inline_quote =
content =
if String.ends_with?(content, "</p>"),
do: build_inline_quote(prefix, quote_url, 0),
else: build_inline_quote(prefix, quote_url, 2)
do:
String.trim_trailing(content, "</p>") <>
build_inline_quote(prefix, quote_url) <> "</p>",
else: content <> build_inline_quote(prefix, quote_url)
content = content <> inline_quote
Map.put(object, "content", content)
end
end
......
......@@ -22,7 +22,7 @@ test "adds quote URL to post content" do
{: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>"
"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
......@@ -41,7 +41,7 @@ test "doesn't add line breaks to markdown posts" do
{:ok, %{"object" => %{"content" => filtered}}} = InlineQuotePolicy.filter(activity)
assert filtered ==
"<p>Nice post</p><span class=\"quote-inline\">RT: <a href=\"https://gleasonator.com/objects/1234\">https://gleasonator.com/objects/1234</a></span>"
"<p>Nice post<span class=\"quote-inline\"><br/><br/>RT: <a href=\"https://gleasonator.com/objects/1234\">https://gleasonator.com/objects/1234</a></span></p>"
end
test "ignores Misskey quote posts" do
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment