logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

normalize_markup.ex (1292B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 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 history_awareness, do: :auto
  10. @impl true
  11. def filter(%{"type" => type, "object" => child_object} = object)
  12. when type in ["Create", "Update"] do
  13. scrub_policy = Pleroma.Config.get([:mrf_normalize_markup, :scrub_policy])
  14. content =
  15. child_object["content"]
  16. |> HTML.filter_tags(scrub_policy)
  17. object = put_in(object, ["object", "content"], content)
  18. {:ok, object}
  19. end
  20. def filter(object), do: {:ok, object}
  21. @impl true
  22. def describe, do: {:ok, %{}}
  23. @impl true
  24. def config_description do
  25. %{
  26. key: :mrf_normalize_markup,
  27. related_policy: "Pleroma.Web.ActivityPub.MRF.NormalizeMarkup",
  28. label: "MRF Normalize Markup",
  29. description: "MRF NormalizeMarkup settings. Scrub configured hypertext markup.",
  30. children: [
  31. %{
  32. key: :scrub_policy,
  33. type: :module,
  34. suggestions: [Pleroma.HTML.Scrubber.Default]
  35. }
  36. ]
  37. }
  38. end
  39. end