2ad3fde0b3ed5fc7308ff3fd5bf126239c003253
[akkoma] / lib / pleroma / web / activity_pub / mrf / normalize_markup.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkup do
6 @moduledoc "Scrub configured hypertext markup"
7 alias Pleroma.HTML
8
9 @behaviour Pleroma.Web.ActivityPub.MRF
10
11 @impl true
12 def filter(%{"type" => "Create", "object" => child_object} = object) do
13 scrub_policy = Pleroma.Config.get([:mrf_normalize_markup, :scrub_policy])
14
15 content =
16 child_object["content"]
17 |> HTML.filter_tags(scrub_policy)
18
19 object = put_in(object, ["object", "content"], content)
20
21 {:ok, object}
22 end
23
24 def filter(object), do: {:ok, object}
25
26 @impl true
27 def describe, do: {:ok, %{}}
28
29 @impl true
30 def config_description do
31 %{
32 key: :mrf_normalize_markup,
33 related_policy: "Pleroma.Web.ActivityPub.MRF.NormalizeMarkup",
34 label: "MRF Normalize Markup",
35 description: "MRF NormalizeMarkup settings. Scrub configured hypertext markup.",
36 children: [
37 %{
38 key: :scrub_policy,
39 type: :module,
40 suggestions: [Pleroma.HTML.Scrubber.Default]
41 }
42 ]
43 }
44 end
45 end