Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.2KB

  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. defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkup do
  5. @moduledoc "Scrub configured hypertext markup"
  6. alias Pleroma.HTML
  7. @behaviour Pleroma.Web.ActivityPub.MRF.Policy
  8. @impl true
  9. def filter(%{"type" => "Create", "object" => child_object} = object) do
  10. scrub_policy = Pleroma.Config.get([:mrf_normalize_markup, :scrub_policy])
  11. content =
  12. child_object["content"]
  13. |> HTML.filter_tags(scrub_policy)
  14. object = put_in(object, ["object", "content"], content)
  15. {:ok, object}
  16. end
  17. def filter(object), do: {:ok, object}
  18. @impl true
  19. def describe, do: {:ok, %{}}
  20. @impl true
  21. def config_description do
  22. %{
  23. key: :mrf_normalize_markup,
  24. related_policy: "Pleroma.Web.ActivityPub.MRF.NormalizeMarkup",
  25. label: "MRF Normalize Markup",
  26. description: "MRF NormalizeMarkup settings. Scrub configured hypertext markup.",
  27. children: [
  28. %{
  29. key: :scrub_policy,
  30. type: :module,
  31. suggestions: [Pleroma.HTML.Scrubber.Default]
  32. }
  33. ]
  34. }
  35. end
  36. end