1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.HTML.Transform.MediaProxy do
6 @moduledoc "Transforms inline image URIs to use MediaProxy."
8 alias Pleroma.Web.MediaProxy
10 def before_scrub(html), do: html
12 def scrub_attribute(:img, {"src", "http" <> target}) do
20 def scrub_attribute(_tag, attribute), do: attribute
22 def scrub({:img, attributes, children}) do
25 |> Enum.map(fn attr -> scrub_attribute(:img, attr) end)
26 |> Enum.reject(&is_nil(&1))
28 {:img, attributes, children}
31 def scrub({:comment, _text, _children}), do: ""
33 def scrub({tag, attributes, children}), do: {tag, attributes, children}
34 def scrub({_tag, children}), do: children
35 def scrub(text), do: text