scrub_html for translation results, allow 'ellipsis' and 'invisible' class names

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-06-30 23:09:36 +02:00
parent 5d1cb904ac
commit b1691732e9
2 changed files with 15 additions and 1 deletions

View file

@ -33,6 +33,7 @@ def translate(text, source_language, target_language) do
{:error, :not_found}
else
provider.translate(text, source_language, target_language)
|> scrub_html()
end
store_result(result, cache_key)
@ -112,4 +113,15 @@ defp store_result({:ok, result}, cache_key) do
defp store_result(_, _), do: nil
defp content_hash(text), do: :crypto.hash(:sha256, text) |> Base.encode64()
defp scrub_html({:ok, %{content: content} = result}) when is_binary(content) do
scrubbers = Pleroma.Config.get([:markup, :scrub_policy])
content
|> Pleroma.HTML.filter_tags(scrubbers)
{:ok, %{result | content: content}}
end
defp scrub_html(result), do: result
end

View file

@ -79,7 +79,9 @@ defmodule Pleroma.HTML.Scrubber.Default do
Meta.allow_tag_with_this_attribute_values(:span, "class", [
"h-card",
"recipients-inline",
"quote-inline"
"quote-inline",
"invisible",
"ellipsis"
])
Meta.allow_tag_with_these_attributes(:span, ["lang"])